spring-projects / spring-projects/spring-security
AccessDecisionManager of GlobalMethodSecurityConfiguration is not MessageSourceAware
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 9.6k
- Forks
- 6.3k
- Avg merge
- 2d 11h
- Merged PRs (30d)
- 52
Description
AffirmativeBased access decision manager which is used in GlobalMethodSecurityConfiguration is created by accessDecisionManager() method and it is not a Spring bean. As a result, setMessageSource() method gets never executed which makes this access decision manager not MessageSourceAware although AffirmativeBased implements MessageSourceAware interface. This avoids customizing spring security access denied messages generated by @PreAuthorize annotation.
The solution for that is to set the messageSource manually like below;
@Configuration
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class MethodSecurityConfig extends GlobalMethodSecurityConfiguration {
@Autowired
private MessageSource messageSource;
@Override
protected AccessDecisionManager accessDecisionManager() {
AffirmativeBased manager = (AffirmativeBased) super.accessDecisionManager();
manager.setMessageSource(messageSource);
return manager;
}
}
Just for reference, this issue doesn't apply to the access decision manager of AbstractInterceptUrlConfigurer where messageSource is set during postProcess.
This problem is also mentioned in this stackoverflow post.
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 in config/src/main/java/org/springframework/security/config/annotation/method/configuration/GlobalMethodSecurityConfiguration.java at accessDecisionManager(), then compare the message-source handling described for AbstractInterceptUrlConfigurer. Done means the AffirmativeBased manager used by global method security receives the MessageSource so customized access-denied messages from @PreAuthorize are effective.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring
- Domain
- security
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 38/100