我正在开发企业应用程序,包括 gwt/gwtp 和 spring security 。
我添加了一些会话超时问题,因为默认使用的 SimpleRedirectInvalidSessionStrategy 正在执行 response.sendRedirect() ,我想要重定向的 html 页面响应被 gwt com.google.gwt.user.client.rpc.InvocationException 吞下为异常消息。并且实际上没有发生重定向。
解决这个问题
1 .我定义了我的 cosutom session-manamgemt-filter
为此,您需要在 spring-security.xml 配置文件集中
<session-management session-fixation-protection="none"/> 今年春季安全不会采用默认会话管理过滤器。
-
定义您的会话管理过滤器
在此处输入代码
{
<custom-filter position="SESSION_MANAGEMENT_FILTER" ref="mySessionManagmentFilter"/>
<beans:bean id="mySessionManagmentFilter"
class="org.springframework.security.web.session.SessionManagementFilter">
<beans:constructor-arg index="0" ref="mySessionSecurityContextRepository"/>
<beans:constructor-arg index="1" ref="mySessionAutenticationStrategy"/>
<beans:property name="invalidSessionStrategy">
<beans:ref local="myInvalidSessionStrategy"/>
</beans:property>
</beans:bean>
<beans:bean id="mySessionSecurityContextRepository"
class='org.springframework.security.web.context.HttpSessionSecurityContextRepository'>
<beans:property name='allowSessionCreation' value='false'/>
</beans:bean>
<beans:bean id="mySessionAutenticationStrategy"
class="org.springframework.security.web.authentication.session.ConcurrentSessionControlStrategy">
<beans:constructor-arg name="sessionRegistry" ref="sessionRegistry"/>
<beans:property name="maximumSessions" value="1"/>
<beans:property name="exceptionIfMaximumExceeded" value="false"/>
<beans:property name="alwaysCreateSession" value="true"/>
</beans:bean>
<beans:bean id="myInvalidSessionStrategy"
class="com.my.project.MyInvalidSessionStrategy">
<beans:constructor-arg value="/login.jsp?timeout=1"/>
</beans:bean>
}
这里自定义 - MyInvalidSessionStrategy
{
public class MyInvalidSessionStrategy implements InvalidSessionStrategy {
private final Logger logger = LoggerFactory.getLogger(getClass());
private final String destinationUrl;
public OperationalInvalidSessionStrategy(String invalidSessionUrl) {
this.destinationUrl = invalidSessionUrl;
}
@Override
public void onInvalidSessionDetected(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
String exMsg =session timeout ! , need to redirect to login page
logger.warn(exMsg);
throw new TimeOutException(exMsg);
}
}
}
所以当超时发生时,新的实现会抛出异常..
异常可以是卡车上 gwt 回调 onFailure 方法
检查异常的类型并在 onFailure 方法上将用户重定向到登录页面。
Window.Location.replace(GWT.getHostPageBaseURL() + "/login.jsp")