Open Closed

BackgroundJob Authorization #5039


User avatar
0
russell.thompson created
  • ABP Framework version: v7.2.1
  • UI type: MVC
  • DB provider: EF Core
  • Tiered (MVC) or Identity Server Separated (Angular): no

In our application we allow users to create many records by importing from a file. Because this file may take a long time to process, the creation of the records is performed from a BackgroundJob. Unfortunately, we are then unable to call any app service methods that require authorization. We really want the file to process under the permissions of the user who uploaded it.

Is there something comparable to using (CurrentTenant.Change(tenantId)) { } for setting the CurrentUser? If not that, then what is the recommended approach for dealing with long running actions so that they run in the context of the user performing the action? This is just one example of a number of possible long running actions in our application.


4 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    You can call the domain services in your job.

    The app services are designed for UI.

    Put your app services code to domain services and call it from app services and job.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    Another way is c# proxy.

    https://support.abp.io/QA/Questions/1364/Authorization-in-event-handlers#answer-b530cbdc-4e38-26cb-4120-39fcae2885e8 https://support.abp.io/QA/Questions/1364/Authorization-in-event-handlers#answer-99a457e8-f44b-7606-3238-39fcb87724ee

  • User Avatar
    0
    russell.thompson created

    Thank you for the ideas. After making the post, I saw some documentation about ICurrentPrincipalAccessor.Change https://docs.abp.io/en/abp/latest/CurrentUser#changing-the-current-principal

    Could this also be used in my case and allow the entities to have a proper audit history of the user that created the entity?

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    This is not the recommended practice in your case.

Made with ❤️ on ABP v9.1.0-preview. Updated on December 10, 2024, 06:38