1.fix checkRequestFrequency leak

main
Gary 11 months ago
parent 8fe93a9d05
commit 16372254d2

@ -85,15 +85,17 @@ public class OperationAspect {
} }
private void checkRequestFrequency(String fullMethodName, RequestFrequencyTypeEnum frequencyTyp, Integer threshold) { private void checkRequestFrequency(String fullMethodName, RequestFrequencyTypeEnum frequencyTyp, Integer threshold) {
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
String ip = getIpAddr(request); String redisKey = fullMethodName + getKey(request);
ip = ip.replace(":", "");
String redisKey = fullMethodName + ip;
Object count=redisUtils.get(redisKey); Object count=redisUtils.get(redisKey);
Integer cuCount= null==count?0:Integer.valueOf((String)count); Integer cuCount= null==count?0:Integer.valueOf((String)count);
if (cuCount != null && cuCount > threshold - 1) { if (cuCount != null && cuCount > threshold - 1) {
throw new BizException(StatusCode.REQUEST_TOO_FREQUENCY); throw new BizException(StatusCode.REQUEST_TOO_FREQUENCY);
} }
redisUtils.increment(redisKey, 1, frequencyTyp.getSeconds()); redisUtils.increment(redisKey, 1, frequencyTyp.getSeconds());
}
private String getKey(HttpServletRequest request) {
String mobile = request.getParameter("mobile");
return StringTools.isEmpty(mobile)?getIpAddr(request).replace(":", ""): mobile;
} }
private void checkAppUserLogin() { private void checkAppUserLogin() {
UserLoginDto userLoginDto = getUserLoginDtoFromToken(); UserLoginDto userLoginDto = getUserLoginDtoFromToken();

Loading…
Cancel
Save