JSR-250注解

1、在pom.xml添加
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>jsr250-api</artifactId>
<version>1.0</version>
</dependency>

2、在spring-mvc.xml 开启注解
<security:global-method-security jsr250-annotations="enabled"></security:global-method-security>

3、在权限控制的方法上面使用注解
@RolesAllowed("ADMIN")

这种也可以写@RolesAllowed("ROLE_ADMIN"),上面是省略ROLE_前缀
@Secured注解

1、在spring-mvc.xml 开启注解
<security:global-method-security secured-annotations="enabled"></security:global-method-security>

2、在权限控制的方法上面使用注解
@Secured("ROLE_ADMIN")
这里不能省略ROLE_前缀
 基于表达式操作

1、在spring-mvc.xml 开启注解
<security:global-method-security pre-post-annotations="enabled"></security:global-method-security>

2、在权限控制的方法上面使用注解
@PreAuthorize("authentication.principal.username == 'peny'")
@PreAuthorize("hasRole('ROLE_ADMIN')")
这里可以省略ROLE_前缀;  @PreAuthorize("hasRole('ADMIN')")

相关文章:

  • 2022-01-08
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-07
  • 2021-11-30
  • 2022-12-23
  • 2021-12-09
猜你喜欢
  • 2021-06-11
  • 2021-09-06
  • 2022-12-23
  • 2022-12-23
  • 2021-06-19
  • 2022-12-23
相关资源
相似解决方案