Selaa lähdekoodia

修复使用类别初始化问题

woody 11 kuukautta sitten
vanhempi
commit
589d43be84

+ 4 - 8
framework-base/src/main/java/com/chelvc/framework/base/context/DefaultSessionFactory.java

@@ -9,6 +9,7 @@ import javax.servlet.http.HttpServletRequest;
 import com.chelvc.framework.base.util.HttpUtils;
 import com.chelvc.framework.common.model.Platform;
 import com.chelvc.framework.common.model.Terminal;
+import com.chelvc.framework.common.util.ObjectUtils;
 import com.chelvc.framework.common.util.StringUtils;
 import com.google.common.collect.Sets;
 import lombok.NonNull;
@@ -37,19 +38,14 @@ public class DefaultSessionFactory implements SessionFactory {
         return null;
     }
 
-    /**
-     * 获取使用类别
-     *
-     * @param request Http请求对象
-     * @return 使用类别
-     */
     protected Using getUsing(@NonNull HttpServletRequest request) {
+        Using using = null;
         try {
-            return StringUtils.ifEmpty(request.getHeader(SessionContextHolder.HEADER_USING), Using::valueOf);
+            using = StringUtils.ifEmpty(request.getHeader(SessionContextHolder.HEADER_USING), Using::valueOf);
         } catch (Exception e) {
             log.warn("Using convert failed: {}", e.getMessage());
         }
-        return null;
+        return ObjectUtils.ifNull(using, Using.NORMAL);
     }
 
     /**

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

@@ -244,7 +244,7 @@ public class SessionContextHolder implements ServletRequestListener {
             if (session != null) {
                 deque.poll();
             }
-            session = Session.builder().id(id).scope(scope).anonymous(anonymous)
+            session = Session.builder().id(id).using(using).scope(scope).anonymous(anonymous)
                     .authorities(Collections.unmodifiableSet(authorities))
                     .timestamp(System.currentTimeMillis()).build();
             deque.push(session);

+ 3 - 2
framework-oauth/src/main/java/com/chelvc/framework/oauth/token/RedisSessionValidator.java

@@ -76,9 +76,10 @@ public class RedisSessionValidator implements SessionValidator {
         }
 
         // 更新会话主体信息
+        Long registering = ObjectUtils.get(values, 2);
         long usage = RedisUserDailyHashHolder.increment(template, id, "usage");
-        long registering = ObjectUtils.ifNull(ObjectUtils.get(values, 2), 0L);
-        Using using = usage > 1 ? Using.NORMAL : registering >= DateUtils.today().getTime() ? Using.NEWLY : Using.DAILY;
+        Using using = usage > 1 || registering == null ? Using.NORMAL :
+                registering >= DateUtils.today().getTime() ? Using.NEWLY : Using.DAILY;
         SessionContextHolder.setSession(
                 id, using, scope,
                 OAuthContextHolder.isAnonymous(jwt),