| | |
| | | // 排除过滤的 uri 地址,nacos自行添加 |
| | | @Autowired |
| | | private IgnoreWhiteProperties ignoreWhite; |
| | | |
| | | |
| | | @Autowired |
| | | private RedisService redisService; |
| | | |
| | |
| | | } |
| | | |
| | | 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); |
| | | } |
| | | |
| | |
| | | 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){ |
| | |
| | | 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); |
| | | } |
| | | } |
| | | |
| | |
| | | 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("令牌验证失败"); |
| | | } |
| | | } |