2011-05-02 80 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

相关问题