【发布时间】:2021-03-09 02:06:08
【问题描述】:
从 servlet 容器 HTTP session 迁移到 spring session 成功登录后导致 HTTP 302。登录后我在第一次请求时收到了 HTTP 200,但后续请求似乎再次重定向到登录页面。无法调试后续请求,因为它似乎无法通过我放置断点的 servlet 到达。
现在,我们使用的是 spring session 1.3.5 版本。并且注意到在 spring 的 SessionRepositoryFilter 中,它将原始请求 cookie(例如 servlet 容器)替换为来自 spring session 的值。我不确定这是否是问题的根本原因。如果是,有人可以建议如何解决它吗?还是与某种缺失的配置有关?
这是基于春季会议指南的当前设置:here
Spring 会话 XML 配置:
<context:annotation-config/>
<bean class="org.springframework.session.hazelcast.config.annotation.web.http.HazelcastHttpSessionConfiguration"/>
<bean id="hazelcastInstance" class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
<property name="staticMethod" value="com.xxx.xxx.xxx.xxx.CustomHazelcastProvider.getInstance"/>
</bean>
<bean class="org.springframework.session.web.http.DefaultCookieSerializer">
<property name="cookieName" value="JSESSIONID"/>
<property name="cookiePath" value="/"/>
<property name="domainNamePattern" value="^.+?\.(\w+\.[a-z]+)$"/>
</bean>
web.xml中spring XML配置的参考:
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:application-context.xml</param-value>
</context-param>
在 web.xml 中注册 spring session 存储库过滤器。如指南中所述,我将其作为过滤器链的第一个条目。
<filter>
<filter-name>springSessionRepositoryFilter</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSessionRepositoryFilter</filter-name>
<url-pattern>/rs/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>ERROR</dispatcher>
</filter-mapping>
我已经研究了好几天了,还不知道如何修复它。如果您能提供任何帮助或建议,我们将不胜感激。
提前谢谢你。
【问题讨论】:
-
请注意,Spring Session 1.3.x 已结束生命周期,这意味着没有进一步的维护版本或安全补丁计划。请尽快迁移到受支持的分支。支持的版本有 2.2.x、2.3.x 和 2.4.x
-
@EleftheriaStein-Kousathana,非常感谢您的评论。由于当前库依赖问题,我们无法升级 2.x.x 版本。更改它还需要更改其他依赖项。我只是将 HTTP 会话策略从 cookie 替换为基于标头。到目前为止,我的应用程序正在按预期工作。
标签: spring session-cookies spring-session