Java – create a user in the keycloak through the keycloak management client and return the illegalargumentexception
•
Java
I want to create a user through the keycloak management client, but I get:
This is my keycloak bean:
@Bean Keycloak keycloak() { return KeycloakBuilder .builder() .serverUrl(localhost:9080/auth) .realm(REALM) .clientId(CLIENT_ID) .username(USERNAME) .password(PASSWORD) .resteasyClient(new ResteasyClientBuilder().connectionPoolSize(10).build()) .build(); }
I use this code to call keycloak:
CredentialRepresentation credentialRepresentation = new CredentialRepresentation(); credentialRepresentation.setType(CredentialRepresentation.PASSWORD); credentialRepresentation.setValue(password); UserRepresentation userRepresentation = new UserRepresentation(); userRepresentation.setUsername(username); userRepresentation.setFirstName(firstName); userRepresentation.setLastName(lastName); userRepresentation.setEnabled(true); userRepresentation.setCredentials( Arrays.asList(credentialRepresentation)); keycloak.realm(REALM).users().create(userRepresentation);
Keycloak and keycloak management client are the same version (4.0.0. Final)
My stacktrace looks like this:
This is my build gradle
compile group: 'org.keycloak',name: 'keycloak-admin-client',version: '4.0.0.Final' compile group: 'org.jboss.resteasy',name: 'resteasy-jaxrs',version: '3.1.4.Final' compile group: 'org.jboss.resteasy',name: 'resteasy-client',name: 'resteasy-jackson2-provider',version: '3.1.4.Final'
Solution
Are you using spring boot?
I've tried your scenario for myself and it works well for me (tested on keyclone 4.0.0 and spring boot 1.5.10. Release)
I made a change to the way you create bean keyloak (my code is from the official DOCS) Ensure that the domain is master and client_ The ID is admin cli
@Bean Keycloak initKeycloakWithAdminRole() { return Keycloak.getInstance( "http://localhost:8080/auth","master","admin","admin-cli");
My code
Service code
Controller code
Disadvantages here
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码