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;
@@ -100,6 +100,8 @@ public final class BrokerConstants {
public static final String HZ_Cluster_Node_External_Short_Port = "node_external_short_port";
public static final String HZ_Cluster_Node_ID = "node_id";
public static final String HTTP_SERVER_SECRET_KEY = "http.admin.secret_key";
public static final String HTTP_SERVER_API_NO_CHECK_TIME = "http.admin.no_check_time";
public static final String CLIENT_PROTO_SECRET_KEY = "client.proto.secret_key";
public static final String TOKEN_SECRET_KEY = "token.key ";
@@ -112,6 +112,8 @@ public class Server {
int httpAdminPort = Integer.parseInt(config.getProperty(BrokerConstants.HTTP_ADMIN_PORT));
AdminAction.setSecretKey(config.getProperty(HTTP_SERVER_SECRET_KEY));
AdminAction.setNoCheckTime(config.getProperty(HTTP_SERVER_API_NO_CHECK_TIME));
final LoServer httpServer = new LoServer(httpLocalPort, httpAdminPort, instance.m_processor.getMessagesStore(), instance.m_store.sessionsStore());
try {
httpServer.start();