春季安全'记住我'的cookie在第一次请求中不可用

时间:2013-12-06 10:30:29

标签: java spring cookies spring-security

我无法在登录请求后检索Spring记住我的cookie,但它在下一个对受保护页面的请求中工作正常。谁能告诉我如何立即掌握它?

我在登录请求中设置了记住我的cookie,但是在Spring重定向回原始(受保护的)URL后无法将其重新启动。

一步一步:

  1. 浏览器转至example.com/protected
  2. Spring重定向到登录表单页面
  3. 成功登录后,SPRING_SECURITY_REMEMBER_ME_COOKIE设置在一个非常薄的自定义子类org.springframework.security.web.authentication.rememberme.TokenBasedRememberMeServices
  4. 看起来Spring重定向回example.com/protected,没有往返于浏览器,并且登录“servlet”和受保护页面都由Tomcat 6中的同一个线程处理。
  5. 我们的org.springframework.security.web.access.expression.WebSecurityExpressionRoot的子类具有从< intercept-url pattern =“...”access =“method()”/>
  6. 在我们的方法()中,request.getCookies()不会在第一次请求时给出记住我的cookie,而是在之后的所有请求中给出。
  7. 我们的应用程序存在一些问题,因为cookie丢失了......
  8. 到目前为止,我的理论是我不理解SavedRequest。

    简明配置:

    <http auto-config="false" use-expressions="true" authentication-manager-ref="myAuthenticationManager" path-type="regex">
        <form-login authentication-success-handler-ref="myAuthenticationSuccessHandler" login-page="..." login-processing-url="..." authentication-failure-url="..." username-parameter="username" password-parameter="password" />
    
        <custom-filter ref="logoutFilter" position="LOGOUT_FILTER"/>
        <expression-handler ref="myWebSecurityExpressionHandler" />
    
        <custom-filter ref="myCustomeFilter1" before="FORM_LOGIN_FILTER"/>
        <custom-filter ref="myCustomeFilter2" position="BASIC_AUTH_FILTER"/>
        <custom-filter ref="mySecurityClientTokenAuthenticationFilter" after="LOGOUT_FILTER" />
    
        <access-denied-handler ref="myAccessDeniedHandler"/>
        <intercept-url pattern="xxx"
                       access="method()"/>
    
        <intercept-url pattern="yyy"
                       access="method()"/>
        <remember-me services-ref="rememberMeServices"  key="my_remember"/>
    </http>
    

    我尝试添加以下内容,唯一的结果是用户无法重定向到原始页面。

    <http ...
        <request-cache ref="nullRequestCache"/>
    </http>
    <bean:bean id="nullRequestCache" class="org.springframework.security.web.savedrequest.NullRequestCache"/>
    

0 个答案:

没有答案
相关问题