<html>
  <head>
    <meta content="text/html; charset=windows-1252"
      http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    In this example I play around with keycloak-admin-client. The
    following example access the client roles and add new roles to a
    already defined client.<br>
    <br>
    Maybe it helps<br>
    <br>
<a class="moz-txt-link-freetext" href="https://github.com/OkieOth/grantMaster/blob/master/InitKeycloakServer/src/main/java/de/oth/keycloak/impl/KeycloakAccess.java#L287">https://github.com/OkieOth/grantMaster/blob/master/InitKeycloakServer/src/main/java/de/oth/keycloak/impl/KeycloakAccess.java#L287</a><br>
    <br>
    Kind regards<br>
    Eiko<br>
    <br>
    <div class="moz-cite-prefix">Am 07.06.2016 um 07:31 schrieb Haim
      Vana:<br>
    </div>
    <blockquote
cite="mid:HE1PR03MB1385BFA7D0D224D825AD207ED25D0@HE1PR03MB1385.eurprd03.prod.outlook.com"
      type="cite">
      <meta http-equiv="Content-Type" content="text/html;
        charset=windows-1252">
      <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:12.0pt;
        font-family:"Times New Roman",serif;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal-reply;
        font-family:"Calibri",sans-serif;
        color:#1F497D;}
.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"><span
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif;color:#1F497D">Thanks
            and sorry about the repetition.<o:p></o:p></span></p>
        <p class="MsoNormal"><span
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif;color:#1F497D"><o:p> </o:p></span></p>
        <p class="MsoNormal"><span
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif;color:#1F497D"><o:p> </o:p></span></p>
        <p class="MsoNormal"><b><span
              style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif">From:</span></b><span
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif">
            Stian Thorgersen [<a class="moz-txt-link-freetext" href="mailto:sthorger@redhat.com">mailto:sthorger@redhat.com</a>]
            <br>
            <b>Sent:</b> Tuesday, June 07, 2016 8:23 AM<br>
            <b>To:</b> Haim Vana <a class="moz-txt-link-rfc2396E" href="mailto:haimv@perfectomobile.com">&lt;haimv@perfectomobile.com&gt;</a><br>
            <b>Cc:</b> <a class="moz-txt-link-abbreviated" href="mailto:keycloak-user@lists.jboss.org">keycloak-user@lists.jboss.org</a><br>
            <b>Subject:</b> Re: [keycloak-user] How to get specific
            client role programmatically<o:p></o:p></span></p>
        <p class="MsoNormal"><o:p> </o:p></p>
        <div>
          <p class="MsoNormal">Please don't repeat your question, if
            you're not getting an answer straight away it means we're
            busy.<o:p></o:p></p>
          <div>
            <p class="MsoNormal"><o:p> </o:p></p>
          </div>
          <div>
            <p class="MsoNormal">realm.clients().get("client-uuid").roles().get("rolename").toRepresentation()<o:p></o:p></p>
          </div>
        </div>
        <div>
          <p class="MsoNormal"><o:p> </o:p></p>
          <div>
            <p class="MsoNormal">On 7 June 2016 at 07:02, Haim Vana &lt;<a
                moz-do-not-send="true"
                href="mailto:haimv@perfectomobile.com" target="_blank"><a class="moz-txt-link-abbreviated" href="mailto:haimv@perfectomobile.com">haimv@perfectomobile.com</a></a>&gt;
              wrote:<o:p></o:p></p>
            <blockquote style="border:none;border-left:solid #CCCCCC
              1.0pt;padding:0in 0in 0in
              6.0pt;margin-left:4.8pt;margin-right:0in">
              <div>
                <div>
                  <p class="MsoNormal"
                    style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif;color:#1F497D">Hi,</span><o:p></o:p></p>
                  <p class="MsoNormal"
                    style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif;color:#1F497D"> </span><o:p></o:p></p>
                  <p class="MsoNormal"
                    style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif;color:#1F497D">Any
                      idea regarding the below ?</span><o:p></o:p></p>
                  <p class="MsoNormal"
                    style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif;color:#1F497D"> </span><o:p></o:p></p>
                  <div>
                    <div style="border:none;border-top:solid #E1E1E1
                      1.0pt;padding:3.0pt 0in 0in 0in">
                      <p class="MsoNormal"
                        style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><b><span
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif">From:</span></b><span
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif">
                          <a moz-do-not-send="true"
                            href="mailto:keycloak-user-bounces@lists.jboss.org"
                            target="_blank">keycloak-user-bounces@lists.jboss.org</a>
                          [mailto:<a moz-do-not-send="true"
                            href="mailto:keycloak-user-bounces@lists.jboss.org"
                            target="_blank">keycloak-user-bounces@lists.jboss.org</a>]
                          <b>On Behalf Of </b>Haim Vana<br>
                          <b>Sent:</b> Monday, May 30, 2016 10:22 PM<br>
                          <b>To:</b> <a moz-do-not-send="true"
                            href="mailto:stian@redhat.com"
                            target="_blank">stian@redhat.com</a><br>
                          <b>Cc:</b> <a moz-do-not-send="true"
                            href="mailto:keycloak-user@lists.jboss.org"
                            target="_blank">keycloak-user@lists.jboss.org</a><br>
                          <b>Subject:</b> Re: [keycloak-user] How to get
                          specific client role programmatically</span><o:p></o:p></p>
                    </div>
                  </div>
                  <p class="MsoNormal"
                    style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"> <o:p></o:p></p>
                  <p class="MsoNormal"
                    style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif;color:#1F497D">But
                      the ClientRepresentation doesn’t have any getRole
                      method, so how should I do it ?</span><o:p></o:p></p>
                  <p class="MsoNormal"
                    style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif;color:#1F497D"> </span><o:p></o:p></p>
                  <p class="MsoNormal"
                    style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif;color:#1F497D">Here
                      is my code:</span><o:p></o:p></p>
                  <p class="MsoNormal"
                    style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif;color:#1F497D">ClientRepresentation
                      clientRepresentation =
                      masterRealm.clients().findByClientId(realmName +
                      <b>"-realm"</b>).get(0);</span><o:p></o:p></p>
                  <p class="MsoNormal"
                    style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif;color:#1F497D"> </span><o:p></o:p></p>
                  <p class="MsoNormal"
                    style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif;color:#1F497D"> </span><o:p></o:p></p>
                  <p class="MsoNormal"
                    style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif;color:#1F497D">Thanks,</span><o:p></o:p></p>
                  <p class="MsoNormal"
                    style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif;color:#1F497D">Haim.</span><o:p></o:p></p>
                  <p class="MsoNormal"
                    style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif;color:#1F497D"> </span><o:p></o:p></p>
                  <p class="MsoNormal"
                    style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><b><span
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif">From:</span></b><span
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif">
                      Stian Thorgersen [<a moz-do-not-send="true"
                        href="mailto:sthorger@redhat.com"
                        target="_blank">mailto:sthorger@redhat.com</a>]
                      <br>
                      <b>Sent:</b> Monday, May 30, 2016 10:27 AM<br>
                      <b>To:</b> Haim Vana &lt;<a moz-do-not-send="true"
                        href="mailto:haimv@perfectomobile.com"
                        target="_blank">haimv@perfectomobile.com</a>&gt;<br>
                      <b>Cc:</b> <a moz-do-not-send="true"
                        href="mailto:keycloak-user@lists.jboss.org"
                        target="_blank">keycloak-user@lists.jboss.org</a><br>
                      <b>Subject:</b> Re: [keycloak-user] How to get
                      specific client role programmatically</span><o:p></o:p></p>
                  <p class="MsoNormal"
                    style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"> <o:p></o:p></p>
                  <div>
                    <p class="MsoNormal"
                      style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">To
                      get a specific role for a client you need to get
                      the client, then the role from that client. It's
                      not available through the user resource.<o:p></o:p></p>
                  </div>
                  <div>
                    <div>
                      <blockquote style="border:none;border-left:solid
                        #CCCCCC 1.0pt;padding:0in 0in 0in
