spring security 服务器端方法级权限控制

配置文件

<security:global-method-security pre-post-annotations=“disabled”/>
注解开启
@EnableGlobalMethodSecurity :Spring Security默认是禁用注解的,要想开启注解,需要在继承
WebSecurityConfigurerAdapter的类上加@EnableGlobalMethodSecurity注解,并在该类中将
AuthenticationManager定义为Bean。

1…JSR-250注解
开启jsr-250注解支持

<security:global-method-security jsr250-annotations="enabled"/>

@RolesAllowed 指定方法的角色名称
示例:
@RolesAllowed({“USER”, “ADMIN”}) 该方法只要具有"USER", "ADMIN"任意一种权限就可以访问。
略前缀ROLE_,实际的权限可能是ROLE_ADMIN
@PermitAll 表示允许所有的角色进行访问,也就是说不进行权限控制
@DenyAll 表示无论什么角色都不能访

2.@Secured注解
权限可能是ROLE_ADMIN,不能省略
开启secure的注解的支持

<security:global-method-security secured-annotations="enabled"/>

@Secured注解标注的方法进行权限控制的支持,其值默认为disabled。
示例:

@Secured("IS_AUTHENTICATED_ANONYMOUSLY")
public Account readAccount(Long id);
@Secured("ROLE_TELLER")

3.页面端标签控制权限
在jsp页面中我们可以使用spring security提供的权限标签来进行权限控制
maven导入
(spring本身带有的权限控制方法导入的依赖其实是spring security的依赖)

<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-taglibs</artifactId>
<version>version</version>
</dependency>

页面导入

<%@taglib uri="http://www.springframework.org/security/tags" prefix="security"%>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值