Skip to content

Always fallback to AccessDeniedHandlerImpl for unmatched requests#18889

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

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

@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>
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