From cc788c86acd2983d791fbd3e50a9b30335b91953 Mon Sep 17 00:00:00 2001 From: zhibing.pu <393733352@qq.com> Date: 星期六, 24 八月 2024 15:35:19 +0800 Subject: [PATCH] Merge branch 'master' of http://120.76.84.145:10101/gitblit/r/java/mx_charging_pile --- ruoyi-gateway/src/main/java/com/ruoyi/gateway/filter/AuthFilter.java | 18 ++++++------------ 1 files changed, 6 insertions(+), 12 deletions(-) diff --git a/ruoyi-gateway/src/main/java/com/ruoyi/gateway/filter/AuthFilter.java b/ruoyi-gateway/src/main/java/com/ruoyi/gateway/filter/AuthFilter.java index 0ec1a71..6aa40ff 100644 --- a/ruoyi-gateway/src/main/java/com/ruoyi/gateway/filter/AuthFilter.java +++ b/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("令牌验证失败"); } } -- Gitblit v1.7.1