Merge branch 'new_3A' of axzsource.com:shanghai/axzo-framework into new_3A
This commit is contained in:
commit
ba41fd21af
@ -4,7 +4,7 @@ public class AuthConstants {
|
|||||||
private AuthConstants(){}
|
private AuthConstants(){}
|
||||||
public static final String ENV_DEV="dev";
|
public static final String ENV_DEV="dev";
|
||||||
|
|
||||||
public static final String HEADER_TOKEN = "atoken";
|
public static final String HEADER_TOKEN = "Authorization";
|
||||||
|
|
||||||
public static final String HEADER_TENANT_ID = "tenantId";
|
public static final String HEADER_TENANT_ID = "tenantId";
|
||||||
public static final String HEADER_SAAS_TENANT_ID = "saasTenantId";
|
public static final String HEADER_SAAS_TENANT_ID = "saasTenantId";
|
||||||
|
|||||||
@ -21,21 +21,21 @@ public class LegacyGuessMissedRsp {
|
|||||||
public static final String ST_NO_NEED = "__NO_NEED__";
|
public static final String ST_NO_NEED = "__NO_NEED__";
|
||||||
public static final String ST_GUESS_FAILED = "__GUESS_FAILED__";
|
public static final String ST_GUESS_FAILED = "__GUESS_FAILED__";
|
||||||
public static final String ST_GUESS_OK = "__GUESS_OK__";
|
public static final String ST_GUESS_OK = "__GUESS_OK__";
|
||||||
|
|
||||||
|
private String guessSaasTenant = ST_NO_NEED;
|
||||||
|
|
||||||
private String guessSaasTenant;
|
private Long saasTenantId = 0L;
|
||||||
|
|
||||||
private Long saasTenantId;
|
private String guessTerminal = ST_NO_NEED;
|
||||||
|
|
||||||
private String guessTerminal;
|
private String newTerminal = "";
|
||||||
|
|
||||||
|
private String guessOU = ST_NO_NEED;
|
||||||
|
|
||||||
private String newTerminal;
|
private Long ouId = 0L;
|
||||||
|
|
||||||
private String guessOU;
|
private String guessWorkspace = ST_NO_NEED;
|
||||||
|
|
||||||
private Long ouId;
|
private Long workspaceId = 0L;
|
||||||
|
|
||||||
private String guessWorkspace;
|
|
||||||
|
|
||||||
private Long workspaceId;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,7 +7,7 @@ import lombok.Getter;
|
|||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public enum EnvEnum {
|
public enum EnvEnum {
|
||||||
// dev
|
// dev
|
||||||
DEV("dev", "http://dev-app.axzo.cn/pudge/webApi/oauth/apisix/authentication"),
|
DEV("dev", "http://127.0.0.1:10099/webApi/oauth/apisix/authentication"),
|
||||||
// TEST
|
// TEST
|
||||||
TEST("TEST", "http://test-api.axzo.cn/pudge/webApi/oauth/apisix/authentication"),
|
TEST("TEST", "http://test-api.axzo.cn/pudge/webApi/oauth/apisix/authentication"),
|
||||||
//TEST1
|
//TEST1
|
||||||
|
|||||||
@ -28,11 +28,11 @@ import cn.axzo.framework.auth.domain.UserInfo;
|
|||||||
import cn.axzo.framework.auth.domain.UserInfoMap;
|
import cn.axzo.framework.auth.domain.UserInfoMap;
|
||||||
import cn.axzo.framework.auth.enums.EnvEnum;
|
import cn.axzo.framework.auth.enums.EnvEnum;
|
||||||
import cn.azxo.framework.common.logger.logback.PodNamespacePropertyDefiner;
|
import cn.azxo.framework.common.logger.logback.PodNamespacePropertyDefiner;
|
||||||
import cn.azxo.framework.common.utils.StrUtil;
|
|
||||||
import cn.hutool.core.bean.BeanUtil;
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
import cn.hutool.core.codec.Base64;
|
import cn.hutool.core.codec.Base64;
|
||||||
import cn.hutool.core.lang.TypeReference;
|
import cn.hutool.core.lang.TypeReference;
|
||||||
import cn.hutool.core.text.CharSequenceUtil;
|
import cn.hutool.core.text.CharSequenceUtil;
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
import cn.hutool.http.HttpException;
|
import cn.hutool.http.HttpException;
|
||||||
import cn.hutool.http.HttpRequest;
|
import cn.hutool.http.HttpRequest;
|
||||||
import cn.hutool.json.JSONUtil;
|
import cn.hutool.json.JSONUtil;
|
||||||
@ -104,7 +104,7 @@ public class ContextInfoBuilderAspect {
|
|||||||
ContextInfo contextInfo = new ContextInfo();
|
ContextInfo contextInfo = new ContextInfo();
|
||||||
fillContextInfoWithRequest(contextInfo, request);
|
fillContextInfoWithRequest(contextInfo, request);
|
||||||
|
|
||||||
String userinfoJson;
|
String authResultJson;
|
||||||
// 本地运行 分两种情况 postMan/junit
|
// 本地运行 分两种情况 postMan/junit
|
||||||
// 判断本地环境
|
// 判断本地环境
|
||||||
if (getSystemProperties() == null) {
|
if (getSystemProperties() == null) {
|
||||||
@ -113,17 +113,17 @@ public class ContextInfoBuilderAspect {
|
|||||||
// 硬逻辑 如果不携带token 可理解为junit测试 这里不覆盖 Userinfo的信息
|
// 硬逻辑 如果不携带token 可理解为junit测试 这里不覆盖 Userinfo的信息
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
userinfoJson = getUserInfoFromPudge(contextInfo, request);
|
authResultJson = getUserInfoFromPudge(contextInfo, request);
|
||||||
} else {
|
} else {
|
||||||
// 走 apisix 获取的请求
|
// 走 apisix 获取的请求
|
||||||
String userJsonInfo = request.getHeader(AuthConstants.USER_INFO);
|
String userJsonInfo = request.getHeader(AuthConstants.USER_INFO);
|
||||||
AuthException.error(CharSequenceUtil.isNotEmpty(userJsonInfo),
|
AuthException.error(CharSequenceUtil.isNotEmpty(userJsonInfo),
|
||||||
"do not have userinfo error , please check apisix config is correct");
|
"do not have userinfo error , please check apisix config is correct");
|
||||||
// 转编码
|
// 转编码
|
||||||
userinfoJson = Base64.decodeStr(userJsonInfo);
|
authResultJson = Base64.decodeStr(userJsonInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
buildUserInfo(contextInfo, userinfoJson);
|
buildUserInfo(contextInfo, authResultJson);
|
||||||
|
|
||||||
// 定制一些信息的处理
|
// 定制一些信息的处理
|
||||||
contextInfo.buildCustomInfoByRequest(request);
|
contextInfo.buildCustomInfoByRequest(request);
|
||||||
@ -180,7 +180,7 @@ public class ContextInfoBuilderAspect {
|
|||||||
req.setHeaderSaasTenantId(contextInfo.getSaasTenantId());
|
req.setHeaderSaasTenantId(contextInfo.getSaasTenantId());
|
||||||
req.setHeaderTenantId(contextInfo.getTenantId());
|
req.setHeaderTenantId(contextInfo.getTenantId());
|
||||||
req.setHeaderWorkspaceId(contextInfo.getWorkspaceId());
|
req.setHeaderWorkspaceId(contextInfo.getWorkspaceId());
|
||||||
req.setRequestParamProjectId(StrUtil.nullSafeParseLong(originalRequest.getParameter("projectId")));
|
req.setRequestParamProjectId(nullSafeParseLong(originalRequest.getParameter("projectId")));
|
||||||
|
|
||||||
return JSONUtil.toJsonStr(req);
|
return JSONUtil.toJsonStr(req);
|
||||||
}
|
}
|
||||||
@ -215,28 +215,34 @@ public class ContextInfoBuilderAspect {
|
|||||||
|
|
||||||
contextInfo.setToken(request.getHeader(AuthConstants.HEADER_TOKEN));
|
contextInfo.setToken(request.getHeader(AuthConstants.HEADER_TOKEN));
|
||||||
contextInfo.setTerminalInfo(new TerminalInfo(request.getHeader(AuthConstants.HEADER_TERMINAL)));
|
contextInfo.setTerminalInfo(new TerminalInfo(request.getHeader(AuthConstants.HEADER_TERMINAL)));
|
||||||
contextInfo.setTenantId(StrUtil.nullSafeParseLong(request.getHeader(AuthConstants.HEADER_TENANT_ID)));
|
contextInfo.setTenantId(nullSafeParseLong(request.getHeader(AuthConstants.HEADER_TENANT_ID)));
|
||||||
contextInfo.setSaasTenantId(StrUtil.nullSafeParseLong(request.getHeader(AuthConstants.HEADER_SAAS_TENANT_ID)));
|
contextInfo.setSaasTenantId(nullSafeParseLong(request.getHeader(AuthConstants.HEADER_SAAS_TENANT_ID)));
|
||||||
contextInfo.setOuId(StrUtil.nullSafeParseLong(request.getHeader(AuthConstants.HEADER_OU_ID)));
|
contextInfo.setOuId(nullSafeParseLong(request.getHeader(AuthConstants.HEADER_OU_ID)));
|
||||||
contextInfo.setWorkspaceId(StrUtil.nullSafeParseLong(request.getHeader(AuthConstants.HEADER_WORKSPACE_ID)));
|
contextInfo.setWorkspaceId(nullSafeParseLong(request.getHeader(AuthConstants.HEADER_WORKSPACE_ID)));
|
||||||
|
|
||||||
contextInfo.setVisitTo(request.getHeader(AuthConstants.VISIT_TO));
|
contextInfo.setVisitTo(request.getHeader(AuthConstants.VISIT_TO));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void buildUserInfo(ContextInfo contextInfo, String userJsonInfo) {
|
public void buildUserInfo(ContextInfo contextInfo, String authResultJson) {
|
||||||
|
log.info("buildUserInfo-->authResultJson:{},contextInfo:{}",authResultJson,JSONUtil.toJsonStr(contextInfo));
|
||||||
UserInfo userInfo = new UserInfo();
|
UserInfo userInfo = new UserInfo();
|
||||||
TypeReference<Map<String, Object>> mapTypeReference = new TypeReference<Map<String, Object>>() {
|
TypeReference<Map<String, Object>> mapTypeReference = new TypeReference<Map<String, Object>>() {
|
||||||
};
|
};
|
||||||
Map<String, Object> map = JSONUtil.toBean(userJsonInfo, mapTypeReference, false);
|
Map<String, Object> map = JSONUtil.toBean(authResultJson, mapTypeReference, false);
|
||||||
|
Map<String, Object> userinfoMap = JSONUtil.toBean((String) map.get("userinfo"), mapTypeReference, false);
|
||||||
|
|
||||||
// 对bean进行封装属性
|
// 对bean进行封装属性
|
||||||
BeanUtil.fillBeanWithMap(map, userInfo, false);
|
BeanUtil.fillBeanWithMap(userinfoMap, userInfo, false);
|
||||||
|
|
||||||
contextInfo.setUserInfo(userInfo);
|
contextInfo.setUserInfo(userInfo);
|
||||||
|
|
||||||
fillLegacyGuess(contextInfo, map);
|
try {
|
||||||
|
fillLegacyGuess(contextInfo, userinfoMap);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.warn("fill legacy guess error for user identityId=" + userInfo.getIdentityId(), e);
|
||||||
|
}
|
||||||
|
|
||||||
contextInfo.buildCustomInfoByUserInfo(new UserInfoMap(map));
|
contextInfo.buildCustomInfoByUserInfo(new UserInfoMap(userinfoMap));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -248,7 +254,13 @@ public class ContextInfoBuilderAspect {
|
|||||||
@Deprecated
|
@Deprecated
|
||||||
private void fillLegacyGuess(ContextInfo contextInfo, Map<String, Object> map) {
|
private void fillLegacyGuess(ContextInfo contextInfo, Map<String, Object> map) {
|
||||||
LegacyGuessMissedRsp rsp = new LegacyGuessMissedRsp();
|
LegacyGuessMissedRsp rsp = new LegacyGuessMissedRsp();
|
||||||
BeanUtil.fillBeanWithMap((Map<?, ?>) map.get(LegacyGuessMissedRsp.MAP_KEY_FOR_RSP), rsp, false);
|
Map<?, ?> legacyGuessMap = (Map<?, ?>) map.get(LegacyGuessMissedRsp.MAP_KEY_FOR_RSP);
|
||||||
|
if (legacyGuessMap == null) {
|
||||||
|
log.warn("legacy guess map is null, ignore legacy guess. user identityId=%d",
|
||||||
|
contextInfo.getUserInfo().getIdentityId());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
BeanUtil.fillBeanWithMap(legacyGuessMap, rsp, false);
|
||||||
if (LegacyGuessMissedRsp.ST_GUESS_OK.equals(rsp.getGuessSaasTenant())) {
|
if (LegacyGuessMissedRsp.ST_GUESS_OK.equals(rsp.getGuessSaasTenant())) {
|
||||||
contextInfo.setSaasTenantId(rsp.getSaasTenantId());
|
contextInfo.setSaasTenantId(rsp.getSaasTenantId());
|
||||||
}
|
}
|
||||||
@ -264,4 +276,14 @@ public class ContextInfoBuilderAspect {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Long nullSafeParseLong(String input) {
|
||||||
|
if (input == null)
|
||||||
|
return 0L;
|
||||||
|
if ("".equals(input))
|
||||||
|
return 0L;
|
||||||
|
if ("undefined".equals(input))
|
||||||
|
return 0L;
|
||||||
|
return Long.valueOf(input);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,26 +0,0 @@
|
|||||||
package cn.azxo.framework.common.utils;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* 原来的工具类名字太长了,我弄一个名字短一些的。
|
|
||||||
* 把一些原来自己方便使用的小函数写几个在这里。
|
|
||||||
*
|
|
||||||
* @author gaowei
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public abstract class StrUtil extends StringUtils {
|
|
||||||
public static String killNull(String input) {
|
|
||||||
if(input == null)
|
|
||||||
return "";
|
|
||||||
return input;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Long nullSafeParseLong(String input) {
|
|
||||||
if(input == null)
|
|
||||||
return 0L;
|
|
||||||
if("".equals(input))
|
|
||||||
return 0L;
|
|
||||||
return Long.valueOf(input);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue
Block a user