可能重複:
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"
:
- 訪問http://myhost:8080/mycontext/person/blah
- 轉到登錄頁面。
- 返回到主頁網址http://myhost:8080/mycontext登錄後(我希望它返回到受保護的資源)
沒有create-session="stateless"
,默認爲ifRequired(狀態):
- 訪問http://myhost:8080/mycontext/person/blah
- 去登錄頁面
- 返回受保護的網址http://myhost:8080/mycontext/person/嗒嗒登錄後(這是正確的行爲,但狀態)
它是這個[專題]有了答案[1] [1]:http://stackoverflow.com/questions/8800855/create-session-stateless-usage – bertie 2012-01-12 02:01:10