Hi,
We are using ABP Pro 10.7.0 with Angular. A user with our custom **SuperUser **role can create users, but the role selector only offers SuperUser. A user with the built-in **admin **role can select multiple roles.
SuperUser has AbpIdentity.Users.ManageRoles, as well as the relevant user creation and update permissions.
We also override GetAssignableRolesAsync to exclude certain roles, but that filter applies to both users and does not explain the difference.
Could you confirm:
Is limiting non-admin users to assigning their own roles expected ABP Pro behavior? Can this be configured through permissions, or does it require customization? What is the recommended way to allow SuperUser to assign a specific set of roles, both in the selector and when saving a user, without granting the built-in admin role?
Thanks, Pavel
4 Answer(s)
-
0
Yes — this is expected ABP (Identity module) behavior. Even if a user has
IdentityPermissions.Users.ManageRoles, ABP additionally prevents privilege escalation: unless the operator is in the built-inadminrole, they can only add/remove roles that they already have. That’s why yourSuperUseronly seesSuperUserin the selector and can only assign that role, while a user inadmincan assign any role.This behavior is not configurable via permissions out of the box. The permission (
ManageRoles) only controls whether role changes are processed at all; the “admin can assign any role” rule is an extra security filter.Recommended approach (without granting
admin):Keep
IdentityPermissions.Users.ManageRolesonSuperUser(required to applyRoleNameschanges).Customize the assignable-role pipeline in a way that applies both:
- UI filtering (what appears in the selector)
- Server-side enforcement (what is actually accepted on save)
Concretely, implement your own logic to return exactly the allowed roles for
SuperUser(e.g., a fixed allow-list or a permission-based allow-list), and also validate/limit incomingRoleNamesduring create/update so disallowed roles are rejected or removed.
Since the built-in “non-admin can only assign own roles” rule is hard-coded behavior, achieving “SuperUser can assign a specific set of roles” requires customization (typically by overriding/replacing the relevant Identity application service methods and enforcing your own rule consistently for:
GetAssignableRolesAsync(role picker)- user create/update role assignment (persistence)
Sources:
- https://abp.io/docs/10.7/modules/identity
- https://abp.io/docs/10.7/release-info/migration-guides/abp-6-0
This response was generated by AI. If it didn’t solve your problem, feel free to post a new answer — our support team will jump in to help you soon.
Markdown supported.Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post) -
0
Hi,
great, thanks for the explanation. How can I update user create/update role assignment (persistence) logic? I already know how to update GetAssignableRolesAsync.
Thanks, Pavel
Markdown supported.Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post) -
0
Actually ignore. I have figured it out.
Thanks, Pavel
Markdown supported.Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post) -
0
Hi,
When a user is saved, the roles go through
FilterRolesByCurrentUserAsyncinIdentityUserAppService. For an operator who isn't in theadminrole, it silently drops every role the operator doesn't have. It'sprotected virtual, so you can override it in the same class asGetAssignableRolesAsync.Use the same role list in both methods. If a role is hidden in the list but still allowed on save, editing a user who has that role will remove it.
Here is an example with a fixed role map.
SuperUsercan assign its own roles plusManagerandStaff, and only when it has theManageRolespermission. Users in theadminrole keep the default behavior.// Operator role => extra roles that operator can assign (in addition to its own roles) private static readonly Dictionary<string, string[]> ExtraAssignableRoles = new(StringComparer.OrdinalIgnoreCase) { ["SuperUser"] = ["Manager", "Staff"] }; public override async Task<ListResultDto<IdentityRoleDto>> GetAssignableRolesAsync() { if (await HasAdminRoleAsync()) { return await base.GetAssignableRolesAsync(); } var roles = (await RoleRepository.GetListAsync(await GetManageableRoleNamesAsync())) .OrderBy(x => x.Name) .ToList(); return new ListResultDto<IdentityRoleDto>( ObjectMapper.Map<List<IdentityRole>, List<IdentityRoleDto>>(roles)); } protected override async Task<string[]> FilterRolesByCurrentUserAsync(IdentityUser user, string[] inputRoleNames) { if (await HasAdminRoleAsync()) { return await base.FilterRolesByCurrentUserAsync(user, inputRoleNames); } var manageableRoles = (await GetManageableRoleNamesAsync()).ToHashSet(StringComparer.OrdinalIgnoreCase); var currentRoles = await UserManager.GetRolesAsync(user); // Keep roles the operator can't manage, apply the requested changes for the rest return currentRoles.Where(r => !manageableRoles.Contains(r)) .Concat((inputRoleNames ?? []).Where(manageableRoles.Contains)) .Distinct(StringComparer.OrdinalIgnoreCase) .ToArray(); } protected virtual async Task<List<string>> GetManageableRoleNamesAsync() { var operatorUser = await UserManager.GetByIdAsync(CurrentUser.GetId()); var roles = (await UserManager.GetRolesAsync(operatorUser)).ToList(); if (await PermissionChecker.IsGrantedAsync(IdentityPermissions.Users.ManageRoles)) { roles.AddRange(roles.SelectMany(r => ExtraAssignableRoles.TryGetValue(r, out var extra) ? extra : []).ToList()); } return roles.Distinct(StringComparer.OrdinalIgnoreCase).ToList(); }If your class is in the Application project, also add
[RemoteService(IsEnabled = false)]to it. Otherwise ABP exposes it as a second API under/api/app/....Thanks
Markdown supported.Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)