rewrite-spring
rewrite-spring copied to clipboard
Spring Security 5.6+: Replace @EnableGlobalMethodSecurity with @EnableMethodSecurity
https://docs.spring.io/spring-security/reference/5.7.0/servlet/authorization/method-security.html#_enablemethodsecurity
In Spring Security 5.6, we can enable annotation-based security using the @EnableMethodSecurity annotation on any @Configuration instance.
This improves upon @EnableGlobalMethodSecurity in a number of ways. @EnableMethodSecurity:
- Uses the simplified AuthorizationManager API instead of metadata sources, config attributes, decision managers, and voters. This simplifies reuse and customization.
- Favors direct bean-based configuration, instead of requiring extending GlobalMethodSecurityConfiguration to customize beans
- Is built using native Spring AOP, removing abstractions and allowing you to use Spring AOP building blocks to customize
- Checks for conflicting annotations to ensure an unambiguous security configuration
- Complies with JSR-250
- Enables @PreAuthorize, @PostAuthorize, @PreFilter, and @PostFilter by default
Conversion could be rather easy at first glance;
-
@EnableMethodSecurityis itself annotated with@Configuration, so that annotation can be removed if present. -
prePostEnabledis nowtrueby default, so that parameter can be removed if set totrue. - There is no
orderargument anymore; remove the argument.