Open Closed

Permission management across multiple tenants #4959


User avatar
0
portx-dev created

Let's assume that Tenant 1 is treated as a parent tenant, and Tenant 2 and Tenant 3 are child tenants. There is a specification to create roles to be used for Tenant 2 and Tenant 3 on Tenant 1. Is that possible with ABP?

  • ABP Framework version: ABP Commercial 7.1e:
Markdown supported.
Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)

2 Answer(s)
  • User Avatar
    0
    liangshiwei created
    Fullstack Developer

    Hi,

    You can consider creating the same role with permissions for tenants 2 and 3 using domain events or override the application service interface of the module

    • https://docs.abp.io/en/abp/latest/Local-Event-Bus#pre-built-events
    • https://docs.abp.io/en/abp/latest/Customizing-Application-Modules-Overriding-Services

    Pseudocode:

    public class MyIdentityRoleAppService: IdentityRoleAppService
    {
        
        public override async ....CreateAsync()
        {
            create role...
            
            if(CurrentTenant.Name = "Tenant1")
            {
               using(CurrentTenant.Change("Tenant2"))
               {
                  Create role...           
               }
            }
        }
    }
    
    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    0
    liangshiwei created
    Fullstack Developer

    Here's another suggestion:

    If you can accept data sync delay, you can create a background worker to synchronize tenant and role permissions: https://docs.abp.io/en/abp/latest/Background-Workers#asyncperiodicbackgroundworkerbase

    For example:

    public class RolePermissionsSynchronizeWorker : AsyncPeriodicBackgroundWorkerBase
    {
        public RolePermissionsSynchronizeWorker(
                AbpAsyncTimer timer,
                IServiceScopeFactory serviceScopeFactory
            ) : base(
                timer, 
                serviceScopeFactory)
        {
            Timer.Period = 600000; //10 minutes
        }
    
        protected async override Task DoWorkAsync(
            PeriodicBackgroundWorkerContext workerContext)
        {
            Logger.LogInformation("Starting: Sync roles...");
    
            .....
            
            Logger.LogInformation("Completed: Sync roles...");
        }
    }
    
    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 September 23, 2026, 09:57
1
ABP Assistant
🔐 You need to be logged in to use the chatbot. Please log in first.