trials, but not yet finished

This commit is contained in:
Jottyfan
2022-12-06 22:10:08 +01:00
parent 64f130733f
commit f37e4498e8
6 changed files with 38 additions and 53 deletions

View File

@ -6,24 +6,26 @@
<attribute name="gradle_used_by_scope" value="main,test"/> <attribute name="gradle_used_by_scope" value="main,test"/>
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry kind="src" path="src/test/java"/> <classpathentry kind="src" output="bin/test" path="src/test/java">
<attributes>
<attribute name="gradle_scope" value="test"/>
<attribute name="gradle_used_by_scope" value="test"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="bin/main" path="src/main/resources"> <classpathentry kind="src" output="bin/main" path="src/main/resources">
<attributes> <attributes>
<attribute name="gradle_scope" value="main"/> <attribute name="gradle_scope" value="main"/>
<attribute name="gradle_used_by_scope" value="main,test"/> <attribute name="gradle_used_by_scope" value="main,test"/>
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17/"> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17/"/>
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.web.container"/> <classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.web.container"/>
<classpathentry kind="con" path="org.eclipse.buildship.core.gradleclasspathcontainer"> <classpathentry kind="con" path="org.eclipse.buildship.core.gradleclasspathcontainer">
<attributes> <attributes>
<attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/> <attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/5"/> <classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
<classpathentry kind="output" path="bin/default"/> <classpathentry kind="output" path="bin/default"/>
</classpath> </classpath>

View File

@ -1,13 +1,2 @@
arguments=
auto.sync=false
build.scans.enabled=false
connection.gradle.distribution=GRADLE_DISTRIBUTION(WRAPPER)
connection.project.dir= connection.project.dir=
eclipse.preferences.version=1 eclipse.preferences.version=1
gradle.user.home=
java.home=
jvm.arguments=
offline.mode=false
override.workspace.settings=false
show.console.view=false
show.executions.view=false

View File

@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0"> <?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0">
<wb-module deploy-name="camporganizer2"> <wb-module deploy-name="CampOrganizer2">
<property name="context-root" value="camporganizer2"/> <property name="context-root" value="CampOrganizer2"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="src/main/resources"/> <wb-resource deploy-path="/WEB-INF/classes" source-path="src/main/resources"/>

View File

@ -17,7 +17,6 @@ import org.keycloak.representations.idm.UserRepresentation;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
/** /**
* *
* @author henkej * @author henkej
@ -56,50 +55,43 @@ public class KeycloakRepository {
/** /**
* register the login in keycloak * register the login in keycloak
* *
* @param login the username * @param login the username
* @param password the password * @param password the password
* @param email the email * @param email the email
* @return true or false * @return true or false
*/ */
public boolean register(String login, String password, String email) { public boolean register(String login, String password, String email) {
CredentialRepresentation passwordCredentials = new CredentialRepresentation(); CredentialRepresentation passwordCredentials = new CredentialRepresentation();
passwordCredentials.setTemporary(false); passwordCredentials.setTemporary(false);
passwordCredentials.setType(CredentialRepresentation.PASSWORD); passwordCredentials.setType(CredentialRepresentation.PASSWORD);
passwordCredentials.setValue(password); passwordCredentials.setValue(password);
UserRepresentation user = new UserRepresentation(); UserRepresentation user = new UserRepresentation();
user.setUsername(login); user.setUsername(login);
user.setEmail(email); user.setEmail(email);
user.setCredentials(Collections.singletonList(passwordCredentials)); user.setCredentials(Collections.singletonList(passwordCredentials));
user.setEnabled(true); user.setEnabled(true);
UsersResource instance = getInstance(); UsersResource instance = getInstance();
Response response = instance.create(user); Response response = instance.create(user);
boolean result = Status.OK.equals(response.getStatusInfo()); boolean result = Status.OK.equals(response.getStatusInfo());
sendVerificationLink(login); sendVerificationLink(login);
return result; return result;
} }
public Client getClient() { public Client getClient() {
return new ResteasyClientBuilderImpl() return new ResteasyClientBuilderImpl().connectionPoolSize(10).build();
.connectionPoolSize(10)
.build();
} }
public KeycloakBuilder getKeycloak() { public KeycloakBuilder getKeycloak() {
return KeycloakBuilder.builder() return KeycloakBuilder.builder().serverUrl(keycloakUrl).realm(keycloakRealm).grantType(OAuth2Constants.PASSWORD)
.serverUrl(keycloakUrl) .username(keycloakAdminName).password(keycloakAdminPassword).clientId(keycloakClientId)
.realm(keycloakRealm) .resteasyClient(getClient());
.grantType(OAuth2Constants.PASSWORD)
.username(keycloakAdminName)
.password(keycloakAdminPassword)
.clientId(keycloakClientId)
.resteasyClient(getClient());
} }
public UsersResource getInstance() { public UsersResource getInstance() {
return getKeycloak().build().realm(keycloakRealm).users(); return getKeycloak().build().realm(keycloakRealm).users();
} }
/** /**
* send a verification link for newly registered users * send a verification link for newly registered users

View File

@ -13,7 +13,7 @@ public class RegistrationService {
@Autowired @Autowired
private RegistrationGateway gateway; private RegistrationGateway gateway;
@Autowired @Autowired
private KeycloakRepository keycloak; private KeycloakRepository keycloak;
@ -29,14 +29,14 @@ public class RegistrationService {
/** /**
* register the person for a camp; if registerInKeycloak, do so also * register the person for a camp; if registerInKeycloak, do so also
* *
* @param bean the bean * @param bean the bean
* @return true if successful, false otherwise * @return true if successful, false otherwise
*/ */
public Boolean register(RegistrationBean bean) { public Boolean register(RegistrationBean bean) {
Boolean result = gateway.register(bean); Boolean result = gateway.register(bean);
if (result && bean.getRegisterInKeycloak()) { if (result && bean.getRegisterInKeycloak()) {
keycloak.register(bean.getLogin(), bean.getPassword()); keycloak.register(bean.getLogin(), bean.getPassword(), bean.getEmail());
} }
return result; return result;
} }

View File

@ -5,6 +5,8 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
/** /**
* *