<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    <div class="moz-cite-prefix">Assigning roles with the admin client
      is rather tricky.&nbsp; I just finished migrating a test where I had to
      assign all kinds of roles.&nbsp; I think you'll probably find what you
      are looking for:<br>
<a class="moz-txt-link-freetext" href="https://github.com/keycloak/keycloak/blob/master/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/composites/CompositeRoleTest.java">https://github.com/keycloak/keycloak/blob/master/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/composites/CompositeRoleTest.java</a><br>
      <br>
      On 5/23/2016 9:58 AM, Haim Vana wrote:<br>
    </div>
    <blockquote
cite="mid:HE1PR03MB138543C9409E605557387B4BD24E0@HE1PR03MB1385.eurprd03.prod.outlook.com"
      type="cite">
      <meta http-equiv="Content-Type" content="text/html;
        charset=ISO-8859-1">
      <meta name="Generator" content="Microsoft Word 15 (filtered
        medium)">
      <style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:#0563C1;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:#954F72;
        text-decoration:underline;}
pre
        {mso-style-priority:99;
        mso-style-link:"HTML Preformatted Char";
        margin:0in;
        margin-bottom:.0001pt;
        font-size:10.0pt;
        font-family:"Courier New";}
span.EmailStyle17
        {mso-style-type:personal-compose;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
span.HTMLPreformattedChar
        {mso-style-name:"HTML Preformatted Char";
        mso-style-priority:99;
        mso-style-link:"HTML Preformatted";
        font-family:"Courier New";}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri",sans-serif;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
      <div class="WordSection1">
        <p class="MsoNormal">Hi,<o:p></o:p></p>
        <p class="MsoNormal"><o:p>&nbsp;</o:p></p>
        <p class="MsoNormal">I am trying to create admin user for a
          specific realm programmatically, I am able to create the user,
          however I can't assign the realm client roles to it.<o:p></o:p></p>
        <p class="MsoNormal"><o:p>&nbsp;</o:p></p>
        <p class="MsoNormal">For example in the UI I would go to the
          user 'Role Mappings'&nbsp; choose the realm client role and move
          the required roles from the Available section to the Assigned.<o:p></o:p></p>
        <p class="MsoNormal"><o:p>&nbsp;</o:p></p>
        <p class="MsoNormal">When I try to it programmatically I am
          getting 404, my code is below, note that I am getting 404 on
          the last line -
          <span style="font-size:11.5pt;font-family:&quot;Courier
            New&quot;;color:black">adminUserClientRole.listAvailable())</span><o:p></o:p></p>
        <p class="MsoNormal"><o:p>&nbsp;</o:p></p>
        <p class="MsoNormal" style="background:white"><span
            style="font-size:11.5pt;font-family:&quot;Courier
            New&quot;;color:black">createUserAndPsw(keyCloakClient,
          </span><b><span
              style="font-size:11.5pt;font-family:&quot;Courier
              New&quot;;color:green">"master"</span></b><span
            style="font-size:11.5pt;font-family:&quot;Courier
            New&quot;;color:black">, user);<br>
            RealmResource realm = keyCloakClient.realm(</span><b><span
              style="font-size:11.5pt;font-family:&quot;Courier
              New&quot;;color:green">"master"</span></b><span
            style="font-size:11.5pt;font-family:&quot;Courier
            New&quot;;color:black">);<br>
            UserResource userResource =
            realm.users().get(user.getKeyCloakId());<br>
            RoleMappingResource roles = userResource.roles();<br>
            RoleScopeResource adminUserClientRole =
            roles.clientLevel(tenantId + </span><b><span
              style="font-size:11.5pt;font-family:&quot;Courier
              New&quot;;color:green">"-realm"</span></b><span
            style="font-size:11.5pt;font-family:&quot;Courier
            New&quot;;color:black">);<o:p></o:p></span></p>
        <p class="MsoNormal" style="background:white"><span
            style="font-size:11.5pt;font-family:&quot;Courier
            New&quot;;color:black"><br>
adminUserClientRole.add(adminUserClientRole.listAvailable());<o:p></o:p></span></p>
        <p class="MsoNormal"><o:p>&nbsp;</o:p></p>
        <p class="MsoNormal"><o:p>&nbsp;</o:p></p>
        <p class="MsoNormal">Any advice will be appreciated.<o:p></o:p></p>
        <p class="MsoNormal"><o:p>&nbsp;</o:p></p>
        <p class="MsoNormal"><o:p>&nbsp;</o:p></p>
        <p class="MsoNormal">Thanks,<o:p></o:p></p>
        <p class="MsoNormal">Haim.<o:p></o:p></p>
      </div>
      The information contained in this message is proprietary to the
      sender, protected from disclosure, and may be privileged. The
      information is intended to be conveyed only to the designated
      recipient(s) of the message. If the reader of this message is not
      the intended recipient, you are hereby notified that any
      dissemination, use, distribution or copying of this communication
      is strictly prohibited and may be unlawful. If you have received
      this communication in error, please notify us immediately by
      replying to the message and deleting it from your computer. Thank
      you.
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <br>
      <pre wrap="">_______________________________________________
keycloak-user mailing list
<a class="moz-txt-link-abbreviated" href="mailto:keycloak-user@lists.jboss.org">keycloak-user@lists.jboss.org</a>
<a class="moz-txt-link-freetext" href="https://lists.jboss.org/mailman/listinfo/keycloak-user">https://lists.jboss.org/mailman/listinfo/keycloak-user</a></pre>
    </blockquote>
    <br>
  </body>
</html>