Skip to content

Always fallback to AccessDeniedHandlerImpl for unmatched requests#18889

Closed
answndud wants to merge 1 commit intospring-projects:mainfrom
answndud:codex/access-denied-fallback-18871
Closed

Always fallback to AccessDeniedHandlerImpl for unmatched requests#18889
answndud wants to merge 1 commit intospring-projects:mainfrom
answndud:codex/access-denied-fallback-18871

Conversation

@answndud
Copy link
Copy Markdown

@answndud answndud commented Mar 13, 2026

Fixes gh-18871

ExceptionHandlingConfigurer#createDefaultAccessDeniedHandler currently returns the configured handler directly when only one defaultAccessDeniedHandlerFor mapping is registered. In that case, unmatched requests do not fall back to AccessDeniedHandlerImpl.

This change always uses RequestMatcherDelegatingAccessDeniedHandler when default denied handler mappings are present so that unmatched requests consistently fall back to AccessDeniedHandlerImpl.

It also updates the regression test for the single-matcher case to verify that only matching requests use the custom handler and non-matching requests return 403 Forbidden.

Testing:

  • export JAVA_HOME=/opt/homebrew/opt/openjdk/libexec/openjdk.jdk/Contents/Home; export PATH="$JAVA_HOME/bin:$PATH"; export NPM_CONFIG_WORKSPACES=false; ./gradlew :spring-security-config:test --tests org.springframework.security.config.annotation.web.configurers.ExceptionHandlingConfigurerAccessDeniedHandlerTests

Signed-off-by: MJY <jmoon0227@gmail.com>
@answndud
Copy link
Copy Markdown
Author

Closing this for now. I opened it too early before the team had decided whether this behavior should change, and I do not want to create extra noise while that decision is still open. If maintainers decide this direction is desirable later, I can revisit it.

@answndud answndud closed this Mar 19, 2026
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.

ExceptionHandlingConfigurer#createDefaultAccessDeniedHandler should always fallback to AccessDeniedHandlerImpl

2 participants