From 447e8e3121c263f9ff401d325df5de6f7359c45b Mon Sep 17 00:00:00 2001 From: Lierbao Date: Tue, 3 Jan 2023 10:33:50 +0800 Subject: [PATCH] init --- .../security/auth/config/RedisSessionConfig.java | 49 ++++++++++++++++++++++ .../user/security/auth/constants/AuthTypeEnum.java | 47 +++++++++++++++++++++ .../auth/constants/SessionTimeConstant.java | 12 ++++++ 3 files changed, 108 insertions(+) create mode 100644 pmapi/src/main/java/com/ningdatech/pmapi/user/security/auth/config/RedisSessionConfig.java create mode 100644 pmapi/src/main/java/com/ningdatech/pmapi/user/security/auth/constants/AuthTypeEnum.java create mode 100644 pmapi/src/main/java/com/ningdatech/pmapi/user/security/auth/constants/SessionTimeConstant.java diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/user/security/auth/config/RedisSessionConfig.java b/pmapi/src/main/java/com/ningdatech/pmapi/user/security/auth/config/RedisSessionConfig.java new file mode 100644 index 0000000..af60fcd --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/user/security/auth/config/RedisSessionConfig.java @@ -0,0 +1,49 @@ +//package com.ningdatech.pmapi.user.security.auth.config; +// +//import com.ningdatech.basic.util.StrPool; +//import org.springframework.beans.factory.annotation.Value; +//import org.springframework.context.annotation.Bean; +//import org.springframework.context.annotation.Configuration; +// +///** +// *

+// * 设置session的过期时间为一天 +// *

+// * +// * @Author LiuXinXin +// * @Date 2020/7/29 9:46 上午 +// * @Version 1.0 +// **/ +//@Configuration +//@EnableRedisHttpSession( +// maxInactiveIntervalInSeconds = RedisSessionConfig.SESSION_TIMEOUT, +// redisNamespace = RedisSessionConfig.REDIS_NAMESPACE +//) +//public class RedisSessionConfig { +// +// static final int SESSION_TIMEOUT = 24 * 60 * 60 * 10; +// +// static final String REDIS_NAMESPACE = "#{redisSessionConfig.getRedisNamespace()}"; +// +// @Value("${nd.cache.def.keyPrefix:}") +// private String keyPrefix; +// +// public String getRedisNamespace() { +// return (StrUtils.isBlank(keyPrefix) ? StrPool.EMPTY : keyPrefix + StrPool.COLON) + RedisIndexedSessionRepository.DEFAULT_NAMESPACE; +// } +// +// @Bean +// public CookieHttpSessionIdResolver sessionIdResolver() { +// // 创建 CookieHttpSessionIdResolver 对象 +// CookieHttpSessionIdResolver sessionIdResolver = new CookieHttpSessionIdResolver(); +// // 创建 DefaultCookieSerializer 对象 +// DefaultCookieSerializer cookieSerializer = new DefaultCookieSerializer(); +// +// // 设置到 sessionIdResolver 中 +// sessionIdResolver.setCookieSerializer(cookieSerializer); +// cookieSerializer.setCookieName(BizConst.COOKIE_KEY); +// cookieSerializer.setCookieMaxAge(SessionTimeConstant.SESSION_TIME_SECONDS); +// return sessionIdResolver; +// } +// +//} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/user/security/auth/constants/AuthTypeEnum.java b/pmapi/src/main/java/com/ningdatech/pmapi/user/security/auth/constants/AuthTypeEnum.java new file mode 100644 index 0000000..927b5bd --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/user/security/auth/constants/AuthTypeEnum.java @@ -0,0 +1,47 @@ +package com.ningdatech.pmapi.user.security.auth.constants; + +/** + * @author Liuxinxin + * @date 2021/7/30 下午2:10 + */ + +public enum AuthTypeEnum { + + /** + * 手机 + 密码的认证方式 + */ + PHONE_PASSWORD("phone_password"), + + /** + * 子账号 账号 + 密码的认证方式 + */ + ACCOUNT_PASSWORD("account_password"); + + private final String key; + + AuthTypeEnum(String key) { + this.key = key; + } + + public static boolean contains(String key) { + for (AuthTypeEnum value : AuthTypeEnum.values()) { + if (key.equals(value.getKey())) { + return true; + } + } + return false; + } + + public String getKey() { + return key; + } + + public static AuthTypeEnum of(String key) { + for (AuthTypeEnum value : AuthTypeEnum.values()) { + if (key.equals(value.getKey())) { + return value; + } + } + throw new RuntimeException(String.format("invalid AuthTypeEnum = %s", key)); + } +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/user/security/auth/constants/SessionTimeConstant.java b/pmapi/src/main/java/com/ningdatech/pmapi/user/security/auth/constants/SessionTimeConstant.java new file mode 100644 index 0000000..a375263 --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/user/security/auth/constants/SessionTimeConstant.java @@ -0,0 +1,12 @@ +package com.ningdatech.pmapi.user.security.auth.constants; + +/** + * @Author LiuXinXin + * @Date 2022/2/17 12:59 上午 + * @Version 1.0 + **/ +public class SessionTimeConstant { + + public static final Integer SESSION_TIME_SECONDS = 24 * 60 * 60 * 10; + +}