【问题标题】:Spring Security - Is SavedRequestAwareAuthenticationSuccessHandler broke?Spring Security - SavedRequestAwareAuthenticationSuccessHandler 坏了吗?
【发布时间】:2018-02-19 04:58:36
【问题描述】:

TLDR:当重定向到登录页面时,Spring 正在破坏当前的 HTTP 会话;这会破坏登录后导航到 DefaultSavedRequest 的能力。为什么会这样?

详情 - 我正在维护一个遗留的 Spring 应用程序:

  • Spring Core 3.1.0 版
  • Spring Security 3.1.0 版

在我的登录配置中尝试使用 SavedRequestAwareAuthenticationSuccessHandler 时,它不起作用。以下是似乎正在发生的事情:

  • HTTP GET 到安全资源: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 似乎不会影响该功能。

【问题讨论】:

  • 你什么时候看到你的会话被破坏了?重定向之后?还是在您输入凭据并尝试登录之后?
  • @Leffchik,重定向之后。我将在一些评论中添加另一条评论,因为我尝试隔离相对于重定向控制器发生的情况。

标签: spring spring-security


【解决方案1】:

嗯,这很尴尬,但为了在堆栈溢出问题上成为一个好公民,我想我会分享我的发现。

在 Spring HttpSessionEventPublisher 中设置断点以查看堆栈是否可以为我提供线索后,确实可以。这是一个屏幕截图:

您会注意到 login.jsp 在堆栈中。作为这个特定应用程序的新手,我什至没有真正怀疑过 JSP,但这是我发现的:

显然,删除这个 scriptlet 解决了我的问题。现在我只是想知道为什么有人这样做以及我在此过程中破坏了什么:)

【讨论】:

    猜你喜欢
    • 2012-12-10
    • 2021-08-19
    • 2016-07-20
    • 2013-10-12
    • 2016-09-12
    • 2016-11-24
    • 1970-01-01
    • 2021-11-12
    • 2010-11-21
    相关资源
    最近更新 更多