<div dir="ltr">I usually use the admin console and look at the request it sends to figure out how to use the rest endpoints. It&#39;s usually simpler than reading the not so great docs.</div><div class="gmail_extra"><br><div class="gmail_quote">On 21 March 2016 at 14:41,  <span dir="ltr">&lt;<a href="mailto:daniele.capasso@dnshosting.it" target="_blank">daniele.capasso@dnshosting.it</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
I do not understand how to set up a role , I insert a new user , I call this function without errors , but does not assign the role keycloak<br>
<br>
public void addRoleToUser(String idKeycloak, String clientRole){<br>
                UserRepresentation user= getUserRepresentation(idKeycloak);<br>
                Map&lt;String, List&lt;String&gt;&gt; roles =user.getClientRoles();<br>
                List&lt;String&gt; rolesInClient=new ArrayList&lt;String&gt;();<br>
                if (roles!=null)<br>
                        rolesInClient = roles.get(getKeycloakCurrentClient());<br>
                else<br>
                        roles = new HashMap&lt;String, List&lt;String&gt;&gt;();<br>
                rolesInClient.add(clientRole);<br>
                roles.put(getKeycloakCurrentClient(), rolesInClient);<br>
                user.setClientRoles(roles);<br>
                UserResource userResource = getUserResource(idKeycloak);<br>
                userResource.update(user);<span class=""><br>
        }<br>
<br>
Il 2016-03-18 12:58 Stian Thorgersen ha scritto:<br>
</span><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">
Creating a user through admin rest is 3 requests. Create user, update<br>
credentials, assign roles. Not very elegant that&#39;s true and we will<br>
improve it eventually.<br>
On 17 Mar 2016 19:24, &quot;Lohitha Chiranjeewa&quot; &lt;<a href="mailto:kalc04@gmail.com" target="_blank">kalc04@gmail.com</a>&gt; wrote:<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
As far as I know, you have to trigger the Assign Client Role<br>
<br>
</blockquote>
(<a href="http://keycloak.github.io/docs/rest-api/index.html#_add_client_level_roles_to_the_user_role_mapping" rel="noreferrer" target="_blank">http://keycloak.github.io/docs/rest-api/index.html#_add_client_level_roles_to_the_user_role_mapping</a><br>
</span><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
[2]) endpoint to achieve that. Although the payload allows you to<div><div class="h5"><br>
supply roles to the Create User endpoint, it doesn&#39;t assign any<br>
roles underneath. This has been the behavior for a long time.<br>
<br>
Regards,<br>
Lohitha.<br>
<br>
On Thu, Mar 17, 2016 at 7:47 PM, &lt;<a href="mailto:daniele.capasso@dnshosting.it" target="_blank">daniele.capasso@dnshosting.it</a>&gt;<br>
wrote:<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi, i want to register a user via keycloak admin client.<br>
<br>
This is the source, it works except for the role, what i wrong?<br>
<br>
CredentialRepresentation credential = new<br>
CredentialRepresentation();<br>
credential.setType(CredentialRepresentation.PASSWORD);<br>
credential.setValue(model.getPassword());<br>
credential.setTemporary(false);<br>
<br>
UserRepresentation userRepresentation = new UserRepresentation();<br>
userRepresentation.setEmail(model.getEmail());<br>
userRepresentation.setFirstName(model.getName());<br>
userRepresentation.setLastName(model.getSurname());<br>
userRepresentation.setUsername(model.getEmail());<br>
userRepresentation.setCredentials(Arrays.asList(credential));<br>
userRepresentation.setEnabled(true);<br>
userRepresentation.setClientRoles(new HashMap&lt;String,<br>
List&lt;String&gt;&gt;(){{<br>
<br>
<br>
</blockquote>
<br>
</div></div></blockquote>
put(kcApi.getKeycloakCurrentClient(),Arrays.asList(&quot;ROLE_USER_HOST&quot;));<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5">
}});<br>
<br>
Response resp = kcApi.createUser(userRepresentation);<br>
<br>
thank you<br>
_______________________________________________<br>
keycloak-user mailing list<br>
<a href="mailto:keycloak-user@lists.jboss.org" target="_blank">keycloak-user@lists.jboss.org</a><br>
</div></div><a href="https://lists.jboss.org/mailman/listinfo/keycloak-user" rel="noreferrer" target="_blank">https://lists.jboss.org/mailman/listinfo/keycloak-user</a> [1]<br>
</blockquote><span class="">
<br>
_______________________________________________<br>
keycloak-user mailing list<br>
<a href="mailto:keycloak-user@lists.jboss.org" target="_blank">keycloak-user@lists.jboss.org</a><br>
</span><a href="https://lists.jboss.org/mailman/listinfo/keycloak-user" rel="noreferrer" target="_blank">https://lists.jboss.org/mailman/listinfo/keycloak-user</a> [1]<br>
</blockquote>
<br>
<br>
Links:<br>
------<br>
[1] <a href="https://lists.jboss.org/mailman/listinfo/keycloak-user" rel="noreferrer" target="_blank">https://lists.jboss.org/mailman/listinfo/keycloak-user</a><br>
[2]<br>
<a href="http://keycloak.github.io/docs/rest-api/index.html#_add_client_level_roles_to_the_user_role_mapping" rel="noreferrer" target="_blank">http://keycloak.github.io/docs/rest-api/index.html#_add_client_level_roles_to_the_user_role_mapping</a><br>
</blockquote>
<br>
</blockquote></div><br></div>