<html>
  <head>
    <meta content="text/html; charset=windows-1252"
      http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <div class="moz-cite-prefix">Hi,<br>
      <br>
      you should use method "userModel.grantRole(role)" to add new role
      mapping. Methods "getRoleMappings" and "getRealmRoleMappings" are
      used just for reading existing role mappings of user.<br>
      <br>
      Marek<br>
      <br>
      On 15.6.2015 16:49, Scott Rossillo wrote:<br>
    </div>
    <blockquote
      cite="mid:4154AAD4-3C42-422B-8FD5-FAA21732B91B@smartling.com"
      type="cite">
      <meta http-equiv="Content-Type" content="text/html;
        charset=windows-1252">
      Hey all,
      <div class=""><br class="">
      </div>
      <div class="">I was going to create a JIRA for this, but just want
        to make sure it’s an actual bug. We are not able to assign roles
        to a user from a federation provider.</div>
      <div class=""><br class="">
      </div>
      <div class="">For example, we expected something like this to work
        from UserFederationProvider. getUserByUsername(RealmModel realm,
        String username):</div>
      <div class=""><br class="">
      </div>
      <div class="">
        <div style="margin: 0px; font-size: 11px; font-family: Menlo;
          color: rgb(102, 102, 102);" class="">        if
          (remoteUser.getRoles() != null) {</div>
        <div style="margin: 0px; font-size: 11px; font-family: Menlo;
          color: rgb(102, 102, 102);" class="">            for (String
          roleName : remoteUser.getRoles()) {</div>
        <div style="margin: 0px; font-size: 11px; font-family: Menlo;
          color: rgb(102, 102, 102);" class="">                RoleModel
          role = realm.getRole(roleName);</div>
        <div style="margin: 0px; font-size: 11px; font-family: Menlo;
          color: rgb(102, 102, 102);" class="">               
          userModel.getRoleMappings().add(role); // doesn’t work</div>
        <div style="margin: 0px;" class=""><span style="color: rgb(102,
            102, 102); font-family: Menlo; font-size: 11px;" class=""> 
                         </span><span style="color: rgb(102, 102, 102);
            font-family: Menlo; font-size: 11px;" class=""> </span><font
            class="" color="#666666" face="Menlo"><span
              style="font-size: 11px;" class="">userModel.getRealmRoleMappings().add(role); </span></font><span
            style="color: rgb(102, 102, 102); font-family: Menlo;
            font-size: 11px;" class="">// doesn’t work</span></div>
        <div style="margin: 0px; font-size: 11px; font-family: Menlo;
          color: rgb(102, 102, 102);" class="">            }</div>
        <div style="margin: 0px; font-size: 11px; font-family: Menlo;
          color: rgb(102, 102, 102);" class="">        }</div>
      </div>
      <div class=""><br class="">
      </div>
      <div class="">However, nothing but the default role is assigned
        even when we confirm additional roles are assigned to remoteUser
        and realm.getRole() returns a valid RoleModel.</div>
      <div class=""><br class="">
      </div>
      <div class="">Create JIRA or should we be assigning roles from a
        UserFederationProvider in another way?</div>
      <div class=""><br class="">
      </div>
      <div class="">Thanks</div>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <br>
      <pre wrap="">_______________________________________________
keycloak-dev mailing list
<a class="moz-txt-link-abbreviated" href="mailto:keycloak-dev@lists.jboss.org">keycloak-dev@lists.jboss.org</a>
<a class="moz-txt-link-freetext" href="https://lists.jboss.org/mailman/listinfo/keycloak-dev">https://lists.jboss.org/mailman/listinfo/keycloak-dev</a></pre>
    </blockquote>
    <br>
  </body>
</html>