Add success and failure handlers to code grant filter - #19714
Open
prasanna164-code wants to merge 1 commit into
Open
prasanna164-code wants to merge 1 commit into
prasanna164-code wants to merge 1 commit into
Conversation
OAuth2AuthorizationCodeGrantFilter now delegates the outcome of processing the Authorization Response to an AuthenticationSuccessHandler and an AuthenticationFailureHandler, following the structure of OAuth2AuthorizationCodeGrantWebFilter. The defaults preserve the existing behavior: redirect to the saved request or the redirect_uri on success, and to the redirect_uri with the error parameters on failure. Both handlers can be configured through the Java DSL, the Kotlin DSL and the XML namespace. Closes spring-projectsgh-11069 Signed-off-by: Prasanna Sankaran <prasanna164@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds
AuthenticationSuccessHandlerandAuthenticationFailureHandlersupport toOAuth2AuthorizationCodeGrantFilter, following the structure ofOAuth2AuthorizationCodeGrantWebFilter, so that the outcome of the Authorization Code grant can be customized, for example to forward into the application instead of redirecting.Filter
setAuthenticationSuccessHandler: invoked with theOAuth2AuthorizationCodeAuthenticationTokenafter theOAuth2AuthorizedClienthas been saved. The default preserves the existing behaviour: redirect to the saved request if present, otherwise to theredirect_uriof theOAuth2AuthorizationRequest.setRequestCachekeeps its contract and feeds the default handler.setAuthenticationFailureHandler: invoked with anOAuth2AuthenticationExceptionwrapping theOAuth2AuthorizationExceptionfrom theAuthenticationManager. The default preserves the existing redirect to theredirect_uriwitherror,error_descriptionanderror_uriappended.RedirectStrategyandRequestCacheremain private to the default handlers; no public API is removed or deprecated.DSL and docs
OAuth2ClientConfigurer.AuthorizationCodeGrantConfigurerand the KotlinAuthorizationCodeGrantDslexposeauthenticationSuccessHandlerandauthenticationFailureHandler; the XML namespace gainsauthentication-success-handler-refandauthentication-failure-handler-refonauthorization-code-grant, so all three configuration styles offer the same options for this element.Tests
OAuth2AuthorizationCodeGrantFilterTests: null checks for both setters, custom success handler receives the token and suppresses the redirect while the authorized client is still saved,ForwardAuthenticationSuccessHandlerforwards, custom failure handler receives the wrapped exception with the originalOAuth2Error.OAuth2ClientConfigurerTests,AuthorizationCodeGrantDslTestsandOAuth2ClientBeanDefinitionParserTests: both handlers wired through the Java DSL, the Kotlin DSL and XML.Closes gh-11069