trials, but not yet finished
This commit is contained in:
@ -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
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
|
||||
/**
|
||||
*
|
||||
|
Reference in New Issue
Block a user