puzhibing
2024-08-23 3f2d9bb3cfd67d61c965c7c5345c40d3e4271a09
ruoyi-gateway/src/main/java/com/ruoyi/gateway/filter/AuthFilter.java
@@ -39,7 +39,7 @@
   // 排除过滤的 uri 地址,nacos自行添加
   @Autowired
   private IgnoreWhiteProperties ignoreWhite;
   @Autowired
   private RedisService redisService;
   
@@ -98,7 +98,7 @@
   }
   
   private Mono<Void> unauthorizedResponse(ServerWebExchange exchange, String msg) {
      log.error("[鉴权异常处理]请求路径:{}", exchange.getRequest().getPath());
      log.error("[鉴权异常处理]请求路径:{}", exchange.getRequest().getPath() + "\n" + msg);
      return ServletUtils.webFluxResponseWriter(exchange.getResponse(), msg, HttpStatus.UNAUTHORIZED);
   }
   
@@ -144,7 +144,7 @@
      if(null == cacheMap){
         cacheMap = new HashMap<>();
         cacheMap.put(url, timestamp);
         redisService.setCacheMap(client, cacheMap);
         redisService.setCacheMap(client, cacheMap, 5L);
      }else{
         Object o = cacheMap.get(url);
         if(null == o){
@@ -159,7 +159,7 @@
               cacheMap.put(url, timestamp);
            }
         }
         redisService.setCacheMap(client, cacheMap);
         redisService.setCacheMap(client, cacheMap, 5L);
      }
   }
   
@@ -179,14 +179,8 @@
      if (claims == null) {
         throw new RuntimeException("令牌已过期或验证不正确!");
      }
//      String userkey = JwtUtils.getUserKey(claims);
//      boolean islogin = redisService.hasKey(getTokenKey(userkey));
//      if (!islogin) {
//         throw new RuntimeException("登录状态已过期");
//      }
      String userid = JwtUtils.getUserId(claims);
      String username = JwtUtils.getUserName(claims);
      if (StringUtils.isEmpty(userid) || StringUtils.isEmpty(username)) {
      if (StringUtils.isEmpty(userid)) {
         throw new RuntimeException("令牌验证失败");
      }
   }