Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,14 @@ public final List<ClientRole> listAvailableRoleMappings(@PathParam("id") String
}

private Set<String> getRoleIdsWithPermissions(String roleResourceScope, String clientResourceScope) {
Set<String> roleIds = this.auth.roles().getRoleIdsByScope(roleResourceScope);
Set<String> clientIds = this.auth.clients().getClientIdsByScope(clientResourceScope);
clientIds.stream().flatMap(cid -> realm.getClientById(cid).getRolesStream()).forEach(role -> roleIds.add(role.getId()));
Set<String> roleIds;
if (AdminPermissionsSchema.SCHEMA.isAdminPermissionsEnabled(realm) && canPerformOnAllClients(clientResourceScope)) {
roleIds = session.clients().getClientsStream(realm).flatMap(client -> client.getRolesStream()).map(RoleModel::getId).collect(Collectors.toSet());
} else {
roleIds = this.auth.roles().getRoleIdsByScope(roleResourceScope);
Set<String> clientIds = this.auth.clients().getClientIdsByScope(clientResourceScope);
clientIds.stream().flatMap(cid -> realm.getClientById(cid).getRolesStream()).forEach(role -> roleIds.add(role.getId()));
}
return roleIds;
}

Expand All @@ -254,4 +259,17 @@ private List<ClientRole> searchForClientRolesByExcludedIds(RealmModel realm, Str
Stream<RoleModel> result = session.roles().searchForClientRolesStream(realm, search, excludedIds, first, max);
return result.map(role -> RoleMapper.convertToModel(role, realm)).collect(Collectors.toList());
}

private boolean canPerformOnAllClients(String scope) {
switch (scope) {
case MAP_ROLES:
return auth.clients().canMapRoles(null);
case MAP_ROLES_COMPOSITE:
return auth.clients().canMapCompositeRoles(null);
case MAP_ROLES_CLIENT_SCOPE:
return auth.clients().canMapClientScopeRoles(null);
default:
return false;
}
}
}
Loading