@RolesAllowed vs. @PreAuthorize vs. @Secured

前端 未结 3 865
挽巷
挽巷 2021-02-04 01:29

I have a basic SpringBoot app. using Spring Initializer, embedded Tomcat, Thymeleaf template engine, and package as an executable JAR file.

I want to secure a controller

3条回答
  •  离开以前
    2021-02-04 01:56

    All of these are basically the same for your purpose, but @PreAuthorize is the best fit for controllers and controller methods. @Secured and @RolesAllowed are intended for describing service layer security attributes.

    Also be aware for @PreAuthorize annotation to work you must define a configuration class:

    @Configuration
    @EnableGlobalMethodSecurity(prePostEnabled = true)
    public class MethodSecurityConfig extends GlobalMethodSecurityConfiguration {
    ...
    }
    

提交回复
热议问题