java - 替换 SESSION_MANAGEMENT_FILTER 位置的默认过滤器

标签 java spring spring-security servlet-filters

我想替换默认的SessionManagementFilter和我自己的,但我遇到了这个

17:31:32,901 ERROR [[/accounts]] Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Filter beans '<accountsSessionManageFilter>' and 'Root bean: class [org.springframework.security.web.session.SessionManagementFilter]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null' have the same 'order' value. When using custom filters, please make sure the positions do not conflict with default filters. Alternatively you can disable the default filters by removing the corresponding child elements from <http> and avoiding the use of <http auto-config='true'>. Offending resource: ServletContext resource [/WEB-INF/spring-contexts/security.xml]

问题似乎是我使用的是 <http>在同一位置设置默认过滤器的元素/属性。但是我不是(或者如果我是无意的)。

这是我的安全上下文 <http>定义:

<http use-expressions="true" auto-config="false" entry-point-ref="loginUrlAuthenticationEntryPoint">

    <!-- lots of intercept-url definitions (nothing else) -->

    <custom-filter position="SESSION_MANAGEMENT_FILTER" ref="accountsSessionManageFilter"/>
    <custom-filter position="FORM_LOGIN_FILTER" ref="accountsSsoFilter"/>
</http>

.......

<beans:bean id="accountsSessionManageFilter" class="org.springframework.security.web.session.SessionManagementFilter">
    <beans:property name="sessionAuthenticationStrategy" ref="NullAuthenticatedSessionStrategy"/>
</beans:bean>

.......

<bean id="accountsSsoFilter" class="cayetano.core.base.service.impl.spring.filter.SsoUserPassAuthFilter">
    <property name="authenticationManager" ref="ssoAuthManager" />

    <property name="authenticationFailureHandler" ref="relativeLoginFailureHandler" />
    <property name="authenticationSuccessHandler" ref="noopLoginSuccessHandler" />

    <property name="authenticationService" ref="basicAuthenticatorService" />
    <property name="authorityService" ref="userTypeBasedAuthotiryService" />
</bean>

那么为什么 Spring 会提示我使用的是 <http>使用默认过滤器的元素?

文档还指出 <session-management>是唯一<http>使用默认过滤器的元素,还有其他吗?

我正在使用 Spring Security 3.0。

谢谢,

最佳答案

如果您尝试指定一个自定义 SESSION_MANAGEMENT_FILTER 以便您可以更改默认类/实例的 sessionAuthenticationStrategy,只需使用 the session-authentication-strategy-ref attribute :

<http ...>
    <session-management session-authentication-strategy-ref="NullAuthenticatedSessionStrategy"/>
</http>

这当然假定 NullAuthenticatedSessionStrategy 是上下文中定义的另一个 bean。由于这也是 Spring Security 中的一个类的名称,我认为您真正想要的是:

<http ...>
    <session-management session-authentication-strategy-ref="sessionStrategy"/>
</http>

<bean id="sessionStrategy" class="org.springframework.security.web.authentication.session.NullAuthenticatedSessionStrategy"/>

关于java - 替换 SESSION_MANAGEMENT_FILTER 位置的默认过滤器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10300369/

相关文章:

java - 跨多个容器的安全上下文

java - Spring 安全和 Thymeleaf 不起作用

java - 将 "daemon"-status 传播到 Java 中的所有子线程

java - Spring Data JPA - 结果中具有多个聚合函数的自定义查询

java - 如何使用自己的数据库用户使用 spring security 和 JWT 进行身份验证

java - 我应该为 DAO 测试类使用@Transactional 还是@Rollback?

java - 使用自定义身份验证处理 Spring 5 中的 AuthenticationException

java - ElasticSearch 中集群中的节点如何通信,以及我们如何决定应该在哪个节点存储文档以及稍后从哪里检索文档?

java - Spring Boot REST 应用测试方法

java - 诺基亚 S60 Java SDK?