|
|
|
@ -1,6 +1,7 @@
|
|
|
|
|
package com.ibeetl.admin.core.util;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
|
|
import com.ibeetl.admin.core.conf.MVCConf;
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
@ -18,12 +19,14 @@ import java.net.UnknownHostException;
|
|
|
|
|
import java.util.Arrays;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.Objects;
|
|
|
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
import static cn.hutool.core.util.ObjectUtil.defaultIfBlank;
|
|
|
|
|
import static com.ibeetl.admin.core.service.CorePlatformService.LOGIN_USER_TTL;
|
|
|
|
|
import static com.ibeetl.admin.core.service.CorePlatformService.TOKEN_KEY;
|
|
|
|
|
import static com.ibeetl.admin.core.util.servlet.ServletUtils.getRequest;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -105,7 +108,7 @@ public class HttpRequestLocal {
|
|
|
|
|
if (headerToken == null) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
DefaultRedisMap<String, Object> redisMap = tokenRedisMap.get(headerToken);
|
|
|
|
|
DefaultRedisMap<String, Object> redisMap = tokenRedisMap.get(standardRedisTokenKey(headerToken));
|
|
|
|
|
if (redisMap == null) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
@ -117,7 +120,7 @@ public class HttpRequestLocal {
|
|
|
|
|
if (headerToken == null) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
DefaultRedisMap<String, Object> redisMap = tokenRedisMap.get(headerToken);
|
|
|
|
|
DefaultRedisMap<String, Object> redisMap = tokenRedisMap.get(standardRedisTokenKey(headerToken));
|
|
|
|
|
if (redisMap == null) {
|
|
|
|
|
return ;
|
|
|
|
|
}
|
|
|
|
@ -131,6 +134,12 @@ public class HttpRequestLocal {
|
|
|
|
|
* @param obj
|
|
|
|
|
*/
|
|
|
|
|
public void setSessionValueByToken(String token, String key, Object obj){
|
|
|
|
|
// token 标准化
|
|
|
|
|
token = jwtTokenSplitTimestamp(Objects.requireNonNull(token))[0];
|
|
|
|
|
// token的二次加工,用于分组
|
|
|
|
|
if (token != null) {
|
|
|
|
|
token = TOKEN_KEY + ":" + token;
|
|
|
|
|
}
|
|
|
|
|
DefaultRedisMap<String, Object> defaultRedisMap = tokenRedisMap.get(token);
|
|
|
|
|
if (defaultRedisMap == null) {
|
|
|
|
|
defaultRedisMap = new DefaultRedisMap<>(token, stringRedisTemplate);
|
|
|
|
@ -149,7 +158,7 @@ public class HttpRequestLocal {
|
|
|
|
|
if (headerToken == null) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
DefaultRedisMap<String, Object> redisMap = tokenRedisMap.get(headerToken);
|
|
|
|
|
DefaultRedisMap<String, Object> redisMap = tokenRedisMap.get(standardRedisTokenKey(headerToken));
|
|
|
|
|
if (redisMap == null) {
|
|
|
|
|
return ;
|
|
|
|
|
}
|
|
|
|
@ -164,7 +173,7 @@ public class HttpRequestLocal {
|
|
|
|
|
if (headerToken == null) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
tokenRedisMap.remove(headerToken);
|
|
|
|
|
tokenRedisMap.remove(standardRedisTokenKey(headerToken));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -197,13 +206,31 @@ public class HttpRequestLocal {
|
|
|
|
|
|
|
|
|
|
return token;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 二次加工Redis的TokenKey
|
|
|
|
|
* @param token
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public static String standardRedisTokenKey(String token) {
|
|
|
|
|
if (StrUtil.isBlank(token)) {
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (token.startsWith(TOKEN_KEY)) {
|
|
|
|
|
return token;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return TOKEN_KEY + ":" + token;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Object getAttribute(String key){
|
|
|
|
|
String headerToken = getHeaderToken();
|
|
|
|
|
if (headerToken == null) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
DefaultRedisMap<String, Object> redisMap = tokenRedisMap.get(headerToken);
|
|
|
|
|
DefaultRedisMap<String, Object> redisMap = tokenRedisMap.get(standardRedisTokenKey(headerToken));
|
|
|
|
|
if (redisMap == null) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
@ -214,7 +241,7 @@ public class HttpRequestLocal {
|
|
|
|
|
if (headerToken == null) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
DefaultRedisMap<String, Object> redisMap = tokenRedisMap.get(headerToken);
|
|
|
|
|
DefaultRedisMap<String, Object> redisMap = tokenRedisMap.get(standardRedisTokenKey(headerToken));
|
|
|
|
|
if (redisMap == null) {
|
|
|
|
|
return ;
|
|
|
|
|
}
|
|
|
|
|