-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FEIGN + OAUTH2 calls from another thread not propagating security #1330
Comments
Hi there, checkout the reference doc on 1.2.0.M1. A new property |
Hi, I've tried with M1, but that didn't resolved my issue :( |
I'll check out your sample project tomorrow and give a try on finding out what's wrong. |
I've checked out your project and I don't understand why you want to make a call with Feign from a home made executor. By default, Feign operations are already wrapped in a seperate Hyxtrix thread. If you keep this simple setup, you can activate the You can checkout this unit test here. The test actually sets up a Feign Client with an interceptor that generates a http header based on the username of the SecurityContext. The interceptor is invoke in a separate thread by Hystrix, proving that it is properly delegated automatically. Explain your use case a bit more so I can guide you more efficiently. Regards, |
@daniellavoie I need to execute it in another thread, because the application is build in this style. Application "rest-api" code is executed within main thread and another threads are used to do validation and call another services. Code is based on AxonFramework if that helps you. My application only demonstrates the usage of code. If you need more info, let me know. Thanks |
The You can inspire yourself of this PR. It leverages the Good luck. |
@daniellavoie try to look at this commit. I've just wrapped the client call in another callable and added |
Tell me if I am wrong but I have the feeling that 3 threads are involved in your current setup.
Considering this setup, if you include in your classpath |
Ok so I removed the "wrapper" callable and added spring-boot-starter-security to the dependencies, enabled hystrix.shareSecurityContext=true. But unfortunately I've got again No thread-bound request found. There could be probably possibility in hystrix to pass the current request attributes to child threads, something as I wrote in wrapper class ... here is branch with current code. |
You should not remove the wrapper callable as you are in a 3 thread hierarchy setup. the I am no expert on Spring Cloud OAuth so I will checkout the implementation to find if the |
maybe @dsyer can help us here to specify which attributes needs to be transfered. Then we can maybe create something like DelegatinOAuth2SecurityContext classes. |
I've resolved the issue using custom |
@bilak is it still an issue with the latest release trains? If that's the case can you please open a new issue in the https://github.com/spring-cloud/spring-cloud-openfeign/ project? |
By default, the Spring Security Authentication is bound to a ThreadLocal – so, when the execution flow runs in a new thread with (Observable.zip) that’s not going to be an authenticated context. To prevent that behaviour, we need to enable the SecurityContextHolder.MODE_INHERITABLETHREADLOCAL strategy: |
Hi,
I'm spending hard times with setup of feign client while I want it to call service from not current thread.
First attempt was to call feign client from current thread. To do this I've added RequestContextFilter but that didn't helped. Then I found this thread and I configured property
feign.hystrix.enabled: false
and finally I was able to call feign client from current thread.Now for the issue:
For security context propagation I'm using DelegatingSecurityContextAsyncTaskExecutor as I hope this executor is suitable to do so. In this executor I'm executing
Callable
which calls feignClient, but I allways get this exception:here is my sample project. When you start both services follow this steps:
Can someone point me to correct setup for feign and oauth2 to have working calls? Is it also possible to enable hystrix for this (use SEMAPHORE or something else)?
The text was updated successfully, but these errors were encountered: