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

Steve Chernyak mrrothstein at gmail.com
Tue Dec 20 22:26:56 EST 2016


Forgot to mention, I did set the enabled attribute.

Current version:

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

On Tue, Dec 20, 2016 at 10:20 PM, Steve Chernyak <mrrothstein at gmail.com>
wrote:

> I would really appreciate some help with this...
>
> Am I missing something in the documentation? I can't find anything that
> describes this process in detail.
>
> It also doesn't appear that the password I'm using during the creation
> process is honored either. I have to change the password through the
> console to get the login to work.
>
> Is there a specific set of attributes that are used for the user creation
> process while others are ignored? Is there anything that documents the
> correct way to do what i'm trying?
>
> Thanks
>
> On Sat, Dec 17, 2016 at 11:59 PM, Steve Chernyak <mrrothstein at gmail.com>
> wrote:
>
>> 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