加入配置:
sso.cookie.name=JSESSIONID
sso.cookie.path=/
sso.cookie.maxage=-1
sso.cookie.domain=XXX.com
配置Cooke domain 和 名称:
<bean id="defaultCookieSerializer" class="org.springframework.session.web.http.DefaultCookieSerializer">
<property name="domainName" value="${sso.cookie.domain}"/>
<property name="cookieName" value="${sso.cookie.name}"/>
<property name="cookieMaxAge" value="${sso.cookie.maxage}" />
<property name="cookiePath" value="${sso.cookie.path}" />
<!--<property name="domainNamePattern" value="^.+?\\.(\\w+\\.[a-z]+)$"/>-->
</bean>
domainNamePattern 的使用,受制很多条件,此处的源码如下:
private String getDomainName(HttpServletRequest request) {
if (this.domainName != null) {
return this.domainName;
}
if (this.domainNamePattern != null) {
Matcher matcher = this.domainNamePattern.matcher(request.getServerName());
if (matcher.matches()) {
return matcher.group(1);
}
}
return null;
}
request.getServerName() 能否正确的获取当前使用的域名,可能和反向代理服务器的配置有关,请谨慎使用。
Spring session 配置如下:
<!-- 配置spring session -->
<bean class="org.springframework.session.data.redis.config.annotation.web.http.RedisHttpSessionConfiguration">
<!-- session超时设置 -->
<property name="maxInactiveIntervalInSeconds" value="${spring.session.expiration}" />
<property name="cookieSerializer" ref="defaultCookieSerializer" />
</bean>