|
@@ -8,7 +8,6 @@ import java.util.Deque;
|
|
|
import java.util.Objects;
|
|
|
import java.util.Set;
|
|
|
import java.util.function.Function;
|
|
|
-import java.util.stream.Stream;
|
|
|
import javax.servlet.ServletRequestEvent;
|
|
|
import javax.servlet.ServletRequestListener;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
@@ -86,14 +85,19 @@ public class SessionContextHolder implements ServletRequestListener {
|
|
|
public static final String HEADER_VERSION = "version";
|
|
|
|
|
|
/**
|
|
|
- * 权限标识请求头
|
|
|
+ * 请求时间戳请求头
|
|
|
*/
|
|
|
- public static final String HEADER_AUTHORITIES = "authorities";
|
|
|
+ public static final String HEADER_TIMESTAMP = "timestamp";
|
|
|
|
|
|
/**
|
|
|
- * 时间戳请求头
|
|
|
+ * 注册时间戳请求头
|
|
|
*/
|
|
|
- public static final String HEADER_TIMESTAMP = "timestamp";
|
|
|
+ public static final String HEADER_REGISTERING = "registering";
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 权限标识请求头
|
|
|
+ */
|
|
|
+ public static final String HEADER_AUTHORITIES = "authorities";
|
|
|
|
|
|
/**
|
|
|
* 空会话对象实例
|
|
@@ -150,44 +154,7 @@ public class SessionContextHolder implements ServletRequestListener {
|
|
|
* @return 会话信息
|
|
|
*/
|
|
|
public static Session setSession(@NonNull Long id, @NonNull String scope) {
|
|
|
- return setSession(id, Using.NORMAL, scope);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 设置会话信息,如果当前已存在会话则更新会话主体信息
|
|
|
- *
|
|
|
- * @param id 主体标识
|
|
|
- * @param using 使用类别
|
|
|
- * @param scope 应用范围
|
|
|
- * @return 会话信息
|
|
|
- */
|
|
|
- public static Session setSession(@NonNull Long id, @NonNull Using using, @NonNull String scope) {
|
|
|
- return setSession(id, using, scope, (String) null);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 设置会话信息,如果当前已存在会话则更新会话主体信息
|
|
|
- *
|
|
|
- * @param id 主体标识
|
|
|
- * @param scope 应用范围
|
|
|
- * @param mobile 手机号码
|
|
|
- * @return 会话信息
|
|
|
- */
|
|
|
- public static Session setSession(@NonNull Long id, @NonNull String scope, String mobile) {
|
|
|
- return setSession(id, Using.NORMAL, scope, mobile);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 设置会话信息,如果当前已存在会话则更新会话主体信息
|
|
|
- *
|
|
|
- * @param id 主体标识
|
|
|
- * @param using 使用类别
|
|
|
- * @param scope 应用范围
|
|
|
- * @param mobile 手机号码
|
|
|
- * @return 会话信息
|
|
|
- */
|
|
|
- public static Session setSession(@NonNull Long id, @NonNull Using using, @NonNull String scope, String mobile) {
|
|
|
- return setSession(id, using, scope, mobile, Collections.emptySet());
|
|
|
+ return setSession(id, scope, Collections.emptySet());
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -199,35 +166,7 @@ public class SessionContextHolder implements ServletRequestListener {
|
|
|
* @return 会话信息
|
|
|
*/
|
|
|
public static Session setSession(@NonNull Long id, @NonNull String scope, @NonNull Set<String> authorities) {
|
|
|
- return setSession(id, Using.NORMAL, scope, authorities);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 设置会话信息,如果当前已存在会话则更新会话主体信息
|
|
|
- *
|
|
|
- * @param id 主体标识
|
|
|
- * @param using 使用类别
|
|
|
- * @param scope 应用范围
|
|
|
- * @param authorities 权限标识集合
|
|
|
- * @return 会话信息
|
|
|
- */
|
|
|
- public static Session setSession(@NonNull Long id, @NonNull Using using, @NonNull String scope,
|
|
|
- @NonNull Set<String> authorities) {
|
|
|
- return setSession(id, using, scope, null, authorities);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 设置会话信息,如果当前已存在会话则更新会话主体信息
|
|
|
- *
|
|
|
- * @param id 主体标识
|
|
|
- * @param scope 应用范围
|
|
|
- * @param mobile 手机号码
|
|
|
- * @param authorities 权限标识集合
|
|
|
- * @return 会话信息
|
|
|
- */
|
|
|
- public static Session setSession(@NonNull Long id, @NonNull String scope, String mobile,
|
|
|
- @NonNull Set<String> authorities) {
|
|
|
- return setSession(id, Using.NORMAL, scope, mobile, authorities);
|
|
|
+ return setSession(id, Using.NORMAL, scope, null, null, authorities);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -237,23 +176,24 @@ public class SessionContextHolder implements ServletRequestListener {
|
|
|
* @param using 使用类别
|
|
|
* @param scope 应用范围
|
|
|
* @param mobile 手机号码
|
|
|
+ * @param registering 注册时间戳
|
|
|
* @param authorities 权限标识集合
|
|
|
* @return 会话信息
|
|
|
*/
|
|
|
public static Session setSession(@NonNull Long id, @NonNull Using using, @NonNull String scope, String mobile,
|
|
|
- @NonNull Set<String> authorities) {
|
|
|
+ Long registering, @NonNull Set<String> authorities) {
|
|
|
Deque<Session> deque = SESSION_CONTEXT.get();
|
|
|
Session session = deque.peek();
|
|
|
if (session == null || session == EMPTY_SESSION) {
|
|
|
if (session != null) {
|
|
|
deque.poll();
|
|
|
}
|
|
|
- session = Session.builder().id(id).using(using).scope(scope).mobile(mobile)
|
|
|
+ session = Session.builder().id(id).using(using).scope(scope).mobile(mobile).registering(registering)
|
|
|
.authorities(Collections.unmodifiableSet(authorities))
|
|
|
.timestamp(System.currentTimeMillis()).build();
|
|
|
deque.push(session);
|
|
|
} else {
|
|
|
- session.initializePrincipal(id, using, scope, mobile, authorities);
|
|
|
+ session.initializePrincipal(id, using, scope, mobile, registering, authorities);
|
|
|
}
|
|
|
return session;
|
|
|
}
|
|
@@ -357,6 +297,15 @@ public class SessionContextHolder implements ServletRequestListener {
|
|
|
return ObjectUtils.ifNull(getSession(false), Session::getTimestamp);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 获取注册时间戳
|
|
|
+ *
|
|
|
+ * @return 时间戳
|
|
|
+ */
|
|
|
+ public static Long getRegistering() {
|
|
|
+ return ObjectUtils.ifNull(getSession(false), Session::getRegistering);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 判断是否是审核用户
|
|
|
*
|
|
@@ -464,6 +413,38 @@ public class SessionContextHolder implements ServletRequestListener {
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 判断是否是指定版本
|
|
|
+ *
|
|
|
+ * @param version 版本注解
|
|
|
+ * @return true/false
|
|
|
+ */
|
|
|
+ public static boolean isVersion(@NonNull com.chelvc.framework.base.annotation.Version version) {
|
|
|
+ String value = version.value();
|
|
|
+ if (StringUtils.isEmpty(value)) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ Environment environment = ApplicationContextHolder.getEnvironment(false);
|
|
|
+ if (environment != null) {
|
|
|
+ value = environment.resolvePlaceholders(value);
|
|
|
+ }
|
|
|
+ value = ApplicationContextHolder.getProperty(value, value);
|
|
|
+ if (version.compare() == Compare.EQ) {
|
|
|
+ return isVersion(version.terminal(), value);
|
|
|
+ } else if (version.compare() == Compare.NE) {
|
|
|
+ return !isVersion(version.terminal(), value);
|
|
|
+ } else if (version.compare() == Compare.GT) {
|
|
|
+ return isAfterVersion(version.terminal(), value);
|
|
|
+ } else if (version.compare() == Compare.GE) {
|
|
|
+ return isAfterVersion(version.terminal(), value, true);
|
|
|
+ } else if (version.compare() == Compare.LT) {
|
|
|
+ return isBeforeVersion(version.terminal(), value);
|
|
|
+ } else if (version.compare() == Compare.LE) {
|
|
|
+ return isBeforeVersion(version.terminal(), value, true);
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 判断是否是指定版本
|
|
|
*
|
|
@@ -471,31 +452,14 @@ public class SessionContextHolder implements ServletRequestListener {
|
|
|
* @return true/false
|
|
|
*/
|
|
|
public static boolean isVersion(@NonNull com.chelvc.framework.base.annotation.Version... versions) {
|
|
|
- return ObjectUtils.notEmpty(versions) && Stream.of(versions).anyMatch(version -> {
|
|
|
- String value = version.value();
|
|
|
- if (StringUtils.isEmpty(value)) {
|
|
|
- return false;
|
|
|
- }
|
|
|
- Environment environment = ApplicationContextHolder.getEnvironment(false);
|
|
|
- if (environment != null) {
|
|
|
- value = environment.resolvePlaceholders(value);
|
|
|
- }
|
|
|
- value = ApplicationContextHolder.getProperty(value, value);
|
|
|
- if (version.compare() == Compare.EQ) {
|
|
|
- return isVersion(version.terminal(), value);
|
|
|
- } else if (version.compare() == Compare.NE) {
|
|
|
- return !isVersion(version.terminal(), value);
|
|
|
- } else if (version.compare() == Compare.GT) {
|
|
|
- return isAfterVersion(version.terminal(), value);
|
|
|
- } else if (version.compare() == Compare.GE) {
|
|
|
- return isAfterVersion(version.terminal(), value, true);
|
|
|
- } else if (version.compare() == Compare.LT) {
|
|
|
- return isBeforeVersion(version.terminal(), value);
|
|
|
- } else if (version.compare() == Compare.LE) {
|
|
|
- return isBeforeVersion(version.terminal(), value, true);
|
|
|
+ if (ObjectUtils.notEmpty(versions)) {
|
|
|
+ for (com.chelvc.framework.base.annotation.Version version : versions) {
|
|
|
+ if (isVersion(version)) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
}
|
|
|
- return false;
|
|
|
- });
|
|
|
+ }
|
|
|
+ return false;
|
|
|
}
|
|
|
|
|
|
/**
|