[keycloak-user] Is it possible to update users with the admin client

Stian Thorgersen stian at redhat.com
Mon Dec 29 02:56:48 EST 2014



----- Original Message -----
> From: "Alexander Chriztopher" <alexander.chriztopher at gmail.com>
> To: keycloak-user at lists.jboss.org
> Sent: Friday, 19 December, 2014 7:36:05 PM
> Subject: [keycloak-user] Is it possible to update users with the admin client
> 
> Hi,
> 
> I would like to use the admin client to update a user in order to force him
> to change his password next time he logs in ?
> 
> So far i have failed miserably to do it so i was wondering if this is at all
> possible ?
> 
> This is basically what am doing :
> 
> Keycloak keycloak = Keycloak.getInstance(authServer, "example",
> "examples-admin-client", "password", "examples-admin-client", "password");
> RealmResource realm = keycloak.realm("example");
> UsersResource users = realm.users();
> List<UserRepresentation> users_ = users.search("", 0, 1000000); // This gets
> me all my users
> for (UserRepresentation user_ : users_) {
> if (user_.getUsername().equals("examples-admin-client")) {
> user_.setEmailVerified(true);
> }
> }
> RealmRepresentation realm_ = realm.toRepresentation();
> realm_.setUsers(users_);
> realm.update(realm_);
> 
> Does the method update of realm support users update ?

Here's the code to require a user with username "user1" to update password on next login:

    UserResource user = realm.users().get("user1");
    UserRepresentation userRep = user.toRepresentation();
    if (!userRep.getRequiredActions().contains("UPDATE_PASSWORD")) {
        userRep.getRequiredActions().add("UPDATE_PASSWORD");
        user.update(userRep);  
    }

> 
> Thanks for any help on this.
> 
> _______________________________________________
> keycloak-user mailing list
> keycloak-user at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/keycloak-user


More information about the keycloak-user mailing list