Skip to content
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

Added setter to make RequestCache injectable #8392

Closed

Conversation

parikshitdutta
Copy link
Contributor

@parikshitdutta parikshitdutta commented Apr 14, 2020

  • updated requestCache member variable to non-final

  • added setter to make RequestCache injectable

  • added respective test to validate requestCache can not be set to null

  • added test that asserts the supplied RequestCache is actually used

  • updated OAuth2ClientConfigurer to set the configured requestCache

  • added test that verifies provided RequestCache in OAuth2ClientConfigurer is used

closes gh-8120

@parikshitdutta
Copy link
Contributor Author

Hi @jgrandja, FYI: the same integration test (gradlew spring-security-config:integrationTest) ran just fine at my end. Let me know, if you envision any change that I can help with.

Attached snap:
image

Thank you.

@jgrandja
Copy link
Contributor

@parikshitdutta Apologies for the delay with this review. I'm currently working on some priority items but will get to this tomorrow or early next week. Thanks for your patience.

@jgrandja jgrandja 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 Apr 16, 2020
@jgrandja jgrandja added this to the 5.4.x milestone Apr 17, 2020
Copy link
Contributor

@jgrandja jgrandja 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 @parikshitdutta. Please see my comments.

In addition, we need to ensure that a configured RequestCache is actually supplied to OAuth2AuthorizationCodeGrantFilter.setRequestCache(). Take a look at OAuth2LoginConfigurer to see how it configures OAuth2AuthorizationRequestRedirectFilter.setRequestCache() and apply the same.

@@ -134,6 +134,17 @@ public final void setAuthorizationRequestRepository(AuthorizationRequestReposito
this.authorizationRequestRepository = authorizationRequestRepository;
}

/**
* Sets the {@link RequestCache} used for storing the current request
* before redirecting the OAuth 2.0 Authorization Request.
Copy link
Contributor

Choose a reason for hiding this comment

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

The javadoc needs to be updated here as it does not save the current request. Instead it loads a saved request and replays it.

@@ -130,6 +130,12 @@ public void setAuthorizationRequestRepositoryWhenAuthorizationRequestRepositoryI
.isInstanceOf(IllegalArgumentException.class);
}

@Test
Copy link
Contributor

Choose a reason for hiding this comment

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

We should also have a test that asserts the supplied RequestCache is actually used.

@parikshitdutta
Copy link
Contributor Author

Hi @jgrandja, please check as you find time, I will look forward to your feedback, if any.

@jgrandja
Copy link
Contributor

jgrandja commented May 4, 2020

@parikshitdutta Looks like this was missed:

In addition, we need to ensure that a configured RequestCache is actually supplied to OAuth2AuthorizationCodeGrantFilter.setRequestCache(). Take a look at OAuth2LoginConfigurer to see how it configures OAuth2AuthorizationRequestRedirectFilter.setRequestCache() and apply the same.

@parikshitdutta
Copy link
Contributor Author

Hi @jgrandja, I regret that I missed to correct that part.
As I look into your referred OAuth2LoginConfigurer, I find configure to set requestCache for OAuth2AuthorizationRequestRedirectFilter, followed by postProcess with that filter.

Can you please suggest where you exactly want me to configure OAuth2AuthorizationCodeGrantFilter that way? I didn't get this part.

@jgrandja
Copy link
Contributor

jgrandja commented May 5, 2020

@parikshitdutta

Can you please suggest where you exactly want me to configure OAuth2AuthorizationCodeGrantFilter that way?

It should be configured in OAuth2ClientConfigurer

@parikshitdutta
Copy link
Contributor Author

Hi @jgrandja, please review as you find time, I will look forward to your feedback.

@parikshitdutta
Copy link
Contributor Author

Hi @jgrandja , if you envision any change for this PR that I can help with, please let me know while I look at some other open issues.

Thank you.

Copy link
Contributor

@jgrandja jgrandja 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 updates @parikshitdutta. Please see review comments.

@@ -218,6 +218,10 @@ private void configure(B builder) {
OAuth2AuthorizationRequestRedirectFilter authorizationRequestRedirectFilter = createAuthorizationRequestRedirectFilter(builder);
builder.addFilter(postProcess(authorizationRequestRedirectFilter));
OAuth2AuthorizationCodeGrantFilter authorizationCodeGrantFilter = createAuthorizationCodeGrantFilter(builder);
RequestCache requestCache = builder.getSharedObject(RequestCache.class);
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you move this logic to createAuthorizationCodeGrantFilter()

@@ -218,6 +218,10 @@ private void configure(B builder) {
OAuth2AuthorizationRequestRedirectFilter authorizationRequestRedirectFilter = createAuthorizationRequestRedirectFilter(builder);
builder.addFilter(postProcess(authorizationRequestRedirectFilter));
OAuth2AuthorizationCodeGrantFilter authorizationCodeGrantFilter = createAuthorizationCodeGrantFilter(builder);
RequestCache requestCache = builder.getSharedObject(RequestCache.class);
if (requestCache != null) {
authorizationCodeGrantFilter.setRequestCache(requestCache);
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 a test in OAuth2ClientConfigurerTests to verify(requestCache).getRequest()

@parikshitdutta
Copy link
Contributor Author

parikshitdutta commented May 15, 2020

Thanks @jgrandja for your time reviewing changes, please validate my latest changes done based on your comments.

@jgrandja jgrandja modified the milestones: 5.4.x, 5.4.0-M2 May 15, 2020
@jgrandja jgrandja added the status: duplicate A duplicate of another issue label May 15, 2020
@jgrandja
Copy link
Contributor

Thanks for the PR @parikshitdutta ! This is now in master.

@jgrandja jgrandja closed this May 15, 2020
@jgrandja
Copy link
Contributor

jgrandja commented May 15, 2020

@parikshitdutta I just logged #8536, which is the equivalent of the changes you applied in this PR but for the WebFlux stack. Let me know if you're interested and free to take #8536.

@parikshitdutta
Copy link
Contributor Author

@jgrandja I would love to, thanks for asking. Already asked for permission there, just seeing the message here now.

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 type: enhancement A general enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add RequestCache setter in OAuth2AuthorizationCodeGrantFilter
3 participants