feature: Integration with WebFlux ReactiveSecurityContextHolder
See original GitHub issueDescribe the Feature Request
Currently we are trying to access ReactiveSecurityContextHolder to fetch the Principal, since we are dependant on Roles to show the proper Data.
e.g.:
@DgsQuery(field = "stuffByFilter")
public CompletionStage<List<Stuff>> leaves(@InputArgument("filter") final StuffFilter filter) {
return ReactiveSecurityContextHolder.getContext()
.map(SecurityContext::getAuthentication)
.map(Authentication::getPrincipal)
.map(Object::toString)
.doOnNext(log::info)
.flatMapMany(principal -> randomStuff())
.collectList()
.toFuture();
}
The above code returns empty list as no logging is generated and no breakpoints are hit.
Describe Preferred Solution
Ideally we could get the current Principal available in the WebFlux Call chain via ReactiveSecurityContextHolder
Issue Analytics
- State:
- Created 2 years ago
- Comments:14 (8 by maintainers)
Top Results From Across the Web
ReactiveSecurityContextHolder is empty in Spring WebFlux
I am trying to use the ReactiveSecurityContextHolder with Spring WebFlux. Unfortunately, the SecurityContext is empty :
Read more >EnableReactiveMethodSecurity :: Spring Security
When integrating with WebFlux Security, the Reactor Context is automatically established by Spring Security according to the authenticated user: Java. Kotlin. @ ...
Read more >Reactive Spring Security 5 Hands-On Workshop
Implement automated security integration tests ... Spring Webflux depends on Reactor and uses it internally to compose asynchronous logic ...
Read more >JWT Authentication in Spring Boot Webflux | by Jaiden Ashmore
If the Authentication object can be authenticated, it will be added to the ReactiveSecurityContextHolder for usage by the subsequent ...
Read more >Introduction to Spring WebFlux - /dev/solita
And then Java 8 introduced lambda expressions as a new language feature bringing functional style programming to Java.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Okay, after messing around inside dgs-framework, I think I have a path forward but would love input from the maintainers.
I modified DataFetcherResultProcessor:
this is a relatively trivial change, allowing access to the dfe (or potential we should allow access to DgsDataFetchingEnvironment instead) inside of Mono/FluxDataFetcherResultProcessors.
I then had to implement my own custom Mono/Flux implementation converters since spring-security is not included in these modules.
noting that my customContext is:
This could probably be improved in some way, but it does work e2e for me on my fork + custom implementations.
What are peoples thoughts and suggestions?
@gnoeley Yes! We discovered that the existing solution proposed in https://github.com/Netflix/dgs-framework/issues/375#issuecomment-864326805 has another issue though: It works for
@DgsQuerybut does not work for@DgsEntityFetcher. Would it be possible to consider this in your current PR so that it works for@DgsEntityFetcheras well?