-
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
Hystrix shareSecurityContext is not working #1336
Comments
Can you share a project where I can have a look ? |
BTW, I don't see Spring Security Starter in your gradle. The |
hi. i have some effort to share the project on github, therefore i will needs some hours, but would like to answer your question. org.springframework.cloud:spring-cloud-starter-oauth2 depends on spring-cloud-starter-security and spring-security-core and so on, therefore i think i have all dependencies in. i can also debug through the autoconfiguration HystrixSecurityAutoConfiguration where the "existingConcurrencyStrategy" is null and gets wrapped into the SecurityContextConcurrencyStrategy. but then the exception occurs in the called OAuth2FeignRequestInterceptor at |
@daniellavoie I think this is the same issue as mine. The problem is that RequestContextHolder doesn't hold the attributes for child threads. |
I fear that the |
you can see my code within this project and/or the other Org Projects there: https://github.com/dennyh89-spring-cloud-ref/microservice-two the config is a bit mixed between config-repo and bootstrap.yml as i have tried around a little bit but it should be easy to follow. |
This project does not even run. I am not sure you understand how |
it is now runnable (i forgot to checkin gradle directory with it - gradle bootRun) |
My small input maybe you don't realize it. I tried to solve it myself, and maybe I don't understand it fully but there is few places where HystrixConcurrencyStrategy is tweaked: user can inject a bean - it will be picked by HystrixSecurityAutoConfiguration and wrap it with something that wraps callable. There is also SleuthHystrixConcurrencyStrategy which takes HystrixConcurrencyStrategy from HystrixPlugins.getInstance().getConcurrencyStrategy(). If it executes after HystrixSecurityAutoConfiguration will wrap already wrapped strategy, but if order will be different then Sleuth will replace plugin and then will be overriden by HystrixSecurityAutoConfiguration (sorry for syntax, I don't know how to explain it in polish even). I'm not sure what the order will be, will test it maybe later but my suggestion:
Maybe it would be nice to introduce Strategy that could be a general wrapper for some 'callablewrapperproviders' that could be chained. It would simplify what has to be done to extend it. Code in HystrixSecurityAutoConfiguration and SleuthHystrixConcurrencyStrategy it quite complicated (and similar) and this way it would be as simple as registering new 'histrixcallablewrapperprovider' bean or something. Making this strategy as default would not break existing code even. Because currently to do it by myself I Have to almost copy code from one of the above classes:/ |
There is a fundamental flaw on the implementation of The OAuth2FeignRequestInterceptor should be getting the token value from the
instead of going after the
This should be the case, because we are dealing with the SecurityContext which gets associated to the current thread of execution on cc. @dsyer; @miguelsauza; @joaoevangelista |
I was able to work around this by doing the below
|
I can issue a PR, if you agree with this approach. |
Actually, I don't think that is the right approach. The Also, the code you linked to is in a different project. Maybe you should open an issue or pull request there instead? |
@dsyer - I can create another issue, give you the github project and work with you for a PR But if I understand you correctly, you are acknowledging that there is an issue and you are saying it would be better to change the implementation of Currently the issue happens within this method, And if I step through with my debugger I can grab the detailed message as
Stacktrace
|
Your debugging probably suggests that the solution could be in spring-cloud-netflix (supporting |
@dsyer - Thank you for clarifying. I got your coordinates now. And I was able to get the request attributes propagated to the I have an auto configuration
The If you like this approach, I can issue a PR. |
I think it is better to collapse the logic, while enabling Also should not be looking for the presence of |
We had already written our token relay implementation based on the It works with stuff wrapped in @daniellavoie do you see any pitfall in this approach ? It seems far too simple compared to what you did in 5b0f601. @dsyer would it be a bad idea to suggest that Spring Boot could auto-configure the |
That won't work with refresh tokens, but neither will anything else in this project (that's more of a spring-cloud-security thing) so it seems like a reasonable solution if it works for you. I'm kind of surprised it works though because |
@alwaysastudent I don't think we want to link security and request scope together in a single class (they come from different dependencies). I think Spring Cloud Netflix allows you to stack Hystrix strategies together (but I don't recall if that applies to the concurrency strategy - if not we'd have to see if we can extend something). If you are still working on a PR, please try and split it up so it works when Spring Security is not in use. |
OK that's the catch. I was using a FeignClient within an
|
That's because |
@dsyer - Makes sense. I am thinking to have a |
Closing as Hystrix is no longer supported within Spring Cloud Netflix. |
Hi all.
i am using the following libs and versions:
i try to get hystrix working in the THREAD isolation strategy mode relaying AccessTokens, therefore i tried both, Oauth2RestTemplate and Feign.
I also set the
feign.hystrix.enabled
property to true and alsohystrix.shareSecurityContext
to true but still getting the "no thread bound" exception when making the service to service call. it is just working with setting the SEMAPHORE strategy.Any ideas? @daniellavoie
The text was updated successfully, but these errors were encountered: