我正在運行一個GWT應用程序,它在會話對象中維護用戶緩存。我正在使用Spring Security 3.0.5。在網絡模式下獲取會話null在GWT應用程序中,但不在託管模式下
以下是我用來獲取會話對象
ServletRequestAttributes attr = (ServletRequestAttributes) RequestContextHolder.currentRequestAttributes();
HttpSession session = attr.getRequest().getSession(false);
if(session != null)
return session;
else
throw new IllegalStateException("Session Expired");
在託管模式,即碼頭服務器的代碼,一切工作正常,我能夠檢索會話對象,但在Web模式即tomcat的6,會話對象則返回null
我使用web.xml中有以下條目,運行上面的代碼
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>
org.springframework.web.context.request.RequestContextListener
</listener-class>
</listener>
要求UPDATE
以下是我使用
<http>
<intercept-url pattern="/**Phoenix.html*" access="ROLE_ADMIN"/>
<form-login authentication-failure-url="/login.html" default-target-url="/Phoenix.html?gwt.codesvr=127.0.0.1:9997" always-use-default-target="true"/>
<remember-me/>
<logout />
<access-denied-handler error-page="/login.html"/>
<session-management><concurrency-control/></session-management>
</http>
UPDATE
這是在網絡模式,因爲發生登錄後 SecurityContextHolder.getContext().getAuthentication().getPrincipal().toString()
返回「anonymousUser」 ,而在託管模式的春季安全設置相同的表達式會返回登錄用戶的登錄憑據。 以下是我使用的網址 託管模式:http://127.0.0.1:8888/Phoenix.html?gwt.codesvr=127.0.0.1:9997
網絡模式:http://localhost:8185/PhoenixMCDemo/Phoenix.html;jsessionid=E56C80258410D102E6B51EFEE5AA0E91
完全相同的問題 – kozla13 2013-12-12 13:50:52