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"/>
</attributes>
</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">
<attributes>
<attribute name="gradle_scope" value="main"/>
<attribute name="gradle_used_by_scope" value="main,test"/>
</attributes>
</classpathentry>
<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.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17/"/>
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.web.container"/>
<classpathentry kind="con" path="org.eclipse.buildship.core.gradleclasspathcontainer">
<attributes>
<attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
</attributes>
</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"/>
</classpath>

View File

@ -1,13 +1,2 @@
arguments=
auto.sync=false
build.scans.enabled=false
connection.gradle.distribution=GRADLE_DISTRIBUTION(WRAPPER)
connection.project.dir=
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">
<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"/>

View File

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

View File

@ -13,7 +13,7 @@ public class RegistrationService {
@Autowired
private RegistrationGateway gateway;
@Autowired
private KeycloakRepository keycloak;
@ -29,14 +29,14 @@ public class RegistrationService {
/**
* register the person for a camp; if registerInKeycloak, do so also
*
*
* @param bean the bean
* @return true if successful, false otherwise
* @return true if successful, false otherwise
*/
public Boolean register(RegistrationBean bean) {
Boolean result = gateway.register(bean);
if (result && bean.getRegisterInKeycloak()) {
keycloak.register(bean.getLogin(), bean.getPassword());
keycloak.register(bean.getLogin(), bean.getPassword(), bean.getEmail());
}
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.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
/**
*