扫二维码与项目经理沟通
我们在微信上24小时期待你的声音
解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流
例如:
/home=authc
/resources/**=anon
另外一种是基于注解:
例如:
RequiresAuthentication注解要求在访问或调用被注解的类/实例/方法时,Subject在当前的session中已经被验证。
@RequiresAuthentication
public void updateAccount(Account userAccount) {
//this method will only be invoked by a
//Subject that is guaranteed authenticated
...
}
RequiresGuest注解要求当前Subject是一个“访客”,也就是,在访问或调用被注解的类/实例/方法时,他们没有被认证或者在被前一个Session记住。
@RequiresGuest
public void signUp(User newUser) {
//this method will only be invoked by a
//Subject that is unknown/anonymous
...
}
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
...
}
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的类
我们在微信上24小时期待你的声音
解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流