2014-01-15 69 views
0

有什麼方法可以在用戶認證後設置Spring Security RememberMe cookie的域。版本3.1.4中API的更改使得子類化和重寫setCookie()方法變得不切實際。同樣在那個時候,我沒有我需要的認證信息來確定我想要設置cookie的域。認證後設置Spring的RememberMe Cookie域

基本上系統有兩種類型的用戶,我想基於哪種類型的用戶已經登錄來設置cookie域,以便他們只能使用記憶我身份驗證訪問其用戶特定區域。

我試圖從用戶進行身份驗證,然後修改域,然後將cookie添加到HttpServletResponse,但其不工作的HttpServletRequest的cookie。出現在瀏覽器中的cookie仍然附有根域。

有沒有更簡單的方法做我想做的事情?這一切都覺得應該已經有功能在某處做這件事。是否有可能改爲在我的CustomPersistentTokenBasedRememberMeService類中重定向?根據是否拋出異常,我知道用戶需要重定向哪個區域。

回答

0

我結束了以下這篇文章的建議:Spring Security RememberMe success handler or url filtering 並實現了AuthenticationSuccessHandler,我傳遞給我的表單登錄配置和我的記得我配置。

<http> 
    <form-login ... authentication-success-handler-ref="customAuthenticationSuccessHandler"/> 
    <remember-me authentication-success-handler-ref="customAuthenticationSuccessHandler"/> 
</http> 

<beans:bean id="customAuthenticationSuccessHandler" 
class="foo.bar.CustomAuthenticationSuccessHandler" /> 

,然後我在我的CustomAuthenticationSuccesshandler重寫onAuthenticationSuccess結束時,我只是把:

response.sendRedirect(response.encodeRedirectURL(redirectAddress)); 

,它就像一個魅力