-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Make JsonWebToken available in arbitrarily activated CDI request context in HTTP proxy interceptors #46715
base: main
Are you sure you want to change the base?
Conversation
This comment has been minimized.
This comment has been minimized.
🎊 PR Preview 7843777 has been successfully built and deployed to https://quarkus-pr-main-46715-preview.surge.sh/version/main/guides/
|
This comment has been minimized.
This comment has been minimized.
Thanks Michal, I'll have a look a bit later, quick question, how does it work for reactive routes? |
It works for everything based on Vert.x HTTP (including Reactive Routes), but IIRC in the Reactive Routes we activate CDI request context for endpoints created with annotations and if Quarkus activates the context itself, so we can add the identity to the context when we activate the context. This change shouldn't have negative impact in terms of functionality. I would actually do this by default if I could, it would make things more reliable, but I think we want to avoid adding stuff to local data when we don't have to because the concurrent hash map uses synchronized block when inserting stuff. But it is not like this PR does something unusual either (CDI request state is stored in local data, OpenTelemetry has context storage that relies on it etc.). |
extensions/vertx-http/runtime/src/main/java/io/quarkus/vertx/http/runtime/AuthConfig.java
Outdated
Show resolved
Hide resolved
Thanks @michalvavrik, LGTM, definitely worth supporting the injection into arbitrary handlers registered directly with the router, all the suggestions are really about trying to make it very specific to a concrete combination (handlers registered directly on the router), I'd rather us expanding it with some more details later |
5fb31a8
to
b1443da
Compare
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, very useful to have the identity injection working for handlers directly attached to the router.
Michal, if possible, please move the text to Security Tips and Tricks, may be we can consolidate there (later) all the tips related to the request scope management.
I'd also appreciate if @cescoffier could double check
b1443da
to
94d4ac6
Compare
Status for workflow
|
Status for workflow
|
This PR is motivated by user that uses
io.vertx.httpproxy.HttpProxy#reverseProxy(io.vertx.core.http.HttpClient)
and theirio.vertx.httpproxy.ProxyInterceptor
needs to injectorg.eclipse.microprofile.jwt.JsonWebToken
from CDI request context (reproducer is not publicly available, ask @sberyozkin for details if you require them). There is noRoutingContext
available, onlyio.vertx.httpproxy.ProxyContext
that doesn't expose underlying request'sRoutingContext
.Why doesn't it work OOTB? Basically what is happening is that injecting
org.eclipse.microprofile.jwt.JsonWebToken
inside aHandler<RoutingContext>
requiresSecurityIdentity
taken from the CDI request context. But when user activates CDI request context with theActivateRequestContext
annotation (or programmatically), where would the request scoped bean take the identity if it cannot accessRoutingContext
with the HTTP user?Only way how to propagate
RoutingContext
is IMO local data of the Vert.x duplicated context. I know we don't want to do that by default because it relies on theConcurrentHashMap
which would be bad when used on the hoth path, but I think it can be justified in this situation when explicitly enabled.Key part of the original reproducer looked like:
and
myInterceptor
is@ApplicationScoped
bean that injectsJsonWebToken
.