Apache Shiro 注解方式授权
2012-11-09 09:35
387 查看
除了通过API方式外,Shiro 提供Java 5+注解的集合,以注解为基础的授权控制。在你可以使用Java 注释之前,你需要在你的应用程序中启用AOP 支持。
Shiro注解支持AspectJ、Spring、Google-Guice等,可根据应用进行不同的配置。
相关的注解如下:
The RequiresAuthentication annotation(RequiresAuthentication 注解)
要求当前Subject 已经在当前的session 中被验证通过才能被访问或调用。例如:
The RequiresGuest annotation(RequiresGuest 注解)
要求当前的Subject 是一个"guest",也就是说,他们必须是在之前的session 中没有被验证或被记住才能被访问或调用。例如:
The RequiresPermissions annotation(RequiresPermissions 注解)
要求当前的Subject 被允许一个或多个权限,以便执行注解的方法。例如:
The RequiresRoles annotation(RequiresRoles 注解)
要求当前的Subject 拥有所有指定的角色。如果他们没有,则该方法将不会被执行,而且AuthorizationException 异常将会被抛出。例如:
The RequiresUser annotation(RequiresUser 注解)
RequiresUser 注解需要当前的Subject 是一个应用程序用户才能被注解的类/实例/方法访问或调用。一个“应用程序用户”被定义为一个拥有已知身份,或在当前session 中由于通过验证被确认,或者在之前session 中的'RememberMe'服务被记住。例如:
Shiro注解支持AspectJ、Spring、Google-Guice等,可根据应用进行不同的配置。
相关的注解如下:
The RequiresAuthentication annotation(RequiresAuthentication 注解)
要求当前Subject 已经在当前的session 中被验证通过才能被访问或调用。例如:
@RequiresAuthentication public void updateAccount(Account userAccount) { //this method will only be invoked by a //Subject that is guaranteed authenticated … } |
要求当前的Subject 是一个"guest",也就是说,他们必须是在之前的session 中没有被验证或被记住才能被访问或调用。例如:
@RequiresGuest public void signUp(User newUser) { //this method will only be invoked by a //Subject that is unknown/anonymous … } |
要求当前的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 … } |
要求当前的Subject 拥有所有指定的角色。如果他们没有,则该方法将不会被执行,而且AuthorizationException 异常将会被抛出。例如:
@RequiresRoles("administrator") public void deleteUser(User user) { //this method will only be invoked by an administrator … } |
RequiresUser 注解需要当前的Subject 是一个应用程序用户才能被注解的类/实例/方法访问或调用。一个“应用程序用户”被定义为一个拥有已知身份,或在当前session 中由于通过验证被确认,或者在之前session 中的'RememberMe'服务被记住。例如:
@RequiresUser public void updateAccount(Account account) { //this method will only be invoked by a 'user' //i.e. a Subject with a known identity … } |
相关文章推荐
- Apache Shiro 注解方式授权
- Apache Shiro 标签方式授权
- 我的shiro之旅-注解方式授权
- Apache Shiro 标签方式授权
- Shiro第五篇【授权过滤、注解、JSP标签方式、与ehcache整合】
- Apache Shiro 标签方式授权
- Apache Shiro 编程方式授权
- Apache Shiro 标签方式授权
- Apache Shiro 标签方式授权
- Shiro第五篇【授权过滤、注解、JSP标签方式、与ehcache整合】
- Shiro之授权管理与授权的三种方式(1、编程方式,2、注解方式,3、jsp标签)-yellowcong
- Shiro 采用注解方式无法进入自定义Realm类的授权方法 解决方案
- Apache Shiro 使用手册(三)Shiro 授权
- Apache shiro集群实现 (四)shiro授权(Authentication)--访问控制
- apache shiro与spring整合、动态filterChainDefinitions、以及认证、授权
- apache shiro与spring整合、动态filterChainDefinitions、以及认证、授权
- shiro 注解授权不起作用问题解决方案
- Apache Shiro 关于Shiro 授权
- Apache Shiro 使用手册(三)Shiro 授权
- 在SpringMVC中开启Shiro注解授权的正确方法