6.0pt;margin-left:4.8pt;margin-top:5.0pt;margin-right:0in;margin-bottom:5.0pt">
                        <div>
                          <div>
                            <div>
                              <div style="border:none;border-top:solid
                                #E1E1E1 1.0pt;padding:3.0pt 0in 0in 0in">
                                <p class="MsoNormal"
                                  style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><b>From:</b>
                                  <a moz-do-not-send="true"
                                    href="mailto:keycloak-user-bounces@lists.jboss.org"
                                    target="_blank">keycloak-user-bounces@lists.jboss.org</a>
                                  [mailto:<a moz-do-not-send="true"
                                    href="mailto:keycloak-user-bounces@lists.jboss.org"
                                    target="_blank">keycloak-user-bounces@lists.jboss.org</a>]
                                  <b>On Behalf Of </b>Haim Vana<br>
                                  <b>Sent:</b> Wednesday, May 25, 2016
                                  10:53 PM<br>
                                  <b>To:</b> <a moz-do-not-send="true"
href="mailto:keycloak-user@lists.jboss.org" target="_blank">keycloak-user@lists.jboss.org</a><br>
                                  <b>Subject:</b> [keycloak-user] How to
                                  get specific client role
                                  programmatically<o:p></o:p></p>
                              </div>
                            </div>
                            <div>
                              <div>
                                <p class="MsoNormal"
                                  style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"> <o:p></o:p></p>
                                <p class="MsoNormal"
                                  style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">Hi,<o:p></o:p></p>
                                <p class="MsoNormal"
                                  style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"> <o:p></o:p></p>
                                <p class="MsoNormal"
                                  style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">I
                                  am using the KeyCloak API to create
                                  admin users and update their roles, I
                                  am able to add to an admin user all
                                  the available client roles, however
                                  how can I add a specific one ?<o:p></o:p></p>
                                <p class="MsoNormal"
                                  style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"> <o:p></o:p></p>
                                <p class="MsoNormal"
                                  style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">This
                                  is my code to get all the available
                                  client roles:<o:p></o:p></p>
                                <p class="MsoNormal"
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;background:white"><span
                                    style="font-size:11.5pt;font-family:&quot;Courier
                                    New&quot;;color:black">userResource.roles().clientLevel(userRealmClientId).listAvailable()</span><o:p></o:p></p>
                                <p class="MsoNormal"
                                  style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"> <o:p></o:p></p>
                                <p class="MsoNormal"
                                  style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">How
                                  can I get specific one and not all ?<o:p></o:p></p>
                                <p class="MsoNormal"
                                  style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"> <o:p></o:p></p>
                                <p class="MsoNormal"
                                  style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"> <o:p></o:p></p>
                                <p class="MsoNormal"
                                  style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">Any
                                  advice will be appreciated,<o:p></o:p></p>
                                <p class="MsoNormal"
                                  style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">Haim.<o:p></o:p></p>
                                <p class="MsoNormal"
                                  style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"> <o:p></o:p></p>
                                <p class="MsoNormal"
                                  style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">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.
                                  <o:p></o:p></p>
                              </div>
                            </div>
                          </div>
                          <div>
                            <div>
                              <p class="MsoNormal"
                                style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">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.
                                <o:p></o:p></p>
                            </div>
                          </div>
                        </div>
                        <p class="MsoNormal"
                          style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><br>
