<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 TRANSITIONAL//EN">
<HTML>
<HEAD>
  <META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=UTF-8">
  <META NAME="GENERATOR" CONTENT="GtkHTML/4.6.6">
</HEAD>
<BODY>
Hi,<BR>
<BR>
Sorry Bill, I think I'm confusing matters here. The AdminClient I'm referring to is not the keycloak-admin-client.jar but rather a combination of insights from <BR>
<A HREF="https://github.com/keycloak/keycloak/blob/master/examples/demo-template/admin-access-app/src/main/java/org/keycloak/example/AdminClient.java">https://github.com/keycloak/keycloak/blob/master/examples/demo-template/admin-access-app/src/main/java/org/keycloak/example/AdminClient.java</A> and from the documentation in the user guide.<BR>
<BR>
That means I'm constructing the URLs myself to invoke the operation. I intend to move to the keycloak-admin-client in the future though.<BR>
<BR>
I can't find the corresponding REST url(s) to invoke to achieve the same results as you describe in your response below. I think that's what I need.<BR>
Cheers.<BR>
<BR>
<BR>
On Mon, 2015-08-03 at 09:13 -0400, Bill Burke wrote:
<BLOCKQUOTE TYPE=CITE>
<PRE>
If you're just using the admin client interfaces its:

realm(&quot;realm&quot;).users().get(&quot;user-id&quot;).roles().realmLevel().add(List&lt;RoleRepresentation&gt; 
rolesToAdd)

