2011-05-02 75 views
1

我正在運行一個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

+0

完全相同的問題 – kozla13 2013-12-12 13:50:52

回答

0

你有沒有enable sessions

+0

我不是在應用程序引擎模式下工作,無論如何,最初能夠登錄創建會話對象。問題在於rpc請求沒有被識別,因爲它的url中缺少會話ID。我通過使用Cookie進行會話管理來解決此問題。有關更多詳情,請參閱:http://technical-ramblings.blogspot.com/2011/05/accessing-session-objects-with-gwt-and.html – 2011-06-14 07:36:57

相關問題