I just add a new method and I call this method after create user:
public void resetUserPassword(String id, String password) {
RealmResource realmResource = keycloak.realm(realmProperties.getRealm());
CredentialRepresentation credential = new CredentialRepresentation();
credential.setType(CredentialRepresentation.PASSWORD);
credential.setValue(password);
credential.setTemporary(false);
realmResource.users().get(id).resetPassword(credential);
}
This solve my problem. Now my password is being stored in the database.
Thanks Marek!
2017-06-05 4:43 GMT-03:00 Marek Posolda <mposolda(a)redhat.com>:
Hi,
once you create user, you need to use separate REST endpoint for update
user credentials. The best is to look at our testsuite and how it uses REST
endpoints (eg. see UserTest class from keycloak codebase) or eventually
explore admin console with some tool like firebug, which will show you what
REST endpoints is our admin console calling (KC admin console is just an
angular application calling admin REST endpoints under the covers)
Marek
On 02/06/17 22:47, Celso Agra wrote:
> Hi all,
>
> Please, need some help! I'm trying to create an user through Keycloak
> Admin
> Client.
> So, When I add an user from Keycloak register page my LDAP stores a tag
> called "userPassword" with the password stored.
> But When I add an user from Keycloak Admin Client, all informations are
> stored in LDAP, except "userPassword". Am I doing something wrong?
>
> Here is my code below:
>
> public Response createUserKeycloak(UserKeycloak userKeycloak) {
>
>> CredentialRepresentation credential = new CredentialRepresentation();
>> credential.setType(CredentialRepresentation.PASSWORD);
>> credential.setValue(userKeycloak.getPassword());
>> credential.setTemporary(false);
>>
>
>
> UserRepresentation user = new UserRepresentation();
>> user.setUsername(userKeycloak.getUsername());
>> user.setFirstName(userKeycloak.getFirstName());
>> user.setLastName(userKeycloak.getLastName());
>> user.setEnabled(true);
>> if (userKeycloak.getEmail() != null)
>> user.setEmail(userKeycloak.getEmail());
>> user.setCredentials(Arrays.asList(credential));
>>
>>
> RealmResource realmResource = keycloak.realm(realmProperties.getRealm());
>> UsersResource userRessource = realmResource.users();
>> return userRessource.create(user);
>> }
>>
>
>
> Best Regards,
>
>
--
---
*Celso Agra*