|
@@ -1,10 +1,13 @@
|
|
|
package com.uas.eis.core;
|
|
package com.uas.eis.core;
|
|
|
|
|
|
|
|
|
|
+import org.slf4j.Logger;
|
|
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
|
|
+
|
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
|
import java.util.concurrent.locks.ReentrantLock;
|
|
import java.util.concurrent.locks.ReentrantLock;
|
|
|
|
|
|
|
|
public class SSOTokenManager {
|
|
public class SSOTokenManager {
|
|
|
-
|
|
|
|
|
|
|
+ private static final Logger logger = LoggerFactory.getLogger(SSOTokenManager.class);
|
|
|
// 线程安全的token缓存: key=用户名, value=TokenInfo
|
|
// 线程安全的token缓存: key=用户名, value=TokenInfo
|
|
|
private static final ConcurrentHashMap<String, TokenInfo> tokenCache = new ConcurrentHashMap<>();
|
|
private static final ConcurrentHashMap<String, TokenInfo> tokenCache = new ConcurrentHashMap<>();
|
|
|
private static final ReentrantLock lock = new ReentrantLock();
|
|
private static final ReentrantLock lock = new ReentrantLock();
|
|
@@ -23,13 +26,14 @@ public class SSOTokenManager {
|
|
|
if (tokenInfo == null || tokenInfo.expirationTime-60*5*1000 < System.currentTimeMillis()) {
|
|
if (tokenInfo == null || tokenInfo.expirationTime-60*5*1000 < System.currentTimeMillis()) {
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
|
|
|
+ logger.info("获取缓存token,token:{},过期时间:{}",tokenInfo.token,tokenInfo.expirationTime);
|
|
|
return tokenInfo.token;
|
|
return tokenInfo.token;
|
|
|
}
|
|
}
|
|
|
public static void setSsoAuthToken(String ssoAuth, String token, long expirationTime) {
|
|
public static void setSsoAuthToken(String ssoAuth, String token, long expirationTime) {
|
|
|
TokenInfo tokenInfo = new TokenInfo();
|
|
TokenInfo tokenInfo = new TokenInfo();
|
|
|
tokenInfo.token = token;
|
|
tokenInfo.token = token;
|
|
|
tokenInfo.expirationTime = expirationTime;
|
|
tokenInfo.expirationTime = expirationTime;
|
|
|
- System.out.println(System.currentTimeMillis()+"过期时间"+expirationTime);
|
|
|
|
|
|
|
+ logger.info("设置token,token:{},过期时间:{}",token,expirationTime);
|
|
|
lock.lock();
|
|
lock.lock();
|
|
|
try {
|
|
try {
|
|
|
tokenCache.put(ssoAuth, tokenInfo);
|
|
tokenCache.put(ssoAuth, tokenInfo);
|