shiro启用注解方式-创新互联
shiro验证权限方式一种是基于url配置文件:![shiro启用注解方式
shiro启用注解方式](/upload/otherpic11/2133202.jpg)
网页标题:shiro启用注解方式-创新互联
链接地址:http://myzitong.com/article/dpdjjg.html
![shiro启用注解方式
shiro启用注解方式](/upload/otherpic11/2133202.jpg)
例如:
/home=authc
/resources/**=anon
另外一种是基于注解:
例如:
RequiresAuthentication注解
RequiresAuthentication注解要求在访问或调用被注解的类/实例/方法时,Subject在当前的session中已经被验证。
@RequiresAuthentication
public void updateAccount(Account userAccount) {
//this method will only be invoked by a
//Subject that is guaranteed authenticated
...
}
RequiresGuest注解
RequiresGuest注解要求当前Subject是一个“访客”,也就是,在访问或调用被注解的类/实例/方法时,他们没有被认证或者在被前一个Session记住。
@RequiresGuest
public void signUp(User newUser) {
//this method will only be invoked by a
//Subject that is unknown/anonymous
...
}
RequiresPermissions 注解
RequiresPermissions 注解要求当前Subject在执行被注解的方法时具备一个或多个对应的权限。
@RequiresPermissions("account:create")
public void createAccount(Account account) {
//this method will only be invoked by a Subject
//that is permitted to create an account
...
}
RequiresRoles 注解
RequiresPermissions 注解要求当前Subject在执行被注解的方法时具备所有的角色,否则将抛出AuthorizationException异常。
@RequiresRoles("administrator")
public void deleteUser(User user) {
//this method will only be invoked by an administrator
...
}
如果在Controller中如果直接使用上面标签是不起作用的,需要开启shiro注解
bean id="myRealm" class="com.controller.MyRealm"/>
redirect:/login
redirect:/admin/common/exceptionLog
其中com.controller.MyRealm类是我自定义的继承自AuthorizingRealm的类
网页标题:shiro启用注解方式-创新互联
链接地址:http://myzitong.com/article/dpdjjg.html