Замена фильтра по умолчанию в позиции SESSION_MANAGEMENT_FILTER

Я хочу заменить 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.

Спасибо,


person Simeon    schedule 24.04.2012    source источник
comment
Возможный дубликат ошибка того же значения порядка в Spring Security Custom SessionManagementfilter   -  person    schedule 04.01.2018


Ответы (1)


Если вы пытаетесь указать custom SESSION_MANAGEMENT_FILTER, чтобы можно было изменить sessionAuthenticationStrategy класса/экземпляра по умолчанию, просто используйте атрибут session-authentication-strategy-ref:

<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"/>
person matt b    schedule 24.04.2012
comment
У вас все еще есть идея, почему я получаю сообщение об ошибке с текущей конфигурацией? - person Simeon; 24.04.2012
comment
Это не на 100% ясно, но я считаю, что использование пространства имен безопасности добавит некоторые bean-компоненты по умолчанию, даже если у вас есть ‹http auto-config=false›`. - person matt b; 24.04.2012
comment
Попробовал, получилось отлично, еще раз спасибо. Немного странно, что только использование пространства имен добавляет неявные bean-компоненты. - person Simeon; 25.04.2012