Spring Security - Method Security
Method Security
Method Security
Enable method security using @EnableGlobalMethodSecurity annotation
1 |
|
Now you can use @Secured
annotation to specify the roles needed to access the method
1 |
|
The @RoleAllowed
annotation is the JSR-250’s equivalent annotation of the @Secured
annotation. You can swap @Secured with @RolesAllowed annotaiton and it will still work.
1 |
@PreAuthorize and @PostAuthorize
@PreAuthorize and @PostAuthorize allows you to use SpEL expression access control. @PreAuthorize happens before method invocation. @PostAuthorize happens after method invocation.
1 |
|
Expression-based annotations are a good choice if you need to define simple rules that go beyond checking the role names against the user’s list of authorities.
Reference