Mic*_*sen 8 java spring-security spring-boot hystrix spring-cloud
我正在运行一个spring boot应用程序,刚刚开始从spring-cloud-netflix集成Hystrix.我正在使用@HystrixCommand来封装使用假装客户端进行的服务到服务调用.
@HystrixCommand(fallbackMethod = "updateThingFallback")
def updateRemoteThing(thingResourceClient: ThingResourceClient, thing: Thing) {
thingResourceClient.updateThing(thing) // Call using feign client
}
Run Code Online (Sandbox Code Playgroud)
此假装客户端使用spring安全上下文为其发出的请求添加安全标头.
我遇到的问题是,当执行HystrixCommand时,它在Hystrix线程池的一个单独的线程中运行,当我的代码尝试访问spring安全上下文时,它在新线程上不可用.
我正在访问Spring安全上下文,如下所示:
SecurityContextHolder.getContext().getAuthentication();
Run Code Online (Sandbox Code Playgroud)
我的问题是,spring是否提供了一种将Spring安全上下文(和应用程序上下文)传递给运行Hystrix命令的Hystrix线程的方法?
Ond*_*zek 10
从Spring Cloud Netflix 1.2.0开始,您可以使用config param与Hystrix共享安全上下文:
hystrix.shareSecurityContext: true
您应该可以ApplicationContext通过常规方法将放入您的bean中。我可以看到两种传递身份验证对象的方法:1)作为方法的参数,或2)使用信号量隔离而不是在单独的线程上运行hystrix 。
@HystrixCommand(fallbackMethod = "updateThingFallback", commandProperties = {
@HystrixProperty(name = "execution.isolation.strategy", value = "SEMAPHORE")
})
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3117 次 |
| 最近记录: |