Skip to content

Allow for customization of IssuerResolver #9005

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

Closed
wants to merge 4 commits into from
Closed

Allow for customization of IssuerResolver #9005

wants to merge 4 commits into from

Conversation

AbstractConcept
Copy link

Customization of IssuerConverter and JwtAuthenticationConverter will make it easier to customize the way JWTs are handled, especially in a multi-tenant env, with the use of the default JwtAuthenticationProvider. This eliminates the need to write a complex implementation for different tasks, that ideally should be quick and easy, such as custom GranthedAuthorities conversion.

Closes gh-8535

…rter

Customization of IssuerConverter and JwtAuthenticationConverter will make it easier to customize the way JWTs are handled, especially in a multi-tenant env, with the use of the default JwtAuthenticationProvider. This eliminates the need to write a complex implementation for different tasks, that ideally should be quick and easy, such as custom GranthedAuthorities conversion.

Closes gh-8535
@pivotal-issuemaster
Copy link

@AbstractConcept Please sign the Contributor License Agreement!

Click here to manually synchronize the status of this Pull Request.

See the FAQ for frequently asked questions.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Sep 9, 2020
@pivotal-issuemaster
Copy link

@AbstractConcept Thank you for signing the Contributor License Agreement!

…rter

Customization of IssuerConverter and JwtAuthenticationConverter will make it easier to customize the way JWTs are handled, especially in a multi-tenant env, with the use of the default JwtAuthenticationProvider. This eliminates the need to write a complex implementation for different tasks, that ideally should be quick and easy, such as custom GranthedAuthorities conversion.

Closes gh-8535
@AbstractConcept
Copy link
Author

@jzheaux Could you take a look?

Copy link
Contributor

@jzheaux jzheaux left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR, @AbstractConcept! I've left some feedback inline.

@jzheaux jzheaux self-assigned this Sep 22, 2020
@jzheaux jzheaux added in: oauth2 An issue in OAuth2 modules (oauth2-core, oauth2-client, oauth2-resource-server, oauth2-jose) type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged labels Sep 22, 2020
@arvidOtt
Copy link
Contributor

arvidOtt commented Oct 5, 2020

@AbstractConcept I would also be really interested in having this enhancement 👍

Do you find time to complete the work on your PR or would you mind if I finish this according to @jzheaux feedback?

@AbstractConcept
Copy link
Author

AbstractConcept commented Oct 5, 2020

@arvidOtt I'll get to this, hopefully will be done by tomorrow.

…arate ticket needed + setter instead of constructor
@AbstractConcept
Copy link
Author

AbstractConcept commented Oct 6, 2020

@jzheaux Requested changes should be there, could you check again? Additionally, created #9096 for the changes you asked to be moved to a separate ticket, will create a PR for it when this one is merged.

Copy link
Contributor

@jzheaux jzheaux left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @AbstractConcept, for the updates! I've left some additional feedback inline.

*/
public JwtIssuerAuthenticationManagerResolver(
AuthenticationManagerResolver<String> issuerAuthenticationManagerResolver,
Converter<HttpServletRequest, String> issuerConverter) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we are using a setter for the issuer converter, this constructor is unnecessary.

@@ -130,6 +165,10 @@ public AuthenticationManager resolve(HttpServletRequest request) {
return authenticationManager;
}

public void setIssuerConverter(Converter<HttpServletRequest, String> issuerConverter) {
this.issuerConverter = issuerConverter;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check for null here using Assert.notNull, as you did earlier in the constructor.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, I believe it would be a bit more consistent with the rest of Spring Security to call this setIssuerResolver. It's certainly reminiscent of BearerTokenResolver in its role in the request.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, out of curiosity, do you have a use case where you need the more generic contract of Converter<HttpServletRequest, String>? If not, setBearerTokenResolver may be better since that's likely the most common use case.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jzheaux the problem is that you cannot set the BearerTokenResolver on the issuerConverter as it is of type Converter<HttpServletRequest,String>. So either you replace the entire thing or you would need to add a setter on that one as well and change the type of the issuerConverter attribute directly to JwtClaimIssuerConverter. What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with you that adding a setter to JwtClaimIssuerConverter would be one way to do it, though it would remain private.

One nice thing about using BearerTokenResolver is that it simplifies the API and focuses on the most common use cases. It seems like a very uncommon use case to pull the issuer from somewhere else in the request other than the token itself.

@@ -130,6 +165,10 @@ public AuthenticationManager resolve(HttpServletRequest request) {
return authenticationManager;
}

public void setIssuerConverter(Converter<HttpServletRequest, String> issuerConverter) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add JavaDoc, including a @since 5.5 so it's clear when the method became available.

@@ -160,8 +199,16 @@ public String convert(@NonNull HttpServletRequest request) {

private final Predicate<String> trustedIssuer;

private final JwtAuthenticationConverter jwtAuthenticationConverter;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's leave these changes regarding JwtAuthenticationConverter for later.

@jzheaux jzheaux changed the title Allow for customization of IssuerConverter and JwtAuthenticationConverter Allow for customization of IssuerResolver Oct 6, 2020
@jzheaux
Copy link
Contributor

jzheaux commented Nov 3, 2020

Thanks for your work on this @AbstractConcept. Another contributor had time to pick up where you left off, so I'm going to close this in favor of #9168

@jzheaux jzheaux closed this Nov 3, 2020
@jzheaux jzheaux added status: duplicate A duplicate of another issue and removed type: enhancement A general enhancement labels Nov 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: oauth2 An issue in OAuth2 modules (oauth2-core, oauth2-client, oauth2-resource-server, oauth2-jose) status: duplicate A duplicate of another issue
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support customization of BearerTokenResolver in JwtIssuerAuthenticationManagerResolver
5 participants