shiro和Spring整合使用注解时没有执行realm的doGetAuthorizationInfo回调方法的解决(XML配置)

在使用Shiro框架进行项目整合时,使用注解在使用Shiro框架进行项目整合时,使用注解在使用Shiro框架进行项目整合时,使用注解@RequiresPermissions为方法提供是需要的权限,但是根本没有进行验证,后面发现在自己的Realm中只执行了doGetAuthenticationInfo(登录验证)方法而没有执行doGetAuthorizationInfo(权限验证)的方法。

查看相关资料后发现是因为在Springmvc的配置文件中(我的名字是spring-servlet.xml)没有加入

<aop:config proxy-target-class="true"/>

<!-- 开启shiro注解 -->
<bean class="org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor">
    <property name="securityManager" ref="securityManager" />
</bean>

加入后解决问题.

也可以使用:

<!-- 支持Shiro对Controller的方法级AOP安全控制 begin-->
<bean class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator" depends-on="lifecycleBeanPostProcessor">
  <property name="proxyTargetClass" value="true" />
</bean>

<bean class="org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor">
    <property name="securityManager" ref="securityManager" />
</bean>
<!-- 保证实现了Shiro内部lifecycle函数的bean执行 -->
<bean id="lifecycleBeanPostProcessor" class="org.apache.shiro.spring.LifecycleBeanPostProcessor"/>

但是一定要记住是把以下配置放在SpringMvc的配置文件中。

<aop:config proxy-target-class="true"/>

<bean class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator" depends-on="lifecycleBeanPostProcessor">
  <property name="proxyTargetClass" value="true" />
</bean>

posted @ 2018-04-11 00:05  路途寻码人  阅读(2522)  评论(0编辑  收藏  举报