【问题标题】:Enable Shiro annotations in Spring based application在基于 Spring 的应用程序中启用 Shiro 注释
【发布时间】:2014-02-02 02:34:36
【问题描述】:

我的项目有两个模块 - webbuisness

web 模块 中,有一个带有配置的 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中的配置够吗?哪里可能出错? web 模块 中的身份验证工作正常。

过滤器有问题吗?我是否必须定义两个过滤器,一个使用&lt;filter-class&gt;org.springframework.web.filter.DelegatingFilterProxy&lt;/filter-class&gt;,另一个使用&lt;filter-class&gt;org.apache.shiro.web.servlet.ShiroFilter&lt;/filter-class&gt;? 谢谢你的建议。

【问题讨论】:

    标签: java spring shiro


    【解决方案1】:

    你的配置就够了。如果你还有BeanNameAutoProxyCreator等其他AOP设置,还需要将beanAuthorizationAttributeSourceAdvisor添加到属性interceptorNames中。

    【讨论】:

      猜你喜欢
      • 2012-05-07
      • 2018-09-04
      • 1970-01-01
      • 1970-01-01
      • 2013-08-26
      • 2011-12-31
      • 2016-06-03
      • 1970-01-01
      • 2012-09-30
      相关资源
      最近更新 更多