zhibing.pu
2024-08-24 cc788c86acd2983d791fbd3e50a9b30335b91953
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;
   
@@ -100,7 +100,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);
   }
   
@@ -146,7 +146,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){
@@ -155,13 +155,13 @@
            Long old_timestamp = Long.valueOf(o.toString());
            Long new_timestamp = Long.valueOf(timestamp);
            //两个请求时间差小于1秒,判定为重复提交
            if((new_timestamp - old_timestamp) <= 1000){
            if((new_timestamp - old_timestamp) <= 500){
               throw new RuntimeException("重复提交");
            }else{
               cacheMap.put(url, timestamp);
            }
         }
         redisService.setCacheMap(client, cacheMap);
         redisService.setCacheMap(client, cacheMap, 5L);
      }
   }
   
@@ -181,14 +181,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("令牌验证失败");
      }
   }