feat(context): context增加ouTypes和workspaceJoinTypes
This commit is contained in:
parent
0c5514889d
commit
7de71dabf0
@ -11,6 +11,8 @@ import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
* 经过auth之后,可以得到ContextInfo。
|
||||
@ -56,6 +58,8 @@ public class ContextInfo {
|
||||
* 单位类型
|
||||
*/
|
||||
private Integer ouType;
|
||||
|
||||
private List<Integer> ouTypes;
|
||||
|
||||
/**
|
||||
* 如果是企业视角,传EntId
|
||||
@ -87,6 +91,8 @@ public class ContextInfo {
|
||||
*/
|
||||
private Integer workspaceJoinType;
|
||||
|
||||
private List<Integer> workspaceJoinTypes;
|
||||
|
||||
/**
|
||||
* 模板方法,用来自定义ContextInfo。
|
||||
*
|
||||
@ -273,4 +279,20 @@ public class ContextInfo {
|
||||
public void setWorkspaceJoinType(Integer workspaceJoinType) {
|
||||
this.workspaceJoinType = workspaceJoinType;
|
||||
}
|
||||
|
||||
public List<Integer> getOuTypes() {
|
||||
return ouTypes;
|
||||
}
|
||||
|
||||
public void setOuTypes(List<Integer> ouTypes) {
|
||||
this.ouTypes = ouTypes;
|
||||
}
|
||||
|
||||
public List<Integer> getWorkspaceJoinTypes() {
|
||||
return workspaceJoinTypes;
|
||||
}
|
||||
|
||||
public void setWorkspaceJoinTypes(List<Integer> workspaceJoinTypes) {
|
||||
this.workspaceJoinTypes = workspaceJoinTypes;
|
||||
}
|
||||
}
|
||||
|
||||
@ -9,11 +9,8 @@ import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
||||
import jdk.nashorn.internal.ir.Terminal;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@ -20,10 +20,15 @@ import cn.hutool.core.lang.TypeReference;
|
||||
import cn.hutool.core.text.CharSequenceUtil;
|
||||
import cn.hutool.http.HttpException;
|
||||
import cn.hutool.http.HttpRequest;
|
||||
import cn.hutool.json.JSONArray;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@ -116,7 +121,7 @@ public class ContextInfoBuilderAspect {
|
||||
|
||||
try {
|
||||
ContextInfo contextInfo = preBuildContext.value().getDeclaredConstructor().newInstance();
|
||||
|
||||
|
||||
fillContextInfoWithRequestBeforeRemoteAuth(contextInfo, httpRequest);
|
||||
|
||||
String authResultJson = remoteAuth(httpRequest, contextInfo);
|
||||
@ -142,7 +147,7 @@ public class ContextInfoBuilderAspect {
|
||||
}
|
||||
|
||||
public Object[] parseContextInfoAndReturnArgs(HttpServletRequest request, ProceedingJoinPoint pjp,
|
||||
ContextInfo contextInfo) {
|
||||
ContextInfo contextInfo) {
|
||||
// 把ContextInfo注入到函数的入参中
|
||||
MethodSignature methodSignature = (MethodSignature) pjp.getSignature();
|
||||
Method method = methodSignature.getMethod();
|
||||
@ -210,7 +215,7 @@ public class ContextInfoBuilderAspect {
|
||||
|
||||
/**
|
||||
* 这个函数基本上都是在本地调试的时候才会走到,如果是apisix网关,不会走这个函数。
|
||||
*
|
||||
*
|
||||
* @param contextInfo
|
||||
* @param originalRequest
|
||||
* @return
|
||||
@ -272,14 +277,14 @@ public class ContextInfoBuilderAspect {
|
||||
|
||||
/**
|
||||
* 期待着前端上线之后,header都补齐,这些代码可以全都删掉
|
||||
*
|
||||
*
|
||||
* @param contextInfo
|
||||
* @param originalRequest
|
||||
* @return
|
||||
*/
|
||||
@Deprecated
|
||||
private String buildLegacyGuessMissedReqStringForRemoteAuth(ContextInfo contextInfo,
|
||||
HttpServletRequest originalRequest) {
|
||||
HttpServletRequest originalRequest) {
|
||||
LegacyGuessMissedReq req = new LegacyGuessMissedReq();
|
||||
req.setOriginalUrl(originalRequest.getRequestURI());
|
||||
req.setHeaderOuId(contextInfo.getOuId());
|
||||
@ -304,39 +309,45 @@ public class ContextInfoBuilderAspect {
|
||||
BeanUtil.fillBeanWithMap(userinfoMap, userInfo, false);
|
||||
|
||||
contextInfo.setUserInfo(userInfo);
|
||||
try {
|
||||
if(userinfoMap.containsKey("ouType"))
|
||||
contextInfo.setOuType(Integer.parseInt(userinfoMap.get("ouType").toString()));
|
||||
} catch (Throwable t) {
|
||||
log.warn("fill ouType error, user identityId=" + userInfo.getIdentityId());
|
||||
}
|
||||
try {
|
||||
contextInfo.setWorkspaceType(Integer.parseInt(userinfoMap.get("workspaceType").toString()));
|
||||
}catch (Throwable t) {
|
||||
log.warn("fill workspaceType error, user identityId=" + userInfo.getIdentityId());
|
||||
}
|
||||
try {
|
||||
contextInfo.setWorkspaceJoinType(Integer.parseInt(userinfoMap.get("workspaceJoinType").toString()));
|
||||
}catch (Throwable t) {
|
||||
log.warn("fill workspaceJoinType error, user identityId=" + userInfo.getIdentityId());
|
||||
}
|
||||
|
||||
try {
|
||||
fillOUWorkspaceType(contextInfo, userinfoMap);
|
||||
fillLegacyGuess(contextInfo, userinfoMap);
|
||||
contextInfo.getSystemAndDeviceInfo().setLoginDevice(contextInfo.getTerminalInfo().getSimpleTerminal());
|
||||
// loginDevice 字段已经被消费了所以这里需要新创建一个字段 用来设置登录端
|
||||
contextInfo.getSystemAndDeviceInfo().setDevice((String) userinfoMap.get("loginDevice"));
|
||||
} catch (Exception e) {
|
||||
log.warn("fill legacy guess error for user identityId=" + userInfo.getIdentityId(), e);
|
||||
log.warn("fill contextInfo error for user identityId=" + userInfo.getIdentityId(), e);
|
||||
}
|
||||
|
||||
|
||||
|
||||
contextInfo.setUserInfoMap(new UserInfoMap(userinfoMap));
|
||||
}
|
||||
|
||||
private void fillOUWorkspaceType(ContextInfo contextInfo, Map<String, Object> userinfoMap) {
|
||||
try {
|
||||
//ouType和ouTypes
|
||||
contextInfo.setOuType(Integer.parseInt(userinfoMap.getOrDefault("ouType", "0").toString()));
|
||||
Object ouTypes = userinfoMap.get("ouTypes");
|
||||
if (ouTypes instanceof JSONArray) {
|
||||
contextInfo.setOuTypes(((JSONArray) ouTypes).toList(Integer.class));
|
||||
}
|
||||
//workspaceJoinType和 workspaceJoinTypes;
|
||||
contextInfo.setWorkspaceType(Integer.parseInt(userinfoMap.getOrDefault("workspaceType", "0").toString()));
|
||||
Object workspaceTypes = userinfoMap.get("workspaceTypes");
|
||||
if (workspaceTypes instanceof JSONArray) {
|
||||
contextInfo.setWorkspaceJoinTypes(((JSONArray) workspaceTypes).toList(Integer.class));
|
||||
}
|
||||
contextInfo.setWorkspaceJoinType(Integer.parseInt(userinfoMap.get("workspaceJoinType").toString()));
|
||||
|
||||
} catch (Throwable t) {
|
||||
log.warn("fill ouType/workspace join type error", t);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 期待着前端上线之后,header都补齐,这些代码可以全都删掉
|
||||
*
|
||||
*
|
||||
* @param contextInfo
|
||||
* @param map 整个userInfoMap,里面放着一个legacy guess的结果
|
||||
*/
|
||||
|
||||
Loading…
Reference in New Issue
Block a user