Keycloak: how to programmatically add / update user with roles?

I am trying to update a user with an administrator role for an area using the admin console, but it does not work.

My code is:

UserResource use = userResources.get(search.get(0).getId()); use.resetPassword(credentials); user=use.toRepresentation(); List<String> roles=new ArrayList<String>(); roles.add("realm-admin"); Map<String,List<String>> m= new HashMap<String,List<String>>(); m.put("realm-management",roles); user.setClientRoles(m); use.update(user); 

Any idea what I can do wrong?

+5
source share
1 answer
 UserResource use = userResources.get(idUser); use.roles().clientLevel(id).add(use.roles().clientLevel( id).listAvailable()); 

This solution in which I found id is the identifier of the client, not client_id.

+4
source

Source: https://habr.com/ru/post/1246415/


All Articles