Skip to content

Add RequestCache setter in OAuth2AuthorizationCodeGrantFilter #8120

Closed
@mdindoffer

Description

@mdindoffer

Summary

Please provide a way to inject specific RequestCache to the OAuth2AuthorizationCodeGrantFilter.
The "sister" filter OAuth2AuthorizationRequestRedirectFilter already has a #setRequestCache method for injecting specific RequestCache, but the OAuth2AuthorizationCodeGrantFilter uses a hardcoded HttpSessionRequestCache.

Reasoning

Current setup does not allow for easy customization of redirect scenarios after successful OAuth2 Code grant authorization flow.

Two workarounds exist to my knowledge:

  1. Use the HttpSessionRequestCache with a specially crafted HttpServletRequestWrapper, such that the DefaultSavedRequest created from it in the HttpSessionRequestCache will return a desired redirect uri.
  2. Avoid saving the request via RequestCache's interface, and store it directly in the session via
request.getSession().setAttribute(customSavedRequest, "SPRING_SECURITY_SAVED_REQUEST")

The first one is prone to breakage and complicated to do so, because the DefaultSavedRequest#getRedirectUrl() builds a URL from multiple fields, that have to be specifically overriden in the request wrapper.
The second workaround is slightly less complicated, but even more prone to breakage, as the session attribute name is not a public constant and can change anytime.

The addition of injectable RequestCache would make the OAuth2AuthorizationCodeGrantFilter on par with OAuth2AuthorizationRequestRedirectFilter.

Version

5.2.2

Metadata

Metadata

Labels

in: oauth2An issue in OAuth2 modules (oauth2-core, oauth2-client, oauth2-resource-server, oauth2-jose)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions