Open Closed

Role assignment restrictions for non-admin users #10961


User avatar
0
CompassInformatics created

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

Markdown supported.
Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)

4 Answer(s)
  • User Avatar
    0
    AI-Bot created
    Support Team ABP Agent
    • 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-in admin role, they can only add/remove roles that they already have. That’s why your SuperUser only sees SuperUser in the selector and can only assign that role, while a user in admin can 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):

      1. Keep IdentityPermissions.Users.ManageRoles on SuperUser (required to apply RoleNames changes).

      2. 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 incoming RoleNames during 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)
  • User Avatar
    0
    CompassInformatics created

    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)
  • User Avatar
    0
    CompassInformatics created

    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)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    Hi,

    When a user is saved, the roles go through FilterRolesByCurrentUserAsync in IdentityUserAppService. For an operator who isn't in the admin role, it silently drops every role the operator doesn't have. It's protected virtual, so you can override it in the same class as GetAssignableRolesAsync.

    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. SuperUser can assign its own roles plus Manager and Staff, and only when it has the ManageRoles permission. Users in the admin role 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)
Boost Your Development
ABP Live Training
Packages
See Trainings
Mastering ABP Framework Book
The Official Guide
Mastering
ABP Framework
Learn More
Mastering ABP Framework Book
Made with ❤️ on ABP v10.8.0-preview. Updated on November 16, 2026, 06:26
1
ABP Assistant
🔐 You need to be logged in to use the chatbot. Please log in first.