abp icon indicating copy to clipboard operation
abp copied to clipboard

Permissions not detected

Open duard-sf opened this issue 6 years ago • 2 comments

As the host admin, I am creating a new tenant. Upon creation of the tenant, I manually create an admin user for this tenant and a new admin role for this admin user, and assign the following permissions to this role:

  • IdentityPermissions.Roles.Default
  • IdentityPermissions.Roles.Create
  • IdentityPermissions.Roles.Update
  • IdentityPermissions.Roles.Delete
  • IdentityPermissions.Roles.ManagePermissions

using

await _permissionManager.SetForRoleAsync(tenantAdminRoleName, permission, true)

Role creation is done as follows:

var tenantAdminRole = new IdentityRole(
        GuidGenerator.Create(),
        tenantAdminRoleName,
        tenantId
    )
    {
        IsDefault = false,
        IsPublic = true
    };

(await _roleManager.CreateAsync(tenantAdminRole)).CheckErrors();
(await _userManager.AddToRoleAsync(tenantAdmin, tenantAdminRoleName)).CheckErrors();

In the database I can verify that the user and role are created correctly with the relevant tenant ID, and the admin role is assigned to the admin user.

When querying the AbpPermissionGrants table, I can verify that the permissions are attached to the admin role (ProviderName is R and ProviderKey is the name of the admin role). However, these AbpPermissionGrants records do not have a tenant ID.

Furthermore, only when I manually update the above-mentioned AbpPermissionGrants records with the correct tenant ID, and restart the ABP application, then does the user's permissions reflect in the application-configuration endpoint's response's auth.grantedPolicies property.

So: how can I, as the host admin, create an admin user for a tenant, and assign this user a new role with permissions?

duard-sf avatar Jan 02 '20 08:01 duard-sf

Try switching to the tenant.

using(CurrentTenant.Change(tenantId))
{
	await _permissionManager.SetForRoleAsync(tenantAdminRoleName, permission, true)
}

maliming avatar Jan 02 '20 08:01 maliming

Thanks, that seems to have resolved the issue!

duard-sf avatar Jan 02 '20 08:01 duard-sf