-
Notifications
You must be signed in to change notification settings - Fork 6.1k
ReactiveSecurityContextHolder.getContext() is broken when used with Mono.toFuture(). #5690
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
Comments
Thanks for the report. If it is just an arbitrary Future I would not expect it to work. However, if the Future was produced from a What are your thoughts @simonbasle and @smaldini? |
@rwinch In my test, the |
@dave-fl Right. This is why I didn't immediately close the issue since this seems somewhat reasonable to support to me. In any case, this is something we will need Project Reactor to support. which is why I pinged Simon and Stephane. We will wait to see what their thoughts are. |
Another simple example.
|
@dave-fl you are switching to a I gather you did that first test to simulate using an external The |
@simonbasle Yes using Caffeine Async Cache - which uses futures. I don't believe it changes the future as its just storing what its being provided. |
Is there anything that can be done with the subscription to preserve the context? |
How do you mean? |
@simonbasle I guess what I am asking you is that if one wanted to introduce their own Mono as I have done in this example, is there not a means to patch in that context so that chain is not broken e.g. do whatever it is that is normally done in the completion stage. |
The sink has a That said, subscribe inside create is an anti-pattern to me, and it achieves nothing. Probably just an attempt at reproducing the issue, but it fails by nature and not as a byproduct of a bug. (bit like saying "this code throws a NPE: |
The same problem seems to exist if I try to use SecurityContext in RxJava2 flow.
Is there any way to access the current security context if using RxJava data types in WebFlux RestController? I tried also with RxJava2Adapter and with Mono.toFuture, as said above the context is visible only when staying purely in reactor flow. |
Nope, the reactive metadata |
I was able to transfer the SecurityContext to RxJava flow using reactor Hooks and custom operator which copies the SecurityContext from reactor context to ThreadLocal as Single created from Mono. Needs some more testing, but looks promising for some of our existing services heavily using RxJava and soon migrating to SpringBoot2. |
Might this also provide a solution for retrieving the SecurityContext within Spring Data AuditorAware implementations? |
@lee-gilbert I'm not sure. Can you provide more information? |
@rwinch It appears the issue is discussed without a solution here: |
Sorry, this might be a bit off topic but not by much because it questions if ReactiveSecurityContextHolder and Future are related at all. Doesn't that violate a Mono<> protocol? |
(sounds indeed a bit off-topic and potentially a separate issue / question, but here goes)
these statements seem to contradict each other. are you subscribing to the the Bear in mind that some You should definitely not disconnect the |
Uh oh!
There was an error while loading. Please reload this page.
Summary
ReactiveSecurityContextHolder
is broken when used with Futures. It does not always provide results and sometimes just fires the onComplete signal.Actual Behavior
Executes onComplete()
Expected Behavior
Should execute onNext()
Version
5.0.7 Release
Sample
The text was updated successfully, but these errors were encountered: