-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Non-JWT QuarkusPrincipal injected into JsonWebToken field #34897
Comments
/cc @sberyozkin (jwt) |
I'll check what changed tomorrow unless @sberyozkin knows or says this is intentional. Workaround (probably obvious to you already) should be to have JWT and claim injected into different bean and programmatically access it only from endpoints authenticated with JWT. |
I don't recall anything changing in this regard in 3.0, but great the reproducer is available |
So
|
@michalvavrik Thanks for checking. The reason I might've called that method As far as the individual claims injection is concerned, which can be injected as String for example, indeed, I think it can't work by just returning null. @martinoneutrino what usecase do you have in mind ? If the request is made to the endpoint which expects to interact with the injected JsonWebToken, then creating a custom authenticated non JWT principal and expecting that code to work does not sound right. I wonder if this issue may be invalid. I think you should inject |
+1 |
Or you can just have it injected only to resources that actually are authenticated with JWT auth mechanism or as I mentioned |
@michalvavrik I only encountered it after I upgraded some services from 2.16.3.Final to 3.1 and later. So apparently my assumption on the cause was incorrect.
@sberyozkin My use case is a bit more complex than just an endpoint. I have a |
@martinoneutrino Thanks, adding a role in a custom filter should not be a problem, should work for any security identity. The problem is, a non-JWT principal coming into the endpoint which expects a JWT one, which is why I thought having a more generic identity representation injected should help. |
I tested and it still shows the same error running in Quarkus 1.x, so I'm not sure how this was ever working for me. I'll keep looking... |
After further testing and research, I think the correct thing is for |
@martinoneutrino Thanks - but then it would make it even more difficult to identify the problem in the way the application has been designed, i.e, when a valid non-JWT principal is passed to the endpoint - which thinks it should still access an injected JsonWebToken as part of this call - which is an application level bug. IMHO this issue has to be closed as invalid one, cheers |
If so, can we then change it from a throwing an exception to producing a warning? I don't agree with an anonymous user getting favourable treatment (with a An application design that mixes authentication schemes and injects |
I think I ran into a similar problem. We are using Basic Auth for our endpoint. When the request is coming from a specific application additionally a JWT is present in the request header. If that is the case the userId from that token should be used and added as additional info (next to the Basic Auth user) when tracing the request through the system. I added the config I worked around that by manually getting the header from the ContainerRequestContext and if present parsing it with a JWTParser instance. |
My current workaround is to catch the |
@sberyozkin Can this |
I think you are talking about the concept of the inclusive authentication, I have #31329 opened awhile back and just can't get back to it, so I'll try to complete it asap, it is an important one. Please watch #31329.
IMHO this is not a very good idea, if you have a non-JWT principal accessing a code expecting IMHO there is nothing else that we can do in this regard |
Describe the bug
I have created a custom HTTP Authorization mechanism (from
HttpAuthenticationMechanism
,UsernamePasswordAuthenticationRequest
andIdentityProvider
), which is to be used in the same service that uses both Basic and JWT authorization (ie. for an administration endpoint that uses custom/non-Basic authorization).However, since Quarkus 3.0, an injected
JsonWebToken
field in a service will be assigned theQuarkusPrincipal
provided by the custom authorization, resulting in the error:java.lang.IllegalStateException: Current principal io.quarkus.security.runtime.QuarkusPrincipal is not a JSON web token
. The error also occurs when injecting a field with aClaim
annotation.Expected behavior
The injected
JsonWebToken
value and anyClaim
fields are null, since noAuthorization: Bearer
(JWT) header was provided.Actual behavior
The following error occurs when the
JsonWebToken
field is accessed (orClaim
is decoded):How to Reproduce?
Reproducer: IllegalStateException-not-a-JSON-web-token
Adds three classes to
security-jwt-quickstart
project:AdminAuthenticationMechanism
,UsernamePasswordAuthenticationRequest
,AdminRoleIdentityProvider
.Run
security-jwt-quickstart
project and send a request to any endpoint (ie.localhost:8080/secured/permit-all
), and include header:Authorization: Admin ANYDATA
Output of
uname -a
orver
Microsoft Windows [Version 10.0.19045.3208]
Output of
java -version
openjdk version "11.0.7"
GraalVM version (if different from Java)
No response
Quarkus version or git rev
3.2.1
Build tool (ie. output of
mvnw --version
orgradlew --version
)Apache Maven 3.8.6
Additional information
No response
The text was updated successfully, but these errors were encountered: