Open Closed

Check multiple permission with Authorization Attribute #8643


User avatar
0
sukhdeep.dhillon created
  • ABP Framework version: v8.2.1
  • UI Type: Angular
  • Database System: EF Core (SQL Server)

in Abp, is there any way to check multiple permission with Authorization attribute as OR operator.

[Authorization(permission1, permission2, permission3)] public Task CreateAsync(){

}


1 Answer(s)
  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    You can try this:

    Configure<AuthorizationOptions>(options =>
    {
        options.AddPolicy("TestPermission1_And_TestPermission2", policy =>
        {
            policy.Requirements.Add(new PermissionsRequirement(["TestPermission1", "TestPermission2"], requiresAll: true));
        });
        
        options.AddPolicy("TestPermission1_Or_TestPermission2", policy =>
        {
            policy.Requirements.Add(new PermissionsRequirement(new []{"TestPermission1", "TestPermission2"}, requiresAll: false));
        });
    });
    
    [Authorize("TestPermission1_And_TestPermission2")]
    
    .....
    
    [Authorize("TestPermission1_Or_TestPermission2")]
    
Made with ❤️ on ABP v9.2.0-preview. Updated on January 20, 2025, 07:44