_______________________________________________<br>
                          keycloak-user mailing list<br>
                          <a moz-do-not-send="true"
                            href="mailto:keycloak-user@lists.jboss.org"
                            target="_blank">keycloak-user@lists.jboss.org</a><br>
                          <a moz-do-not-send="true"
href="https://emea01.safelinks.protection.outlook.com/?url=https%3a%2f%2flists.jboss.org%2fmailman%2flistinfo%2fkeycloak-user&amp;data=01%7c01%7chaimv%40perfectomobile.com%7c23e84d6917a8405f7ae308d38e93c7a1%7cceb4c662d6994e7da0bd272619a46977%7c1&amp;sdata=sLhYtllxBuSVwgemvc7335ro0x%2fKsvw75pDs%2bHTX3OE%3d"
                            target="_blank">https://lists.jboss.org/mailman/listinfo/keycloak-user</a><o:p></o:p></p>
                      </blockquote>
                    </div>
                    <p class="MsoNormal"
                      style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"> <o:p></o:p></p>
                  </div>
                  <p class="MsoNormal"
                    style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">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.
                    <o:p></o:p></p>
                </div>
                <p class="MsoNormal">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. <o:p></o:p></p>
              </div>
            </blockquote>
          </div>
          <p class="MsoNormal"><o:p> </o:p></p>
        </div>
      </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>