Commit 426eb3e5 by 段启岩

更新流量控制校验

parent 2fa8eecb
...@@ -17,9 +17,14 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -17,9 +17,14 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import org.springframework.web.cors.CorsUtils; import org.springframework.web.cors.CorsUtils;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import java.io.DataInputStream;
import java.io.ObjectInputStream;
import java.util.Objects;
import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.Lock;
/** /**
...@@ -95,6 +100,10 @@ public class PreventDuplicateSubmission { ...@@ -95,6 +100,10 @@ public class PreventDuplicateSubmission {
private Object process(ProceedingJoinPoint jp) throws Throwable { private Object process(ProceedingJoinPoint jp) throws Throwable {
String token = jp.getSignature().toString(); String token = jp.getSignature().toString();
token = SubjectUtils.getSubject().getIdentification() + ":" + token; token = SubjectUtils.getSubject().getIdentification() + ":" + token;
HttpServletRequest request = ((ServletRequestAttributes) (RequestContextHolder.currentRequestAttributes())).getRequest();
if (null != request) {
token += request.getRequestURI();
}
Lock lock = redisLockFactory.createLock(Md5Utils.encode(token)); Lock lock = redisLockFactory.createLock(Md5Utils.encode(token));
if (lock.tryLock()) { if (lock.tryLock()) {
try { try {
......
...@@ -29,4 +29,25 @@ public class Md5Utils { ...@@ -29,4 +29,25 @@ public class Md5Utils {
return ""; return "";
} }
} }
public static String encode(byte[] data) {
try {
MessageDigest digest = MessageDigest.getInstance("md5");
byte[] bs = digest.digest(data);
String hexString = "";
for (byte b : bs) {
int temp = b & 255;
if (temp < 16 && temp >= 0) {
hexString = hexString + "0" + Integer.toHexString(temp);
} else {
hexString = hexString + Integer.toHexString(temp);
}
}
return hexString;
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
return "";
}
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment