package com.hz.pm.api.user.security.config;//package com.hz.pm.api.user.security.auth.config;

import com.hz.pm.api.common.model.constant.BizConst;
import com.hz.pm.api.user.security.auth.constants.SessionTimeConst;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.session.data.redis.config.annotation.web.http.EnableRedisHttpSession;
import org.springframework.session.web.http.CookieHttpSessionIdResolver;
import org.springframework.session.web.http.DefaultCookieSerializer;

/**
 * <p>
 * 设置session的过期时间为一天
 * </p>
 *
 * @author LiuXinXin
 * @since 2020/7/29 9:46 上午
 **/
@Configuration
@EnableRedisHttpSession
public class RedisSessionConfig {

    @Bean
    public CookieHttpSessionIdResolver sessionIdResolver() {
        // 创建 CookieHttpSessionIdResolver 对象
        CookieHttpSessionIdResolver sessionIdResolver = new CookieHttpSessionIdResolver();

        // 创建 DefaultCookieSerializer 对象
        DefaultCookieSerializer cookieSerializer = new DefaultCookieSerializer();
        sessionIdResolver.setCookieSerializer(cookieSerializer);
        // 设置到 sessionIdResolver 中
        cookieSerializer.setCookieName(BizConst.COOKIE_KEY);
        cookieSerializer.setCookieMaxAge(SessionTimeConst.SESSION_TIME_SECONDS);
        return sessionIdResolver;
    }

}
