放开校验
This commit is contained in:
parent
9f88726dde
commit
bb386d0f54
|
|
@ -40,29 +40,31 @@ public class RateLimitAspect {
|
||||||
|
|
||||||
@Around("serviceLimit()")
|
@Around("serviceLimit()")
|
||||||
public Object around(ProceedingJoinPoint point) throws Throwable {
|
public Object around(ProceedingJoinPoint point) throws Throwable {
|
||||||
// 获取当前请求
|
// 成功获取许可,继续执行方法
|
||||||
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
|
return point.proceed();
|
||||||
HttpServletRequest request = attributes.getRequest();
|
//// 获取当前请求
|
||||||
// 获取请求的 IP 地址
|
//ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
|
||||||
String ip = IPUtils.getIpAddr(request);
|
//HttpServletRequest request = attributes.getRequest();
|
||||||
|
//// 获取请求的 IP 地址
|
||||||
// 获取方法上的 @AccessLimit 注解
|
//String ip = IPUtils.getIpAddr(request);
|
||||||
MethodSignature signature = (MethodSignature) point.getSignature();
|
//
|
||||||
Method method = signature.getMethod();
|
//// 获取方法上的 @AccessLimit 注解
|
||||||
Limiting accessLimit = method.getAnnotation(Limiting.class);
|
//MethodSignature signature = (MethodSignature) point.getSignature();
|
||||||
double permitsPerSecond = accessLimit.limitNum();
|
//Method method = signature.getMethod();
|
||||||
|
//Limiting accessLimit = method.getAnnotation(Limiting.class);
|
||||||
// 获取或创建该 IP 对应的 RateLimiter
|
//double permitsPerSecond = accessLimit.limitNum();
|
||||||
RateLimiter rateLimiter = RATE_LIMITER.computeIfAbsent(ip, k -> RateLimiter.create(permitsPerSecond));
|
//
|
||||||
|
//// 获取或创建该 IP 对应的 RateLimiter
|
||||||
// 尝试获取许可
|
//RateLimiter rateLimiter = RATE_LIMITER.computeIfAbsent(ip, k -> RateLimiter.create(permitsPerSecond));
|
||||||
if (rateLimiter.tryAcquire()) {
|
//
|
||||||
// 成功获取许可,继续执行方法
|
//// 尝试获取许可
|
||||||
return point.proceed();
|
//if (rateLimiter.tryAcquire()) {
|
||||||
} else {
|
// // 成功获取许可,继续执行方法
|
||||||
// 未获取到许可,抛出异常或返回错误信息
|
// return point.proceed();
|
||||||
log.info("IP: {} 请求方法: {} 超过访问频率限制", ip, method.getName());
|
//} else {
|
||||||
throw new LimitException("访问频率过高,请稍后再试");
|
// // 未获取到许可,抛出异常或返回错误信息
|
||||||
}
|
// log.info("IP: {} 请求方法: {} 超过访问频率限制", ip, method.getName());
|
||||||
|
// throw new LimitException("访问频率过高,请稍后再试");
|
||||||
|
//}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue