Hello,
I’m writting a spring boot application using the admin-client api.
My scenario needs to update a user and assign that user to a realm role.
The code executes successfully, however the user roles are not updated in Admin console.
Please find my configurations and code snippet below:
realm: test-realm
server-url: http://localhost:8080
client-id: admin-cli
grant-type: password
name: admin
password: xxx
Keycloak keycloak=keycloakUtil.getKeycloakInstance();
List<UserRepresentation> users=keycloak.realm(realm).users().searchByEmail(email,true);;
UserRepresentation user=users.get(0);
//update user roles
List<String> roles=user.getRealmRoles();
if(roles==null) {
roles=List.of("publisher");
}
else{
roles.add("publisher");
}
user.setRealmRoles(roles);
keycloak.realm(realm).users().get(user.getId()).update(user);