1. 程式人生 > >shiro和Spring整合使用註解時沒有執行realm的doGetAuthorizationInfo回撥方法的解決

shiro和Spring整合使用註解時沒有執行realm的doGetAuthorizationInfo回撥方法的解決

在使用Shiro框架進行專案整合時,使用註解在使用Shiro框架進行專案整合時,使用註解在使用Shiro框架進行專案整合時,使用註解@RequiresPermissions為方法提供是需要的許可權,但是根本沒有進行驗證,後面發現在自己的Realm中只執行了doGetAuthenticationInfo(登入驗證)方法而沒有執行doGetAuthorizationInfo(許可權驗證)的方法。

檢視相關資料後發現是因為在Springmvc的配置檔案中(我的名字是spring-servlet.xml)沒有加入

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

加入後解決問題.

貌似也可以使用:

<!-- 支援Shiro對Controller的方法級AOP安全控制 begin-->
<bean class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator" depends-on="lifecycleBeanPostProcessor">
<property name="proxyTargetClass" value="true" />
</bean>
<!-- 保證實現了Shiro內部lifecycle函式的bean執行 -->
<bean id="lifecycleBeanPostProcessor" class="org.apache.shiro.spring.LifecycleBeanPostProcessor"/>

但是一定要記住是把這些配置放在     SpringMvc的配置檔案中。