Browse Source

只允许单个用户登录

vincent 3 years ago
parent
commit
f7f559c745

+ 3 - 2
maxkey-gateway/src/main/java/org/gateway/filter/AuthAndLogFilter.java

@@ -2,6 +2,7 @@ package org.gateway.filter;
 
 import com.alibaba.cloud.commons.lang.StringUtils;
 import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
 import com.alibaba.fastjson.serializer.SerializerFeature;
 import org.apache.http.HttpHeaders;
 import org.slf4j.Logger;
@@ -41,6 +42,7 @@ public class AuthAndLogFilter implements GlobalFilter, Ordered
             return chain.filter(exchange.mutate().build());
         }
         String token = exchange.getRequest().getHeaders().getFirst("Authorization");
+        System.out.println("Authorization is : "+ token);
         ServerHttpResponse resp = exchange.getResponse();
         if (StringUtils.isBlank(token))
         {
@@ -48,9 +50,8 @@ public class AuthAndLogFilter implements GlobalFilter, Ordered
             return denyAccess(exchange, "token不存在");
 
         }
-//        SignedJWT jwtToken = jwtLoginService.jwtTokenValidation(token);
+        // redis 连接
         RedisConnection redisConnection = redisConnectionFactory.getConnection();
-        redisConnection.setex("12122",300,"1111");
         String userInfo = (String)redisConnection.get(token);
         redisConnection.close();
         System.out.println(userInfo);

+ 8 - 0
maxkey-webs/maxkey-web-maxkey/src/main/java/org/maxkey/web/contorller/ThirdLoginController.java

@@ -1,5 +1,6 @@
 package org.maxkey.web.contorller;
 
+import com.alibaba.cloud.commons.lang.StringUtils;
 import com.alibaba.fastjson.JSON;
 import com.nimbusds.jwt.SignedJWT;
 import io.swagger.annotations.ApiOperation;
@@ -91,6 +92,13 @@ public class ThirdLoginController
             data.put("token", token);
             RedisConnection redisConnection = redisConnectionFactory.getConnection();
             // 默认 30分钟
+            // 先获取之前有没有token
+            String oldToken = redisConnection.get(userInfo.getId());
+            if(StringUtils.isNotEmpty(oldToken)){
+                redisConnection.delete(userInfo.getId());
+                redisConnection.delete(oldToken);
+            }
+            redisConnection.setex(userInfo.getId(),1800,token);
             redisConnection.setex(token,1800,JSON.toJSONString(userInfo));
             redisConnection.close();
             _logger.debug("token >>>" + token);