Base solution for your next web application
Open Closed

I'm having incovenientes to obtain values of AbpPermissions #1565


User avatar
0
sferrari created

Hello, first of all thank you for sharing such a beautiful project, on the other hand I write from Argentina and my English is not very good, sorry po know that.

I'm having incovenientes to obtain permits from the "AbpPermissions" table, I thought that the permissions of user and automatically obteniean when logueaba.

Then a suuario see the logs in, try to get it with the following methods, and eh not been able to do:

var permission = _permissionManager.GetAllPermissions (false); var permission1 = _permissionManager.GetPermissionOrNull (Manager.Core.Authorization.PermissionNames.Module_MyAccount); var permission2 = _permissionManager.GetPermission (Manager.Core.Authorization.PermissionNames.Module_MyAccount);

var user = _userManager.FindById (1); var list = await _userManager.GetGrantedPermissionsAsync (user);

var list1 = await _userStore.GetPermissionsAsync (1);

I have already read in the forum, and also the documents:

  • <a class="postlink" href="http://www.aspnetboilerplate.com/Pages/Documents/Zero/Permission-Management">http://www.aspnetboilerplate.com/Pages/ ... Management</a>
  • <a class="postlink" href="http://www.aspnetboilerplate.com/Pages/Documents/Authorization">http://www.aspnetboilerplate.com/Pages/ ... horization</a>

But I do not use any Provider, I want to get permsisos AbpPermissions desdde the table.

I hope to receive an answer to this, I attached the print screen of the database.

Thank you very much !


11 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    Why do you need to get records from AbpPermissions table ? In most cases, you dont need records in AbpPermissions table.

  • User Avatar
    0
    sferrari created

    Hi, thanks for the reply, permissions must not be stored in the table AbpPermissions? but that it would be used?

    On the other hand I do not understand how to use: MyAuthorizationProvider as permission to relate the role id or user id logged?

    Attached the print screen of the table "AbpPermissions"

    Thank you.

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    You dont need to do anything. ABP automatically does that for you. It finds the Id of logged in user, find user's role and check permisisons according to User permissin -> Role permission -> default permission value respectively.

    You just need to use an attribute like this

    [AbpAuthorize("Administration.UserManagement.CreateUser")]
    public void CreateUser(CreateUserInput input)
    {
        //A user can not execute this method if he is not granted for "Administration.UserManagement.CreateUser" permission.
    }
    

    or like this,

    if (!PermissionChecker.IsGranted("Administration.UserManagement.CreateUser"))
    {
        throw new AbpAuthorizationException("You are not authorized to create user!");
    }
    
  • User Avatar
    0
    sferrari created

    So in my case example happens to you, the role name must match the name of the provider permission?

    Ex. Table AbpUsers = id: 1 Name: xxxxx Table AbpUserRoles = id: 1 idUser: 1 idRol: 1

    Table AbpRoles = id: 1 name: Master

    In the provider you have to coindir the role name, as you associate with the permission of the user provider role id or id?

    The provider must match one of these data in the table?

    Thank you.

  • User Avatar
    0
    sferrari created

    Hello, print screen step how to implement the provider and the attribute of the controller tells me permission does not exist ...

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    Did you add ManagerAuthorizationProvider to Providers ?

    You should do it in the PreInitialize method of your Application Module like this.

    public override void PreInitialize()
    {
        //Adding authorization providers
        Configuration.Authorization.Providers.Add<ManagerAuthorizationProvider >();
    }
    

    and your Controller should inherit from AbpController or if you created your project from aspnetboilerplate website template the it should inherit from [*ControllerBase] class.

  • User Avatar
    0
    sferrari created

    OK: public override void PreInitialize() { //Remove the following line to disable multi-tenancy. Configuration.MultiTenancy.IsEnabled = true;

            //Add/remove localization sources here
            Configuration.Localization.Sources.Add(
                new DictionaryBasedLocalizationSource(
                    ManagerConsts.LocalizationSourceName,
                    new XmlEmbeddedFileLocalizationDictionaryProvider(
                        Assembly.GetExecutingAssembly(),
                        "Manager.Core.Localization.Source"
                        )
                    )
                );
    
            AppRoleConfig.Configure(Configuration.Modules.Zero().RoleManagement);
    
            Configuration.Authorization.Providers.Add&lt;ManagerAuthorizationProvider&gt;();
    
            Configuration.Settings.Providers.Add&lt;EmailSettingDefinitionProvider&gt;();
        }
    

    OK: [AbpMvcAuthorize(PermissionNames.Module_Customers)] public class CustomersController : ManagerControllerBase


    public class ManagerAuthorizationProvider : AuthorizationProvider { public override void SetPermissions(IPermissionDefinitionContext context) {

            var moduleCustomers = context.CreatePermission(PermissionNames.Module_Customers)
                .CreateChildPermission(PermissionNames.Module_Customers_Create)
                .CreateChildPermission(PermissionNames.Module_Customers_Edit)
                .CreateChildPermission(PermissionNames.Module_Customers_Delete);
    
        }
    

    }

    Hi thanks for the reply, I tell you that goes for the role = 1, but not for the role = 2, do not understand why?

  • User Avatar
    0
    sferrari created

    Hi, as I do for work authorization attributes "AbpMvcAuthorization" for example for 2 roles? I only work for one role?

    Ej.

    Table AbpUsers = id: 1 Name: xxxxx

    Table AbpUserRoles = id: 1 idUser: 1 idRol: 1

    Table AbpRoles = id: 1 name: Master id: 2 name: Admin

    It works OK !


    Ej.

    Table AbpUsers = id: 1 Name: xxxxx

    Table AbpUserRoles = id: 1 idUser: 1 idRol: 2

    Table AbpRoles = id: 1 name: Master id: 2 name: Admin

    It does not work.

  • User Avatar
    0
    sferrari created

    PLEASE HELP !!!! :(

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    As I understand, in your case 1 user have two roles right ? For examle "xxxx" user has both "Admin" and "Master" roles right ?

  • User Avatar
    0
    sferrari created

    Hi, User ID 1 => ROLE = "Master" => is ok User ID 2 => ROLE = "Admin" => error (not permission Module.Configuration), why it does not work ?