spring-session - Spring Session 重写 cookie 值并在成功的 HTTP 请求上失败
问题描述
我们目前正在集成 spring session 1.3.5.RELEASE 版本来替换 servlet 容器 HTTP session。
Spring Session 的 SessionRepositoryFilter 以这样一种方式包装 HttpServletRequest,即每当您在应用程序中的任何位置从请求中获取 HttpSession 时,您实际上都获得了一个 Spring 会话对象。作为 spring session 内部 http session 策略的一部分,它重写了 cookie 值并替换了旧的。然后它用“Set-Cookie”属性传回响应头。
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
request.setAttribute(SESSION_REPOSITORY_ATTR, this.sessionRepository);
SessionRepositoryFilter<S>.SessionRepositoryRequestWrapper wrappedRequest = new SessionRepositoryFilter.SessionRepositoryRequestWrapper(request, response, this.servletContext);
SessionRepositoryFilter<S>.SessionRepositoryResponseWrapper wrappedResponse = new SessionRepositoryFilter.SessionRepositoryResponseWrapper(wrappedRequest, response);
HttpServletRequest strategyRequest = this.httpSessionStrategy.wrapRequest(wrappedRequest, wrappedResponse);
HttpServletResponse strategyResponse = this.httpSessionStrategy.wrapResponse(wrappedRequest, wrappedResponse);
try {
filterChain.doFilter(strategyRequest, strategyResponse);
} finally {
wrappedRequest.commitSession();
}
}
我怀疑这就是后续 HTTP 请求总是返回 HTTP 302 响应的原因。它被重定向到登录页面。
有没有人遇到过同样的问题?非常感谢您提供的任何支持或建议。