register keycloak user (needs manage realm-user privilege)
This commit is contained in:
@ -2,7 +2,6 @@ package de.jottyfan.camporganizer.module.registration;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import javax.ws.rs.client.Client;
|
||||
import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.core.Response.Status;
|
||||
|
||||
@ -100,19 +99,36 @@ public class KeycloakRepository {
|
||||
*/
|
||||
protected boolean register(UsersResource resource, UserRepresentation user) {
|
||||
Response response = resource.create(user);
|
||||
LOGGER.info("created new keycloak user {}", user.getUsername());
|
||||
return Status.OK.equals(response.getStatusInfo());
|
||||
}
|
||||
|
||||
public Client getClient() {
|
||||
return new ResteasyClientBuilderImpl().connectionPoolSize(10).build();
|
||||
}
|
||||
|
||||
/**
|
||||
* generate a keycloak object with the special arguments
|
||||
*
|
||||
* @param url the url
|
||||
* @param realm the realm
|
||||
* @param admin the admin of the realm
|
||||
* @param password the password
|
||||
* @param clientId the client ID
|
||||
* @return the keycloak object
|
||||
*/
|
||||
public KeycloakBuilder getKeycloak(String url, String realm, String admin, String password, String clientId) {
|
||||
return KeycloakBuilder.builder().serverUrl(url).realm(realm).grantType(OAuth2Constants.PASSWORD)
|
||||
.username(admin).password(password).clientId(clientId)
|
||||
.resteasyClient(getClient());
|
||||
.resteasyClient(new ResteasyClientBuilderImpl().connectionPoolSize(10).build());
|
||||
}
|
||||
|
||||
/**
|
||||
* generate a users resource object
|
||||
*
|
||||
* @param url the url
|
||||
* @param realm the realm
|
||||
* @param admin the admin of the realm
|
||||
* @param password the password
|
||||
* @param clientId the client ID
|
||||
* @return the users resource
|
||||
*/
|
||||
public UsersResource getUsersResource(String url, String realm, String admin, String password, String clientId) {
|
||||
return getKeycloak(url, realm, admin, password, clientId).build().realm(realm).users();
|
||||
}
|
||||
|
Reference in New Issue
Block a user