woody 4 hónapja
szülő
commit
985b8d7f0a

+ 8 - 0
framework-base/src/main/java/com/chelvc/framework/base/annotation/Version.java

@@ -7,6 +7,7 @@ import java.lang.annotation.Target;
 
 import com.chelvc.framework.common.model.Compare;
 import com.chelvc.framework.common.model.Terminal;
+import com.chelvc.framework.common.util.StringUtils;
 
 /**
  * 客户端版本号注解
@@ -38,4 +39,11 @@ public @interface Version {
      * @return 比较方式
      */
     Compare compare() default Compare.EQ;
+
+    /**
+     * 获取异常消息
+     *
+     * @return 异常消息
+     */
+    String message() default StringUtils.EMPTY;
 }

+ 32 - 17
framework-base/src/main/java/com/chelvc/framework/base/context/DefaultSessionFactory.java

@@ -144,45 +144,60 @@ public class DefaultSessionFactory implements SessionFactory {
     }
 
     /**
-     * 获取权限标识集合
+     * 获取请求时间戳
      *
      * @param request Http请求对象
-     * @return 权限标识集合
+     * @return 时间戳
      */
-    protected Set<String> getAuthorities(@NonNull HttpServletRequest request) {
-        Enumeration<String> enumeration = request.getHeaders(SessionContextHolder.HEADER_AUTHORITIES);
-        if (enumeration == null) {
-            return Collections.emptySet();
-        }
-        Set<String> authorities = Sets.newHashSetWithExpectedSize(3);
-        while (enumeration.hasMoreElements()) {
-            authorities.add(enumeration.nextElement());
+    protected Long getTimestamp(@NonNull HttpServletRequest request) {
+        try {
+            return StringUtils.ifEmpty(request.getHeader(SessionContextHolder.HEADER_TIMESTAMP), Long::parseLong);
+        } catch (Exception e) {
+            log.warn("Timestamp convert failed: {}", e.getMessage());
         }
-        return authorities;
+        return null;
     }
 
     /**
-     * 获取请求时间戳
+     * 获取注册时间戳
      *
      * @param request Http请求对象
      * @return 时间戳
      */
-    protected Long getTimestamp(@NonNull HttpServletRequest request) {
+    protected Long getRegistering(@NonNull HttpServletRequest request) {
         try {
-            return StringUtils.ifEmpty(request.getHeader(SessionContextHolder.HEADER_TIMESTAMP), Long::parseLong);
+            return StringUtils.ifEmpty(request.getHeader(SessionContextHolder.HEADER_REGISTERING), Long::parseLong);
         } catch (Exception e) {
-            log.warn("Timestamp convert failed: {}", e.getMessage());
+            log.warn("Registering convert failed: {}", e.getMessage());
         }
         return null;
     }
 
+    /**
+     * 获取权限标识集合
+     *
+     * @param request Http请求对象
+     * @return 权限标识集合
+     */
+    protected Set<String> getAuthorities(@NonNull HttpServletRequest request) {
+        Enumeration<String> enumeration = request.getHeaders(SessionContextHolder.HEADER_AUTHORITIES);
+        if (enumeration == null) {
+            return Collections.emptySet();
+        }
+        Set<String> authorities = Sets.newHashSetWithExpectedSize(3);
+        while (enumeration.hasMoreElements()) {
+            authorities.add(enumeration.nextElement());
+        }
+        return authorities;
+    }
+
     @Override
     public Session build(@NonNull HttpServletRequest request) {
         return Session.builder().id(this.getId(request)).using(this.getUsing(request)).host(this.getHost(request))
                 .scope(this.getScope(request)).mobile(this.getMobile(request)).device(this.getDevice(request))
                 .channel(this.getChannel(request)).platform(this.getPlatform(request))
                 .terminal(this.getTerminal(request)).version(this.getVersion(request))
-                .authorities(Collections.unmodifiableSet(this.getAuthorities(request)))
-                .timestamp(this.getTimestamp(request)).build();
+                .timestamp(this.getTimestamp(request)).registering(this.getRegistering(request))
+                .authorities(Collections.unmodifiableSet(this.getAuthorities(request))).build();
     }
 }

+ 12 - 5
framework-base/src/main/java/com/chelvc/framework/base/context/Session.java

@@ -87,14 +87,19 @@ public class Session implements Serializable {
     private String version;
 
     /**
-     * 权限标识集合
+     * 请求时间戳
      */
-    private Set<String> authorities;
+    private Long timestamp;
 
     /**
-     * 请求时间戳
+     * 注册时间戳
      */
-    private Long timestamp;
+    private Long registering;
+
+    /**
+     * 权限标识集合
+     */
+    private Set<String> authorities;
 
     /**
      * 分组场景/标识映射表
@@ -132,14 +137,16 @@ public class Session implements Serializable {
      * @param using       使用类别
      * @param scope       应用范围
      * @param mobile      手机号码
+     * @param registering 注册时间戳
      * @param authorities 权限标识集合
      */
     void initializePrincipal(@NonNull Long id, @NonNull Using using, @NonNull String scope, String mobile,
-                             @NonNull Set<String> authorities) {
+                             Long registering, @NonNull Set<String> authorities) {
         this.id = id;
         this.using = using;
         this.scope = scope;
         this.mobile = mobile;
+        this.registering = registering;
         this.authorities = Collections.unmodifiableSet(authorities);
     }
 }

+ 63 - 99
framework-base/src/main/java/com/chelvc/framework/base/context/SessionContextHolder.java

@@ -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;
     }
 
     /**

+ 9 - 9
framework-base/src/main/java/com/chelvc/framework/base/context/Using.java

@@ -49,25 +49,25 @@ public enum Using implements Enumerable {
     /**
      * 根据上次使用时间及注册时间计算使用类型
      *
-     * @param latest      上次使用时间戳
-     * @param registering 用户注册时间戳
+     * @param latest   上次使用时间戳
+     * @param creating 用户创建时间戳
      * @return 使用类型枚举
      */
-    public static Using from(Long latest, Long registering) {
-        return from(latest, registering, DEFAULT_NEWLY_INTERVAL);
+    public static Using from(Long latest, Long creating) {
+        return from(latest, creating, DEFAULT_NEWLY_INTERVAL);
     }
 
     /**
      * 根据上次使用时间及注册时间计算使用类型
      *
-     * @param latest      上次使用时间戳
-     * @param registering 用户注册时间戳
-     * @param interval    使用刷新时间间隔(毫秒)
+     * @param latest   上次使用时间戳
+     * @param creating 用户创建时间戳
+     * @param interval 使用刷新时间间隔(毫秒)
      * @return 使用类型枚举
      */
-    public static Using from(Long latest, Long registering, long interval) {
+    public static Using from(Long latest, Long creating, long interval) {
         if (latest == null) {
-            return registering == null || registering < DateUtils.today().getTime() ? DAILY : INITIAL;
+            return creating == null || creating < DateUtils.today().getTime() ? DAILY : INITIAL;
         }
         return System.currentTimeMillis() - latest > interval ? NEWLY : NORMAL;
     }

+ 124 - 0
framework-base/src/main/java/com/chelvc/framework/base/interceptor/ControllerAccessInterceptor.java

@@ -0,0 +1,124 @@
+package com.chelvc.framework.base.interceptor;
+
+import java.lang.reflect.Method;
+
+import ch.qos.logback.classic.Level;
+import com.chelvc.framework.base.annotation.Version;
+import com.chelvc.framework.base.annotation.Versions;
+import com.chelvc.framework.base.context.ApplicationContextHolder;
+import com.chelvc.framework.base.context.LoggingContextHolder;
+import com.chelvc.framework.base.context.SessionContextHolder;
+import com.chelvc.framework.common.exception.ResourceUnavailableException;
+import com.chelvc.framework.common.model.Terminal;
+import com.chelvc.framework.common.util.ObjectUtils;
+import com.chelvc.framework.common.util.StringUtils;
+import lombok.extern.slf4j.Slf4j;
+import org.aspectj.lang.JoinPoint;
+import org.aspectj.lang.ProceedingJoinPoint;
+import org.aspectj.lang.Signature;
+import org.aspectj.lang.annotation.Around;
+import org.aspectj.lang.annotation.Aspect;
+import org.aspectj.lang.reflect.MethodSignature;
+import org.springframework.boot.web.servlet.error.ErrorController;
+import org.springframework.core.Ordered;
+import org.springframework.core.annotation.Order;
+import org.springframework.core.env.Environment;
+import org.springframework.stereotype.Component;
+import org.springframework.web.bind.annotation.ExceptionHandler;
+
+/**
+ * Controller接口访问拦截器
+ *
+ * @author Woody
+ * @date 2024/1/30
+ */
+@Slf4j
+@Aspect
+@Component
+@Order(Ordered.HIGHEST_PRECEDENCE)
+public class ControllerAccessInterceptor {
+    /**
+     * 判断是否开启调试日志
+     *
+     * @param point 接口方法拦截点
+     * @return true/false
+     */
+    private boolean isDebug(JoinPoint point) {
+        Object target = point.getTarget();
+        if (target instanceof ErrorController) {
+            return false;
+        }
+        Signature signature = point.getSignature();
+        return signature instanceof MethodSignature
+                && !((MethodSignature) signature).getMethod().isAnnotationPresent(ExceptionHandler.class)
+                && LoggingContextHolder.level(signature.getDeclaringTypeName()) == Level.DEBUG;
+    }
+
+    /**
+     * 检查终端版本号
+     *
+     * @param point 接口方法拦截点
+     */
+    private void checkVersion(JoinPoint point) {
+        Signature signature = point.getSignature();
+        if (!(signature instanceof MethodSignature)) {
+            return;
+        }
+
+        Terminal terminal = SessionContextHolder.getTerminal();
+        if (terminal == null) {
+            return;
+        }
+
+        // 接口方法/类版本注解校验
+        Method method = ((MethodSignature) signature).getMethod();
+        Version[] versions = ObjectUtils.ifNull(method.getAnnotation(Versions.class), Versions::value);
+        if (ObjectUtils.isEmpty(versions)) {
+            Class<?> declaring = signature.getDeclaringType();
+            versions = ObjectUtils.ifNull(declaring.getAnnotation(Versions.class), Versions::value);
+        }
+        if (ObjectUtils.notEmpty(versions)) {
+            Environment environment = ApplicationContextHolder.getEnvironment(false);
+            for (Version version : versions) {
+                if (version.terminal() == terminal && StringUtils.notEmpty(version.value())
+                        && !SessionContextHolder.isVersion(version)) {
+                    String message = version.message();
+                    if (environment != null && StringUtils.notEmpty(message)) {
+                        message = environment.resolvePlaceholders(message);
+                    }
+                    if (StringUtils.isEmpty(message)) {
+                        message = ApplicationContextHolder.getMessage("Version.Control.Limit");
+                    }
+                    throw new ResourceUnavailableException(message);
+                }
+            }
+        }
+
+        // 终端最低版本配置校验
+        String minimum = ApplicationContextHolder.getProperty(terminal.name().toLowerCase() + ".version.minimum");
+        if (StringUtils.notEmpty(minimum) && !SessionContextHolder.isAfterVersion(terminal, minimum, true)) {
+            throw new ResourceUnavailableException(ApplicationContextHolder.getMessage("Version.Control.Limit"));
+        }
+    }
+
+    /**
+     * 接口请求日志打印
+     *
+     * @param point 接口方法拦截点
+     * @throws Throwable 接口调用异常
+     */
+    @Around("@within(org.springframework.stereotype.Controller) " +
+            "|| @within(org.springframework.web.bind.annotation.RestController)")
+    public Object logging(ProceedingJoinPoint point) throws Throwable {
+        boolean debug = this.isDebug(point);
+        if (debug) {
+            LoggingContextHolder.debug(log, point.getArgs());
+        }
+        this.checkVersion(point);
+        Object value = point.proceed();
+        if (debug) {
+            LoggingContextHolder.debug(log, value);
+        }
+        return value;
+    }
+}

+ 0 - 65
framework-base/src/main/java/com/chelvc/framework/base/interceptor/ControllerLoggingInterceptor.java

@@ -1,65 +0,0 @@
-package com.chelvc.framework.base.interceptor;
-
-import ch.qos.logback.classic.Level;
-import com.chelvc.framework.base.context.LoggingContextHolder;
-import lombok.extern.slf4j.Slf4j;
-import org.aspectj.lang.JoinPoint;
-import org.aspectj.lang.ProceedingJoinPoint;
-import org.aspectj.lang.Signature;
-import org.aspectj.lang.annotation.Around;
-import org.aspectj.lang.annotation.Aspect;
-import org.aspectj.lang.reflect.MethodSignature;
-import org.springframework.boot.web.servlet.error.ErrorController;
-import org.springframework.core.Ordered;
-import org.springframework.core.annotation.Order;
-import org.springframework.stereotype.Component;
-import org.springframework.web.bind.annotation.ExceptionHandler;
-
-/**
- * Controller接口日志拦截器
- *
- * @author Woody
- * @date 2024/1/30
- */
-@Slf4j
-@Aspect
-@Component
-@Order(Ordered.HIGHEST_PRECEDENCE)
-public class ControllerLoggingInterceptor {
-    /**
-     * 判断是否开启调试日志
-     *
-     * @param point 接口方法拦截点
-     * @return true/false
-     */
-    private boolean isDebug(JoinPoint point) {
-        Object target = point.getTarget();
-        if (target instanceof ErrorController) {
-            return false;
-        }
-        Signature signature = point.getSignature();
-        return signature instanceof MethodSignature
-                && !((MethodSignature) signature).getMethod().isAnnotationPresent(ExceptionHandler.class)
-                && LoggingContextHolder.level(signature.getDeclaringTypeName()) == Level.DEBUG;
-    }
-
-    /**
-     * 接口请求日志打印
-     *
-     * @param point 接口方法拦截点
-     * @throws Throwable 接口调用异常
-     */
-    @Around("@within(org.springframework.stereotype.Controller) " +
-            "|| @within(org.springframework.web.bind.annotation.RestController)")
-    public Object logging(ProceedingJoinPoint point) throws Throwable {
-        boolean debug = this.isDebug(point);
-        if (debug) {
-            LoggingContextHolder.debug(log, point.getArgs());
-        }
-        Object value = point.proceed();
-        if (debug) {
-            LoggingContextHolder.debug(log, value);
-        }
-        return value;
-    }
-}

+ 3 - 2
framework-feign/src/main/java/com/chelvc/framework/feign/interceptor/FeignInvokeInterceptor.java

@@ -90,7 +90,6 @@ public class FeignInvokeInterceptor implements RequestInterceptor {
         }
     }
 
-
     /**
      * 初始化请求头
      *
@@ -113,9 +112,11 @@ public class FeignInvokeInterceptor implements RequestInterceptor {
         template.header(SessionContextHolder.HEADER_TERMINAL,
                 ObjectUtils.ifNull(session.getTerminal(), Terminal::name));
         template.header(SessionContextHolder.HEADER_VERSION, session.getVersion());
-        template.header(SessionContextHolder.HEADER_AUTHORITIES, session.getAuthorities());
         template.header(SessionContextHolder.HEADER_TIMESTAMP,
                 (String) ObjectUtils.ifNull(session.getTimestamp(), String::valueOf));
+        template.header(SessionContextHolder.HEADER_REGISTERING,
+                (String) ObjectUtils.ifNull(session.getRegistering(), String::valueOf));
+        template.header(SessionContextHolder.HEADER_AUTHORITIES, session.getAuthorities());
     }
 
     @Override

+ 7 - 2
framework-security/src/main/java/com/chelvc/framework/security/context/AuthorizeContextHolder.java

@@ -38,15 +38,20 @@ public final class AuthorizeContextHolder {
     public static final String USERNAME = "user_name";
 
     /**
-     * 用户权限标识
+     * 主体创建时间戳
      */
-    public static final String AUTHORITIES = "authorities";
+    public static final String CREATING = "creating";
 
     /**
      * 主体注册时间戳
      */
     public static final String REGISTERING = "registering";
 
+    /**
+     * 用户权限标识
+     */
+    public static final String AUTHORITIES = "authorities";
+
     private AuthorizeContextHolder() {
     }
 

+ 5 - 4
framework-security/src/main/java/com/chelvc/framework/security/context/AuthorizeSessionFactory.java

@@ -20,9 +20,10 @@ import org.springframework.stereotype.Component;
 public class AuthorizeSessionFactory extends DefaultSessionFactory implements SessionFactory {
     @Override
     public Session build(@NonNull HttpServletRequest request) {
-        return Session.builder().using(Using.NORMAL).host(this.getHost(request)).device(this.getDevice(request))
-                .channel(this.getChannel(request)).platform(this.getPlatform(request))
-                .terminal(this.getTerminal(request)).version(this.getVersion(request))
-                .authorities(Collections.emptySet()).timestamp(this.getTimestamp(request)).build();
+        return Session.builder().using(Using.NORMAL).host(this.getHost(request))
+                .device(this.getDevice(request)).channel(this.getChannel(request))
+                .platform(this.getPlatform(request)).terminal(this.getTerminal(request))
+                .version(this.getVersion(request)).timestamp(this.getTimestamp(request))
+                .authorities(Collections.emptySet()).build();
     }
 }

+ 5 - 2
framework-security/src/main/java/com/chelvc/framework/security/token/RedisSessionValidator.java

@@ -2,6 +2,7 @@ package com.chelvc.framework.security.token;
 
 import java.util.Map;
 import java.util.Objects;
+import java.util.Set;
 
 import com.chelvc.framework.base.context.ApplicationContextHolder;
 import com.chelvc.framework.base.context.SessionContextHolder;
@@ -68,9 +69,11 @@ public class RedisSessionValidator extends DefaultSessionValidator {
         // 更新会话主体信息
         int interval = this.properties.getUsage().getInterval();
         String mobile = (String) context.get(AuthorizeContextHolder.MOBILE);
+        Long creating = (Long) context.get(AuthorizeContextHolder.CREATING);
         Long registering = (Long) context.get(AuthorizeContextHolder.REGISTERING);
-        Using using = Using.from(RedisUserDailyHashHolder.using(template, id), registering, interval);
-        SessionContextHolder.setSession(id, using, scope, mobile, AuthorizeContextHolder.getAuthorities(jwt));
+        Using using = Using.from(RedisUserDailyHashHolder.using(template, id), creating, interval);
+        Set<String> authorities = AuthorizeContextHolder.getAuthorities(jwt);
+        SessionContextHolder.setSession(id, using, scope, mobile, registering, authorities);
         return OAuth2TokenValidatorResult.success();
     }
 }