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>


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM