title: Keycloak: how to add/update user with roles programmatically?
body: <p>I am trying to update a user, with admin role, for the realm using admin console, but it's not working.</p>
  
  <p>My code: </p>
  
  <pre><code>UserResource use = userResources.get(search.get(0).getId());
  use.resetPassword(credentials);
  
  user=use.toRepresentation();
  List&lt;String&gt; roles=new ArrayList&lt;String&gt;();
  roles.add("realm-admin");
  Map&lt;String,List&lt;String&gt;&gt; m= new HashMap&lt;String,List&lt;String&gt;&gt;();
  
  m.put("realm-management",roles);
  user.setClientRoles(m);
  use.update(user);
  </code></pre>
  
  <p>Any idea what I might be doing wrong?</p>