-
Notifications
You must be signed in to change notification settings - Fork 6k
Enable customization of BearerTokenResolver by adding a setter for JwtClaimIssuerConverter on JwtIssuerAuthenticationManagerResolver #9168
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
Conversation
… BearerTokenResolver in the JwtIssuerAuthenticationManagerResolver class (spring-projectsgh-8535)
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.
Thanks, @arvidOtt! I've left some feedback inline.
Also, would you please add unit tests to demonstrate that the feature works?
* | ||
* @since 5.5 | ||
*/ | ||
public void setIssuerConverter(Converter<HttpServletRequest, String> issuerConverter) { |
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.
Instead of setIssuerConverter
, could you do:
public void setBearerTokenResolver(BearerTokenResolver bearerTokenResolver) {
this.issuerConverter = new JwtClaimIssuerConverter(bearerTokenResolver);
}
That way, the API uses a familiar interface that they most likely already configured in their app.
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.
Okay :) Then I would also need to add another constructor to the JwtClaimIssuerConverter
to pass the resolver / converter correct?
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.
@jzheaux I hope this is the way your feedback was meant.
…JwtIssuerReactiveAuthenticationManagerResolver
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.
Thanks for the updates, @arvidOtt! I've left some additional feedback inline.
@@ -130,9 +130,28 @@ public AuthenticationManager resolve(HttpServletRequest request) { | |||
return authenticationManager; | |||
} | |||
|
|||
/** | |||
* Set a custom issuer converter |
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.
Will you please update the JavaDoc so that it talks about BearerTokenResolver
instead?
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.
Done.
...k/security/oauth2/server/resource/authentication/JwtIssuerAuthenticationManagerResolver.java
Show resolved
Hide resolved
private BearerTokenResolver resolver; | ||
|
||
JwtClaimIssuerConverter() { | ||
this.resolver = new DefaultBearerTokenResolver(); |
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.
It might be more efficient to do:
this(new DefaulBearerTokenResolver());
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.
Done 👍
…icationManagerResolver; reuse contructors of JwtAuthenticationManagerResolvers
@jzheaux I adapted the PR according to your feedback. Will write some test cases for the setter method next 🧪 |
…olver, JwtIssuerReactiveAuthenticationManagerResolver
Added unit tests for the new feature. |
@jzheaux thank you for your support! |
Description
When using the
JwtIssuerAuthenticationManagerResolver
there should be a way to replace theDefaultBearerTokenResolver
(or here the entireJwtClaimIssuerConverter
) by a custom implementation which is requested in #8535.I decided to set the entire
JwtClaimIssuerConverter
because it is declared as typeConverter<HttpServletRequest,String>
and implementing a setter or new constructor on it would required to change the type of the attribute directly toJwtClaimIssuerConverter
class.Context
I use the JwtIssuerAuthenticationManagerResolver in a web socket backend which receives the JWT not in the Authorization Header but in a custom X-Authorization Cookie Header. Therefore, I need to use my own BearerTokenResolver implementation which gets the JWT from there. This seems not to be possible at the moment.