我正在运行一个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