2012-01-02 33 views
5

可能重複:
create-session stateless usage無狀態webapp中的Spring Security?

我只是在試驗開始於春季安全,在3.1版本,並即時知道如何與無國籍Web應用程序來實現身份驗證。

想到http-basic和digest,我嘗試了它們,但是我不喜歡不關閉瀏覽器就不能像表單身份驗證一樣註銷。

我目前有一個使用spring security的基於表單的身份驗證的工作狀態web應用程序(通過在會話中存儲身份驗證信息使其成爲有狀態的),並且我想知道我可以研究哪些策略來使spring安全在不使用http會話的情況下工作?

我意識到有一個<http create-session="stateless" ..>,但肯定有些事情需要做更多的事情,因爲應用程序在我嘗試訪問受保護資源時不能正常工作,因此應用程序停止正常工作。

這裏是我的配置:

<http use-expressions="true" create-session="stateless"> 
    <form-login login-page="/login" 
     login-processing-url="/static/j_spring_security_check" 
     authentication-failure-url="/login?login_error=t" /> 
    <logout logout-url="/static/j_spring_security_logout"/> 

    <intercept-url pattern="/person/test/**" 
     access="isAuthenticated() and principal.username=='albertkam'" 
    /> 
    <intercept-url pattern="/person/**" access="hasRole('ROLE_NORMAL')"/> 

    <remember-me 
     key="spitterKey" 
     token-validity-seconds="2419200"/> 
</http> 

隨着create-session="stateless"

  1. 訪問http://myhost:8080/mycontext/person/blah
  2. 轉到登錄頁面。
  3. 返回到主頁網址http://myhost:8080/mycontext登錄後(我希望它返回到受保護的資源)

沒有create-session="stateless",默認爲ifRequired(狀態):

  1. 訪問http://myhost:8080/mycontext/person/blah
  2. 去登錄頁面
  3. 返回受保護的網址http://myhost:8080/mycontext/person/嗒嗒登錄後(這是正確的行爲,但狀態)
+1

它是這個[專題]有了答案[1] [1]:http://stackoverflow.com/questions/8800855/create-session-stateless-usage – bertie 2012-01-12 02:01:10

回答

0

您可以使用always-use-default-target="false"<form-login>防止會成功登錄後,默認的頁面。

+0

你好,我想你的建議,但它仍然與無國籍的主頁一樣。我認爲這不是問題,因爲沒有無狀態屬性值,流程正常工作。 – bertie 2012-01-02 14:23:31

+0

哦,很抱歉知道,我認爲always-use-default-target =「false」也應該在無狀態的情況下工作。 – kunal 2012-01-04 07:45:18

相關問題