Repository navigation
Fix spurious ProviderManager failure event - #19957
Open
Yusuf-Hussien wants to merge 1 commit into
Open
Yusuf-Hussien wants to merge 1 commit into
Yusuf-Hussien wants to merge 1 commit into
Conversation
ProviderManager synthesized a ProviderNotFoundException and published it as an AbstractAuthenticationFailureEvent whenever none of its own providers supported the token. When the manager is part of a parent/child hierarchy, this emitted a spurious event (and an extra event) that masked the actual AuthenticationException produced by the manager that handled the request. Skip publishing the failure event when the exception is the synthesized ProviderNotFoundException, so only the manager that ultimately propagates the AuthenticationException publishes it. Closes spring-projectsgh-19434 Signed-off-by: Yusuf Hussien <yhussien01@gmail.com>
This branch has not been deployed
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.
Closes gh-19434
The problem
When an
AuthenticationManagerhierarchy is in use, anAuthenticationExceptionproduced by a childAuthenticationManageris not the one published as anAbstractAuthenticationFailureEvent. Instead, the parent publishes its ownProviderNotFoundException, which hides the real exception.ProviderManageralready propagates the more specific exception, but it still published the synthesizedProviderNotFoundExceptionwhen none of its own providers supported the token. In a parent/child setup that means two events are published and the listener sees the parent'sProviderNotFoundExceptionrather than the actual failure.The change
Skip publishing the failure event when the exception is the synthesized
ProviderNotFoundException. That exception only means "no provider here supports this token", not that authentication failed; the manager that actually handled the request publishes the failure event.Testing
Added
ProviderManagerTests#providerNotFoundFromParentPublishesOnlyChildException: a parent manager whose provider does not support the token, and a child manager whose provider throws a specific exception. It asserts that only the child's exception is published. Without the fix this test fails because the parent publishes an extraProviderNotFoundException../gradlew :spring-security-core:checkpasses.