ソースを参照

更新用户使用状态处理逻辑

woody 7 ヶ月 前
コミット
0354e675f2

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

@@ -32,6 +32,11 @@ public enum Using implements Enumerable {
      */
     NORMAL("普通请求");
 
+    /**
+     * 默认使用刷新时间间隔(15分钟)
+     */
+    public static final int DEFAULT_NEWLY_INTERVAL = 15 * 60 * 1000;
+
     /**
      * 类别描述
      */
@@ -42,18 +47,28 @@ public enum Using implements Enumerable {
     }
 
     /**
-     * 根据上次使用时间及注册时间结算使用类型
-     * <p>
-     * 如果距离上次使用时间超过15分钟我(900000毫秒)则视为重新进入系统
+     * 根据上次使用时间及注册时间计算使用类型
      *
      * @param latest      上次使用时间戳
      * @param registering 用户注册时间戳
      * @return 使用类型枚举
      */
     public static Using from(Long latest, Long registering) {
+        return from(latest, registering, DEFAULT_NEWLY_INTERVAL);
+    }
+
+    /**
+     * 根据上次使用时间及注册时间计算使用类型
+     *
+     * @param latest      上次使用时间戳
+     * @param registering 用户注册时间戳
+     * @param interval    使用刷新时间间隔(毫秒)
+     * @return 使用类型枚举
+     */
+    public static Using from(Long latest, Long registering, long interval) {
         if (latest == null) {
             return registering == null || registering < DateUtils.today().getTime() ? DAILY : INITIAL;
         }
-        return System.currentTimeMillis() - latest > 900000 ? NEWLY : NORMAL;
+        return System.currentTimeMillis() - latest > interval ? NEWLY : NORMAL;
     }
 }

+ 17 - 0
framework-security/src/main/java/com/chelvc/framework/security/config/SecurityProperties.java

@@ -3,6 +3,7 @@ package com.chelvc.framework.security.config;
 import java.util.Collections;
 import java.util.List;
 
+import com.chelvc.framework.base.context.Using;
 import lombok.Data;
 import org.springframework.boot.context.properties.ConfigurationProperties;
 import org.springframework.context.annotation.Configuration;
@@ -27,6 +28,11 @@ public class SecurityProperties {
      */
     private long duration = 60 * 1000;
 
+    /**
+     * 使用配置
+     */
+    private Usage usage = new Usage();
+
     /**
      * 忽略地址列表
      */
@@ -37,6 +43,17 @@ public class SecurityProperties {
      */
     private final Authorize authorize = new Authorize();
 
+    /**
+     * 使用配置
+     */
+    @Data
+    public static class Usage {
+        /**
+         * 使用刷新时间间隔(毫秒)
+         */
+        private int interval = Using.DEFAULT_NEWLY_INTERVAL;
+    }
+
     /**
      * 认证信息
      */

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

@@ -66,9 +66,10 @@ public class RedisSessionValidator extends DefaultSessionValidator {
         }
 
         // 更新会话主体信息
+        int interval = this.properties.getUsage().getInterval();
         String mobile = (String) context.get(AuthorizeContextHolder.MOBILE);
         Long registering = (Long) context.get(AuthorizeContextHolder.REGISTERING);
-        Using using = Using.from(RedisUserDailyHashHolder.using(template, id), registering);
+        Using using = Using.from(RedisUserDailyHashHolder.using(template, id), registering, interval);
         SessionContextHolder.setSession(id, using, scope, mobile, AuthorizeContextHolder.getAuthorities(jwt));
         return OAuth2TokenValidatorResult.success();
     }