[keycloak-user] Create user with roles using java client

Steve Chernyak mrrothstein at gmail.com
Sat Dec 17 23:59:42 EST 2016


Hello,

I'm trying to create a user associated with a role:

CredentialRepresentation credential = new CredentialRepresentation();
credential.setType(CredentialRepresentation.PASSWORD);
credential.setValue(password);
UserRepresentation user = new UserRepresentation();
user.setUsername(email.getAddress());
user.setCredentials(Arrays.asList(credential));
user.setRealmRoles(Arrays.asList(someRole));
Response response = kc.realm(appRealm).users().create(user);

The response status is the expected 201 and I can see the user in the realm
through the admin console. However, the user is not associated with
"someRole"...

I'm not sure what I'm missing...

How should I go about creating a user associated with a role progrmatically?

Thanks


More information about the keycloak-user mailing list