Skip to content

Fix spurious ProviderManager failure event - #19957

Open
Yusuf-Hussien wants to merge 1 commit into
spring-projects:mainfrom
Yusuf-Hussien:fix/19434-provider-not-found-event
Open

Yusuf-Hussien wants to merge 1 commit into
spring-projects:mainfrom
Yusuf-Hussien:fix/19434-provider-not-found-event

Conversation

@Yusuf-Hussien

Copy link
Copy Markdown

Closes gh-19434

The problem

When an AuthenticationManager hierarchy is in use, an AuthenticationException produced by a child AuthenticationManager is not the one published as an AbstractAuthenticationFailureEvent. Instead, the parent publishes its own ProviderNotFoundException, which hides the real exception.

ProviderManager already propagates the more specific exception, but it still published the synthesized ProviderNotFoundException when 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's ProviderNotFoundException rather 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 extra ProviderNotFoundException.

./gradlew :spring-security-core:check passes.

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>
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Oct 20, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: waiting-for-triage An issue we've not yet triaged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

child AuthenticationManager AuthenticationException not published as AbstractAuthenticationFailureEvent

2 participants