puzhibing
2024-09-24 54b50b89b9f083a892e954a8401a7203af87d4a2
ruoyi-gateway/src/main/java/com/ruoyi/gateway/filter/AuthFilter.java
@@ -1,5 +1,6 @@
package com.ruoyi.gateway.filter;
import com.ruoyi.gateway.config.properties.AntiShakeProperties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@@ -39,9 +40,12 @@
   // 排除过滤的 uri 地址,nacos自行添加
   @Autowired
   private IgnoreWhiteProperties ignoreWhite;
   @Autowired
   private AntiShakeProperties antiShakeProperties;
   @Autowired
   private RedisService redisService;
   
   
   
@@ -59,7 +63,7 @@
      try {
         antiShake(request);
      }catch (Exception e){
         log.error("[重复提交]请求路径:{}", exchange.getRequest().getPath());
         log.error(e.getMessage());
         return ServletUtils.webFluxResponseWriter(exchange.getResponse(), e.getMessage(), HttpStatus.SUCCESS);
      }
      
@@ -129,7 +133,7 @@
    */
   public void antiShake(ServerHttpRequest request) throws Exception{
      HttpMethod method = request.getMethod();
      if(HttpMethod.OPTIONS == method){
      if(HttpMethod.OPTIONS == method || !antiShakeProperties.getEnable()){
         return;
      }
      HttpHeaders headers = request.getHeaders();
@@ -155,8 +159,8 @@
            Long old_timestamp = Long.valueOf(o.toString());
            Long new_timestamp = Long.valueOf(timestamp);
            //两个请求时间差小于1秒,判定为重复提交
            if((new_timestamp - old_timestamp) <= 500){
               throw new RuntimeException("重复提交");
            if((new_timestamp - old_timestamp) <= antiShakeProperties.getInterval()){
               throw new RuntimeException(url + "----->重复提交");
            }else{
               cacheMap.put(url, timestamp);
            }