Spring Session 二级域名共享session配置

加入配置:

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>
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值