使用springSecurity做控制访问
程序员文章站
2024-03-19 13:40:04
...
方法一:
//使用spring完成权限的展示
//1.springmvc.xml文件添加配置
<security:global-method-security pre-post-annotations="enabled"></security:global-method-security>
//2.controller添加注解
@PreAuthorize("hasAnyRole('ROLE_PRODUCT','ROLE_ADMIN')")
方法二:使用springSecurity完成权限的展示
//1.springmvc.xml文件添加配置
<security:global-method-security secured-annotations="enabled"></security:global-method-security>
//2.controller添加注解
@Secured("")
方法三:使用JSR-250
//先导入坐标
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>jsr250‐api</artifactId>
<version>1.0</version>
</dependency>
//1.springmvc.xml文件添加配置
<security:global-method-security jsr250-annotations="enabled"></security:global-method-security>
//2.controller添加注解
@RolesAllowed("ROLE_ADMIN")
下一篇: API认证