token expire time

This commit is contained in:
imhao183
2020-03-07 15:19:50 +08:00
parent c03a6f46fb
commit 7e0f268b7c
5 changed files with 24 additions and 2 deletions
@@ -6,6 +6,7 @@ import io.moquette.spi.impl.security.AES;
public class Tokenor {
private static String KEY = "testim";
private static long expiredTime = Long.MAX_VALUE;
public static void setKey(String key) {
if (!StringUtil.isNullOrEmpty(key)) {
@@ -13,6 +14,10 @@ public class Tokenor {
}
}
public static void setExpiredTime(long expiredTime) {
Tokenor.expiredTime = expiredTime;
}
public static String getUserId(byte[] password) {
try {
String signKey =
@@ -21,8 +26,8 @@ public class Tokenor {
if (signKey.startsWith(KEY + "|")) {
signKey = signKey.substring(KEY.length() + 1);
long timestamp = Long.parseLong(signKey.substring(0, signKey.indexOf('|')));
if (System.currentTimeMillis() - timestamp > 7 * 24 * 60 *60 *1000) {
//return false;
if (expiredTime > 0 && System.currentTimeMillis() - timestamp > expiredTime) {
return null;
}
String id = signKey.substring(signKey.indexOf('|') + 1);
return id;