Example #1
0
  protected void addComposites(AccessToken token, RoleModel role) {
    AccessToken.Access access = null;
    if (role.getContainer() instanceof RealmModel) {
      access = token.getRealmAccess();
      if (token.getRealmAccess() == null) {
        access = new AccessToken.Access();
        token.setRealmAccess(access);
      } else if (token.getRealmAccess().getRoles() != null
          && token.getRealmAccess().isUserInRole(role.getName())) return;

    } else {
      ClientModel app = (ClientModel) role.getContainer();
      access = token.getResourceAccess(app.getClientId());
      if (access == null) {
        access = token.addAccess(app.getClientId());
        if (app.isSurrogateAuthRequired()) access.verifyCaller(true);
      } else if (access.isUserInRole(role.getName())) return;
    }
    access.addRole(role.getName());
    if (!role.isComposite()) return;

    for (RoleModel composite : role.getComposites()) {
      addComposites(token, composite);
    }
  }
 private void processRoles(
     Set<RoleModel> inputRoles,
     List<RoleModel> realmRoles,
     MultivaluedHashMap<String, ClientRoleEntry> clientRoles) {
   for (RoleModel role : inputRoles) {
     if (role.getContainer() instanceof RealmModel) {
       realmRoles.add(role);
     } else {
       ClientModel currentClient = (ClientModel) role.getContainer();
       ClientRoleEntry clientRole =
           new ClientRoleEntry(
               currentClient.getClientId(),
               currentClient.getName(),
               role.getName(),
               role.getDescription());
       clientRoles.add(currentClient.getClientId(), clientRole);
     }
   }
 }
Example #3
0
  protected Set<RoleRepresentation> getRealmRoleComposites(RoleModel role) {
    if (!role.isComposite() || role.getComposites().size() == 0) return Collections.emptySet();

    Set<RoleRepresentation> composites =
        new HashSet<RoleRepresentation>(role.getComposites().size());
    for (RoleModel composite : role.getComposites()) {
      if (composite.getContainer() instanceof RealmModel)
        composites.add(ModelToRepresentation.toRepresentation(composite));
    }
    return composites;
  }
Example #4
0
  @Override
  public Set<RoleModel> getRealmRoleMappings() {
    Set<RoleModel> roleMappings = getRoleMappings();

    Set<RoleModel> realmRoles = new HashSet<RoleModel>();
    for (RoleModel role : roleMappings) {
      RoleContainerModel container = role.getContainer();
      if (container instanceof RealmModel) {
        realmRoles.add(role);
      }
    }
    return realmRoles;
  }
Example #5
0
  public Set<RoleModel> getRealmScopeMappings() {
    Set<RoleModel> roleMappings = getScopeMappings();

    Set<RoleModel> appRoles = new HashSet<RoleModel>();
    for (RoleModel role : roleMappings) {
      RoleContainerModel container = role.getContainer();
      if (container instanceof RealmModel) {
        if (((RealmModel) container).getId().equals(cachedRealm.getId())) {
          appRoles.add(role);
        }
      }
    }

    return appRoles;
  }
Example #6
0
  @Override
  public Set<RoleModel> getApplicationRoleMappings(ApplicationModel app) {
    Set<RoleModel> roleMappings = getRoleMappings();

    Set<RoleModel> roles = new HashSet<RoleModel>();
    for (RoleModel role : roleMappings) {
      RoleContainerModel container = role.getContainer();
      if (container instanceof ApplicationModel) {
        ApplicationModel appModel = (ApplicationModel) container;
        if (appModel.getId().equals(app.getId())) {
          roles.add(role);
        }
      }
    }
    return roles;
  }
Example #7
0
  protected Set<RoleRepresentation> getApplicationRoleComposites(String appName, RoleModel role) {
    if (!role.isComposite() || role.getComposites().size() == 0) return Collections.emptySet();

    ApplicationModel app = realm.getApplicationByName(appName);
    if (app == null) {
      throw new NotFoundException("Could not find application: " + appName);
    }

    Set<RoleRepresentation> composites =
        new HashSet<RoleRepresentation>(role.getComposites().size());
    for (RoleModel composite : role.getComposites()) {
      if (composite.getContainer().equals(app))
        composites.add(ModelToRepresentation.toRepresentation(composite));
    }
    return composites;
  }
Example #8
0
  @Override
  public Set<RoleModel> getClientScopeMappings(ClientModel client) {
    Set<RoleModel> roleMappings = client.getScopeMappings();

    Set<RoleModel> appRoles = new HashSet<RoleModel>();
    for (RoleModel role : roleMappings) {
      RoleContainerModel container = role.getContainer();
      if (container instanceof RealmModel) {
      } else {
        ClientModel app = (ClientModel) container;
        if (app.getId().equals(getId())) {
          appRoles.add(role);
        }
      }
    }

    return appRoles;
  }
Example #9
0
 protected void deleteRole(RoleModel role) {
   if (!role.getContainer().removeRole(role)) {
     throw new NotFoundException("Role not found");
   }
 }