server api时间戳检查开关

This commit is contained in:
heavyrain.lee
2019-05-20 19:33:22 +08:00
parent 59add35703
commit f655f519d0
4 changed files with 19 additions and 2 deletions
@@ -26,11 +26,20 @@ import win.liyufan.im.RateLimiter;
abstract public class AdminAction extends Action {
private static String SECRET_KEY = "123456";
private static boolean NO_CHECK_TIME = false;
private final RateLimiter mLimitCounter = new RateLimiter(10, 500);
public static void setSecretKey(String secretKey) {
SECRET_KEY = secretKey;
}
public static void setNoCheckTime(String noCheckTime) {
try {
NO_CHECK_TIME = Boolean.parseBoolean(noCheckTime);
} catch (Exception e) {
}
}
@Override
public ErrorCode preAction(Request request, Response response) {
if (!mLimitCounter.isGranted("admin")) {
@@ -51,8 +60,8 @@ abstract public class AdminAction extends Action {
return ErrorCode.INVALID_PARAMETER;
}
if (System.currentTimeMillis() - ts > 2 * 60 * 60 * 1000) {
// return ErrorCode.ERROR_CODE_SIGN_EXPIRED;
if (!NO_CHECK_TIME && System.currentTimeMillis() - ts > 2 * 60 * 60 * 1000) {
return ErrorCode.ERROR_CODE_SIGN_EXPIRED;
}
String str = nonce + "|" + SECRET_KEY + "|" + timestamp;