- ABP Framework version: v8.1.1
- UI Type: Angular
- Database System: EF Core (SQL Server)
- Tiered (for MVC) or Auth Server Separated (for Angular): yes
- Exception message and full stack trace:
- Steps to reproduce the issue:
Continue of Dynamic permissions question but with more complex scenario.
I have the entities Risk
, Plan
, and Task
with 1-n
relation between them (Risk
1-n Plan
) and (Plan
1-n Task
). each entity has a property OwnerId
which is related to users entity. Now regarding permission: if I assign the RisksPermission
to some user, he should see all risks, but if another user is assigned as owner for a task or plan, he should see the related risks only (not the ones he is not part of). I managed to make this work in a monolith project as follows:
- Define
DynamicPermissionValueProvider
withProviderName = "D"
- When user is assigned as owner for task or plan, grant this user
RisksPermission
using this dynamic provider (usingIPermissionManager.SetAsync
method) - When listing the risks: check if the user has the permission with
RolePermissionValueProvider
orUserPermissionValueProvider
return all risks, if the permission is granted withDynamicPermissionValueProvider
, filter the risks.
Now this approach is good for frontend (angular) when using requiredPolicy
for RoutesService
(if the user has the permission with any provider, he can see the risks menu item).
The problem of this approach with microservice project is that IPermissionManager
is only provided in administration service and can't be used in other services.
How can I achieve this scenario in a microservice project.
Thanks in advance
10 Answer(s)
-
0
Hi,
They are using
RemotePermissionChecker
https://github.com/abpframework/abp/blob/rel-8.3/framework/src/Volo.Abp.AspNetCore.Mvc.Client.Common/Volo/Abp/AspNetCore/Mvc/Client/RemotePermissionChecker.cs#L8you can override it.
-
0
Hi, I checked it and couldn't figure out how to get the provider that is granting the required permission, it can only tell if the permission is granted or not. Also the methods are not defined
virtual
so couldn't override them -
0
-
0
I checked it and it works fine in the
Api.Host
project. How can I use it in the application layer? try to useIPermissionManager
in theProductService.Application
project, it will not work directly. There is some dependency I need to add, can you tell what dependency or projects I need to add to make it work? -
0
Hi,
yes ,you need to add some dependency.
add
Volo.Abp.PermissionManagement.Domain
package and module dependency -
0
Hi, I resovled package and module dependency, and was able to use
IPermissionManager
in my service, but faced another issue. I defined newDynamicPermissionManagementProvider
extendsPermissionManagementProvider
andDynamicPermissionValueProvider
extendsPermissionValueProvider
to grant some users some dynamic permissions. I was able to use the new provider and could see the granted permissions in the tableAbpPermissionGrants
in database. Also logged the result of getting the permission using this line of code:var granted = await _permissionManager.GetAsync(RisksManagementServicePermissions.Risks.Default, DynamicPermissionValueProvider.ProviderName, CurrentUser.Id.Value.ToString());
And found that the permission is actually granted to the user using my provider. But from angular side, when sending
application-configuration
request (which includes in its responseauth -> grantedPolicies
to tell angular app current users' permissions, I don't see my permission granted!Any idea?
-
0
Hi,
But from angular side, when sending application-configuration request (which includes in its response auth -> grantedPolicies to tell angular app current users' permissions, I don't see my permission granted!
You may need to custom the
AbpApplicationConfigurationAppService
service https://github.com/abpframework/abp/blob/dev/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/AbpApplicationConfigurationAppService.cs -
0
Hi, I managed to make it work without any customization. The issue was that I defined my custom permission provider in another microservice, and the configuration request was redirected to administration service. When I moved the permission provider to administration service, it worked. Now I have a question related to some code that I needed to write:
To add my provider I needed to write this code
public override void ConfigureServices(ServiceConfigurationContext context) { // Other codes Configure<PermissionManagementOptions>(options => { options.ManagementProviders.Add<DynamicPermissionManagementProvider>(); options.ProviderPolicies[DynamicPermissionValueProvider.ProviderName] = AdministrationServicePermissions.Dashboard.Host; }); Configure<AbpPermissionOptions>(options => { options.ValueProviders.Add<DynamicPermissionValueProvider>(); }); }
My question is about this line
options.ProviderPolicies[DynamicPermissionValueProvider.ProviderName] = AdministrationServicePermissions.Dashboard.Host;
Why is this needed? and does it matter what permission I provide for it?
-
0
-
0
Hi, Thank you. It's clear now