2014-01-14 92 views
1

我有兩個模塊的項目 - webbuisness在基於Spring的應用程序中啓用Shiro註釋

網絡模塊,有一個與配置的shiro.ini文件(如教程 - https://github.com/lhazlewood/apache-shiro-tutorial-webapp/blob/step7/src/main/webapp/WEB-INF/shiro.ini - 用我自己的屬性)。

樓內設有商務模塊,沒有與此代碼applicationContext.xml文件:

<bean id="iniRealm" class="org.apache.shiro.realm.text.IniRealm"> 
    <property name="resourcePath" value="file:C:\project\webmodule\src\main\webapp\WEB-INF\shiro.ini" /> 
</bean> 

<bean id="lifecycleBeanPostProcessor" class="org.apache.shiro.spring.LifecycleBeanPostProcessor" /> 

<bean class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator" depends-on="lifecycleBeanPostProcessor" /> 

<bean id="securityManager" class="org.apache.shiro.web.mgt.DefaultWebSecurityManager"> 
    <property name="realm" ref="iniRealm" /> 
</bean> 

<bean class="org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor"> 
    <property name="securityManager" ref="securityManager" /> 
</bean> 

但是,如果我想使用的註釋,像@RequiresAuthentication,這是行不通的。

applicationContext.xml中的配置是否足夠?哪裏可以是一個錯誤?在網絡模塊認證工作正常。

它可能是過濾器的問題?我是否必須定義兩個過濾器,一個是<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>,另一個是<filter-class>org.apache.shiro.web.servlet.ShiroFilter</filter-class>? 謝謝你的任何建議。

回答

1

您的配置就足夠了。如果您有其他AOP設置,例如BeanNameAutoProxyCreator,則還需要將AuthorizationAttributeSourceAdvisor豆添加到屬性interceptorNames中。

相關問題