On 8/3/2015 9:07 AM, Edem Morny wrote:
<FONT COLOR="#737373">&gt; Hi Bill,</FONT>
<FONT COLOR="#737373">&gt;</FONT>
<FONT COLOR="#737373">&gt; The adminClient.createUser is my modification of the code situated in</FONT>
<FONT COLOR="#737373">&gt; the AdminClient implementation of the &quot;admin-access-app&quot; in the examples.</FONT>
<FONT COLOR="#737373">&gt;</FONT>
<FONT COLOR="#737373">&gt; Could you point me in the direction of the API calls to do the addition</FONT>
<FONT COLOR="#737373">&gt; of the roles? I had a feeling it might be a subsequent step (like for</FONT>
<FONT COLOR="#737373">&gt; setting the password, which I actually implemented), but I'm struggling</FONT>
<FONT COLOR="#737373">&gt; to find any pointers as to how to do this particular one.</FONT>
<FONT COLOR="#737373">&gt;</FONT>
<FONT COLOR="#737373">&gt;</FONT>
<FONT COLOR="#737373">&gt; On Mon, 2015-08-03 at 08:36 -0400, Bill Burke wrote:</FONT>
<FONT COLOR="#737373">&gt;&gt; Is adminClient.createUser(...) your own method?  There is a different</FONT>
<FONT COLOR="#737373">&gt;&gt; REST API for adding roles.</FONT>
<FONT COLOR="#737373">&gt;&gt;</FONT>
<FONT COLOR="#737373">&gt;&gt; create the user</FONT>
<FONT COLOR="#737373">&gt;&gt; then add the roles</FONT>
<FONT COLOR="#737373">&gt;&gt;</FONT>
<FONT COLOR="#737373">&gt;&gt; On 8/3/2015 8:23 AM, Edem Morny wrote:</FONT>
<FONT COLOR="#737373">&gt;&gt; &gt; Hi,</FONT>
<FONT COLOR="#737373">&gt;&gt; &gt;</FONT>
<FONT COLOR="#737373">&gt;&gt; &gt; We're currently using Keycloak 1.2.0.Final.</FONT>
<FONT COLOR="#737373">&gt;&gt; &gt;</FONT>
<FONT COLOR="#737373">&gt;&gt; &gt; We are migrating users from an existing application with it's own user</FONT>
<FONT COLOR="#737373">&gt;&gt; &gt; management implementation to Keycloak, and have been making extensive</FONT>
<FONT COLOR="#737373">&gt;&gt; &gt; use of the Via the REST api to achieve this. I'm able to create a new</FONT>
<FONT COLOR="#737373">&gt;&gt; &gt; user, set their temporary password and so on. However, I'm finding that</FONT>
<FONT COLOR="#737373">&gt;&gt; &gt; all our attempts to add the roles to the created user seem not to be</FONT>
<FONT COLOR="#737373">&gt;&gt; &gt; taking effect when we observe the newly created user on the keycloak</FONT>
<FONT COLOR="#737373">&gt;&gt; &gt; side. Here's the code we are trying to use to do this</FONT>
<FONT COLOR="#737373">&gt;&gt; &gt;</FONT>
<FONT COLOR="#737373">&gt;&gt; &gt; UserRepresentation user = new UserRepresentation();</FONT>
<FONT COLOR="#737373">&gt;&gt; &gt; user.setUsername(username);</FONT>
<FONT COLOR="#737373">&gt;&gt; &gt; user.setFirstName(employee.getFirstName());</FONT>
<FONT COLOR="#737373">&gt;&gt; &gt; user.setLastName(employee.getLastName());</FONT>
<FONT COLOR="#737373">&gt;&gt; &gt; user.setEmail(employee.getEmail());</FONT>
<FONT COLOR="#737373">&gt;&gt; &gt; user.setEnabled(true);</FONT>
<FONT COLOR="#737373">&gt;&gt; &gt; user.setEmailVerified(false);</FONT>
<FONT COLOR="#737373">&gt;&gt; &gt; List&lt;String&gt; requiredActions = new ArrayList&lt;&gt;();</FONT>
<FONT COLOR="#737373">&gt;&gt; &gt; requiredActions.add(UserModel.RequiredAction.UPDATE_PASSWORD.name());</FONT>
<FONT COLOR="#737373">&gt;&gt; &gt; *List&lt;String&gt; userRoles = getMigrateRoles(employee);*</FONT>
<FONT COLOR="#737373">&gt;&gt; &gt; * user.setRealmRoles(userRoles);*</FONT>
<FONT COLOR="#737373">&gt;&gt; &gt; user.setRequiredActions(requiredActions);</FONT>
<FONT COLOR="#737373">&gt;&gt; &gt; adminClient.createUser(settings.getKeycloackUrl(),</FONT>
<FONT COLOR="#737373">&gt;&gt; settings.getRealm(), access, user);</FONT>
<FONT COLOR="#737373">&gt;&gt; &gt;</FONT>
<FONT COLOR="#737373">&gt;&gt; &gt; It seams setting the list of roles to the Realm Roles isn't enough to</FONT>
<FONT COLOR="#737373">&gt;&gt; &gt; the user with these roles. The user gets created alright, but doesn't</FONT>
<FONT COLOR="#737373">&gt;&gt; &gt; come with any roles. Is there any other means by which we can specify</FONT>
<FONT COLOR="#737373">&gt;&gt; &gt; the user roles during the process of account creation?</FONT>
<FONT COLOR="#737373">&gt;&gt; &gt;</FONT>
<FONT COLOR="#737373">&gt;&gt; &gt; The migration will be very tedious if we ask the administrators to</FONT>
<FONT COLOR="#737373">&gt;&gt; &gt; manually do the assignment of the user to their roles after our current</FONT>
<FONT COLOR="#737373">&gt;&gt; &gt; implementation of being able to automatically migrate the user accounts</FONT>
<FONT COLOR="#737373">&gt;&gt; &gt; themselves to keycloak.</FONT>
<FONT COLOR="#737373">&gt;&gt; &gt;</FONT>
<FONT COLOR="#737373">&gt;&gt; &gt;</FONT>
<FONT COLOR="#737373">&gt;&gt; &gt; _______________________________________________</FONT>
<FONT COLOR="#737373">&gt;&gt; &gt; keycloak-user mailing list</FONT>
<FONT COLOR="#737373">&gt;&gt; &gt; <A HREF="mailto:keycloak-user@lists.jboss.org">keycloak-user@lists.jboss.org</A> &lt;<A HREF="mailto:keycloak-user@lists.jboss.org">mailto:keycloak-user@lists.jboss.org</A>&gt;</FONT>
<FONT COLOR="#737373">&gt;&gt; &gt; <A HREF="https://lists.jboss.org/mailman/listinfo/keycloak-user">https://lists.jboss.org/mailman/listinfo/keycloak-user</A></FONT>
<FONT COLOR="#737373">&gt;&gt; &gt;</FONT>
<FONT COLOR="#737373">&gt;&gt;</FONT>
<FONT COLOR="#737373">&gt;</FONT>
<FONT COLOR="#737373">&gt;</FONT>
<FONT COLOR="#737373">&gt; _______________________________________________</FONT>
<FONT COLOR="#737373">&gt; keycloak-user mailing list</FONT>
<FONT COLOR="#737373">&gt; <A HREF="mailto:keycloak-user@lists.jboss.org">keycloak-user@lists.jboss.org</A></FONT>
<FONT COLOR="#737373">&gt; <A HREF="https://lists.jboss.org/mailman/listinfo/keycloak-user">https://lists.jboss.org/mailman/listinfo/keycloak-user</A></FONT>
<FONT COLOR="#737373">&gt;</FONT>

</PRE>
</BLOCKQUOTE>
</BODY>
</HTML>