spring-projects / spring-projects/spring-security
`ExceptionHandlingConfigurer#createDefaultAccessDeniedHandler` should always fallback to `AccessDeniedHandlerImpl`
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 9.6k
- Forks
- 6.3k
- Avg merge
- 2d 11h
- Merged PRs (30d)
- 52
Description
org.springframework.security.config.annotation.web.configurers.ExceptionHandlingConfigurer#createDefaultAccessDeniedHandler has this implementation:
LinkedHashMap<RequestMatcher, AccessDeniedHandler> defaultDeniedHandlerMappings
private AccessDeniedHandler createDefaultAccessDeniedHandler(H http) {
if (this.defaultDeniedHandlerMappings.isEmpty()) {
return new AccessDeniedHandlerImpl();
}
if (this.defaultDeniedHandlerMappings.size() == 1) {
return this.defaultDeniedHandlerMappings.values().iterator().next();
}
return new RequestMatcherDelegatingAccessDeniedHandler(this.defaultDeniedHandlerMappings,
new AccessDeniedHandlerImpl());
}
I'd propose that special case for this.defaultDeniedHandlerMappings.size() == 1 is not intuitive, because defaultDeniedHandlerMappings is always added for a specific RequestMatcher.
- If I don't add a handler for a request matcher, then
AccessDeniedHandlerImplis always used. - If I add two handlers for request matchers, then
AccessDeniedHandlerImplis used when those matchers don't match - If I add exactly one handler for a request matcher, then that handler is also used when its request matcher does not match
I assume the reason is backwards compatibility rather than design choice?
Sorry if it has been reported before.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with org.springframework.security.config.annotation.web.configurers.ExceptionHandlingConfigurer#createDefaultAccessDeniedHandler and inspect how defaultDeniedHandlerMappings is used with request matchers. Verify the single-mapping behavior against the stated fallback expectations; done means an unmatched request uses AccessDeniedHandlerImpl consistently, with the relevant behavior covered by tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- authorization, security
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100