Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spring Security 5.6+: Replace @EnableGlobalMethodSecurity with @EnableMethodSecurity #203

Open
timtebeek opened this issue Jun 18, 2022 · 0 comments

Comments

@timtebeek
Copy link
Contributor

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:

  1. Uses the simplified AuthorizationManager API instead of metadata sources, config attributes, decision managers, and voters. This simplifies reuse and customization.
  2. Favors direct bean-based configuration, instead of requiring extending GlobalMethodSecurityConfiguration to customize beans
  3. Is built using native Spring AOP, removing abstractions and allowing you to use Spring AOP building blocks to customize
  4. Checks for conflicting annotations to ensure an unambiguous security configuration
  5. Complies with JSR-250
  6. Enables @PreAuthorize, @PostAuthorize, @PreFilter, and @PostFilter by default

Conversion could be rather easy at first glance;

  1. @EnableMethodSecurity is itself annotated with @Configuration, so that annotation can be removed if present.
  2. prePostEnabled is now true by default, so that parameter can be removed if set to true.
  3. There is no order argument anymore; remove the argument.
@traceyyoshima traceyyoshima added the recipe Recipe requested label Jun 29, 2022
@traceyyoshima traceyyoshima moved this to Backlog in OpenRewrite Jun 29, 2022
@timtebeek timtebeek moved this from Backlog to Recipes Wanted in OpenRewrite May 1, 2023
@rpau rpau added this to the Support Spring Security migrations milestone May 24, 2023
@timtebeek timtebeek removed this from the Support Spring Security migrations milestone Nov 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Recipes Wanted
Development

No branches or pull requests

4 participants