shiro篇---开启常见的注解

计算机组成
• 阅读 1683

  shiro常见的注解:    (注:建议将shiro注解放入controller,因为如果service层使用了spring的事物注解,那么shiro注解将无效,如果spring管控了 filter还是 Interceptor,怎controller层无效 ,此时可以放在service层试试)

    @RequiresAuthentication:

使用该注解标注的类,实例,方法在访问或调用时,当前Subject必须在当前session中已经过认证。

@RequiresGuest:

使用该注解标注的类,实例,方法在访问或调用时,当前Subject可以是“gust”身份,不需要经过认证或者在原先的session中存在记录。

@RequiresPermissions:

当前Subject需要拥有某些特定的权限时,才能执行被该注解标注的方法。如果当前Subject不具有这样的权限,则方法不会被执行。

@RequiresRoles:

当前Subject必须拥有所有指定的角色时,才能访问被该注解标注的方法。如果当天Subject不同时拥有所有指定角色,则方法不会执行还会抛出AuthorizationException异常。

 @RequiresUser:

        当前Subject必须是应用的用户,才能访问或调用被该注解标注的类,实例,方法。

在application.xml或者shiro.xml里面进行配置,纯注解的方式请忽略下面的代码一 和 代码二

代码一、

      <!-- 开启shiro的注解支持 --> 
<bean id="defaultAdvisorAutoProxyCreator" class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator"> 
    <!-- 必须改为true,即使用cglib方式为Action创建代理对象。默认值为false,使用JDK创建代理对象,会造成问题 --> 
    <property name="proxyTargetClass" value="true"></property> 
</bean> 
<!-- 使用shiro框架提供的切面类,用于创建代理对象 --> 
<bean class="org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor"></bean> 
 ~~~
 
代码二、

<!-- 开启shiro的注解支持 --> 
<bean class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator" depends-on="lifecycleBeanPostProcessor"/>  
 <bean class="org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor">  

点赞
收藏
评论区
推荐文章
Easter79 Easter79
3年前
springboot代码自动生成
在项目开始阶段经常需要自动生成一批代码,如果使用了mybatis则可以使用mybatisplus就可以生成mybatis相关代码。不过经常项目中还有一些mvc代码需要生成,比如说前端代码、相关sql、swagger注解、权限注解等等。下面提供一个代码生成demospringboot集成vm自动生成前端代码、controller、service、myba
Wesley13 Wesley13
3年前
@Repository、@Service、@Controller 和 @Component
@Repository、@Service、@Controller(https://my.oschina.net/u/1774615)和@Component将类标识为Beanspring自2.0版本开始,陆续引入了一些注解用于简化Spring的开发。@Repository注解便属于最先引入的一批,它用于将数据访问层(DAO层)的类
Stella981 Stella981
3年前
Spring Boot快速入门(三):依赖注入
springboot使用依赖注入的方式很简单,只需要给添加相应的注解即可@Service用于标注业务层组件 @Controller用于标注控制层组件@Repository用于标注数据访问组件,即DAO组件 @Component泛指组件,当组件不好归类的时候,我们可以使用这个注解进行标注。然后在使用的地方使用@A
Stella981 Stella981
3年前
SpringBoot缓存相关问题
框架注解在写代码时,特别是SpringMVC框架下的代码,在dao层,service层,controller层,开始写代码时,一定要先在类上加@注解(https://my.oschina.net/u/3022537),切记不能再犯这个小错误.MyBatis与MySQL版本在使用MyBa
Stella981 Stella981
3年前
Micro
micromvc框架,借助nhmicro框架和groovy技术使所有的controller、servicebean、dao和sql脚本都支持动态热部署和调试。Controller层Controller层groovy中使用注解MicroUrlMapping设置url地址类上的注解必须有并作为根路径各个方法中设置子路径比如下面的gro
Easter79 Easter79
3年前
SpringBoot缓存相关问题
框架注解在写代码时,特别是SpringMVC框架下的代码,在dao层,service层,controller层,开始写代码时,一定要先在类上加@注解(https://my.oschina.net/u/3022537),切记不能再犯这个小错误.MyBatis与MySQL版本在使用MyBa
Easter79 Easter79
3年前
Spring注解大全,汇总版
Spring使用的注解大全和解释注解解释@Controller组合注解(组合了@Component注解),应用在MVC层(控制层),DispatcherServlet会自动扫描注解了此注解的类,然后将web请求映射到注解了@RequestMapping的方法上。@Service组合注解(组合了@Component注解),应用在
Stella981 Stella981
3年前
Spring Boot @ControllerAdvice+@ExceptionHandler处理controller异常
需求:  1.springboot 项目restful 风格统一放回json  2.不在controller写trycatch代码块简洁controller层  3.对异常做统一处理,同时处理@Validated校验器注解的异常方法:  @ControllerAdvice注解定义全局异常处理类@ControllerAdvice
Wesley13 Wesley13
3年前
1.1Spring Boot 环境配置和常用注解
SpringBoot常用注解:@Service:注解在类上,表示这是一个业务层bean@Controller:注解在类上,表示这是一个控制层bean@Repository:注解在类上,表示这是一个数据访问层bean@Component:注解在类上,表示通用bean,value不写默认就是类名首字母小写@Auto
Stella981 Stella981
3年前
Spring 12 种 常用注解!
1.声明bean的注解@Component组件,没有明确的角色@Service在业务逻辑层使用(service层)@Repository在数据访问层使用(dao层)@Controller在展现层使用,控制器的声明(C)2.注入bean的注解@Autowired:由Spring提供@Inj
Easter79 Easter79
3年前
Spring中@Controller、@Repository、@Service、@Component注解的作用详解
Spring中使用在类上的常用注解有@Controller、@Repository、@Service、@Component,下面分别详细介绍一下他们的作用:1、@Controller:用于标注控制层服务。2、@Repository:用于标注数据访问层,也可以说用于标注数据访问组件,即DAO组件。3、@Service:用于标注业务逻辑层服务,主要