Get user that runs an asynchronous method

前端 未结 3 2050
遥遥无期
遥遥无期 2021-01-17 18:11

I\'m trying to get the user from spring context in an application spring as follows:

Authentication auth = SecurityContextHolder.getContext().getAuthenticati         


        
3条回答
  •  隐瞒了意图╮
    2021-01-17 18:40

    Spring support for sending asynchronous requests with propagated SecurityContext. From a programming model perspective, the new capabilities appear deceptively simple. You can access to user info in async methods by setting security content strategy name in your security configurer class:

    @Configuration
    @EnableAsync
    public class SpringAsyncConfig implements AsyncConfigurer {
    
        public SpringAsyncConfig() {
            SecurityContextHolder.setStrategyName(SecurityContextHolder.MODE_INHERITABLETHREADLOCAL);
        }
    
    }
    

提交回复
热议问题