Spring Security and @Async (Authenticated Users mixed up)

后端 未结 6 568
离开以前
离开以前 2020-11-27 13:03

I asynchronously invoke method with Spring, using @Async.This method invokes other method annotated with @PreAuthorize, Spring Security Annotation. To make authorization wor

6条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-27 13:27

    Using the information from Ralph and Oak -

    If you want to get @Async working with the standard task executor tag, you would set up your Spring XML config like this

    
    
    
    
         
    
    

    Then in your @Async method, you would specify the pool you want to use

    @Async("importPool")
    public void run(ImportJob import) {
       ...
    }
    

    That should work so when whenever you call your @Async method, the threadpool thread will use the same security context as the calling thread

提交回复
热议问题