TLDR:Spring在重定向到登录页面时会破坏当前的HTTP会话;这会破坏登录后导航到DefaultSavedRequest的能力。为什么会这样?
详情 - 我正在维护一个遗留的Spring应用程序:
尝试在我的登录配置中使用SavedRequestAwareAuthenticationSuccessHandler时,它无法正常工作。以下是似乎正在发生的事情:
http://localhost:8080/myapp/viewWorkOrder?workOrderNumber=315261
Spring正确地确定我没有登录并保存我的请求:
DEBUG o.s.s.w.s.HttpSessionRequestCache - DefaultSavedRequest added to Session: DefaultSavedRequest[http://localhost:8080/myapp/viewWorkOrder?workOrderNumber=315261]
Spring正确重定向到我的登录页面:
DEBUG o.s.security.web.FilterChainProxy - /login.jsp at position 1 of 9 in additional filter chain; firing Filter: 'ChannelProcessingFilter'
Spring会破坏当前会话,这会有效地破坏以后使用DefaultSavedRequest的能力:
DEBUG o.s.s.w.s.HttpSessionEventPublisher - Publishing event: org.springframework.security.web.session.HttpSessionDestroyedEvent[source=org.apache.catalina.session.StandardSessionFacade@b25f027]
为什么或什么导致当前会话被销毁?
以下是相关配置详情:
<bean id="savedRequestAwareAuthenticationSuccessHandler"
class="org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler">
<property name="defaultTargetUrl" value="/postLogin" />
<property name="targetUrlParameter" value="targetUrl" />
<property name="alwaysUseDefaultTargetUrl" value="false" />
</bean>
<security:http auto-config="false">
<!-- Override default login and logout pages -->
<security:form-login login-page="/login.jsp"
login-processing-url="/j_spring_security_check"
authentication-failure-url="/login.jsp?login_error=1"
authentication-success-handler-ref="savedRequestAwareAuthenticationSuccessHandler"
/>
<security:session-management session-fixation-protection="none"/>
session-management
似乎不会影响该功能。