fix terminal by session
This commit is contained in:
parent
644383e644
commit
6085cf9323
@ -18,6 +18,7 @@
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
||||
<maven.compiler.target>8</maven.compiler.target>
|
||||
<javax.servlet.version>4.0.1</javax.servlet.version>
|
||||
<sa-token.version>1.30.0</sa-token.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
@ -91,6 +92,12 @@
|
||||
<artifactId>transmittable-thread-local</artifactId>
|
||||
<version>2.12.6</version>
|
||||
</dependency>
|
||||
<!-- Sa-Token 权限认证, 在线文档:http://sa-token.dev33.cn/ -->
|
||||
<dependency>
|
||||
<groupId>cn.dev33</groupId>
|
||||
<artifactId>sa-token-spring-boot-starter</artifactId>
|
||||
<version>${sa-token.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
||||
@ -7,12 +7,10 @@ public class TerminalInfo {
|
||||
/**
|
||||
* TODO: 数据库迁移,terminal字符串有存到数据库里的。比如这个函数
|
||||
*
|
||||
* {@link cn.axzo.pudge.webapi.modules.panel.PanelCommonController.getBannerFromSmp(Long)}
|
||||
* {@link cn.axzo.pudge.webapi.modules.panel.PanelCommonController.getBannerFromSmp(Long)}
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 之前的CEMS、PMS合成一个,叫CMS了。
|
||||
* 现在没有PMS了。
|
||||
@ -38,11 +36,11 @@ public class TerminalInfo {
|
||||
public static final String STR_TERMINAL_CMS = "cms";
|
||||
@Deprecated
|
||||
public static final String NUM_TERMINAL_CMS = "3";
|
||||
|
||||
//调试的时候,发现有一个15,是CMS
|
||||
|
||||
// 调试的时候,发现有一个15,是CMS
|
||||
@Deprecated
|
||||
public static final String NUM15_TERMINAL_CMS = "15";
|
||||
|
||||
|
||||
/**
|
||||
* 从业人员App,企业版App
|
||||
*/
|
||||
@ -88,7 +86,7 @@ public class TerminalInfo {
|
||||
*/
|
||||
@Deprecated
|
||||
public static final String STR_TERMINAL_PROJ = "proj";
|
||||
|
||||
|
||||
/**
|
||||
* 智能面板
|
||||
*/
|
||||
@ -99,10 +97,20 @@ public class TerminalInfo {
|
||||
*/
|
||||
@Deprecated
|
||||
public static final String STR_TERMINAL_SMP = "smp";
|
||||
|
||||
|
||||
@Deprecated
|
||||
public static final String STR_TERMINAL_SCREEN = "screen";
|
||||
|
||||
/**
|
||||
* cn.axzo.pudge.server.modules.sys.enums.AppTerminalTypeEnum
|
||||
*
|
||||
* 智能面板插件
|
||||
*/
|
||||
@Deprecated
|
||||
public static final String STR_TERMINAL_PL_PREFIX = "pl-";
|
||||
|
||||
|
||||
|
||||
private static Map<String, String> aliasMap = new HashMap<String, String>();
|
||||
|
||||
/**
|
||||
@ -125,6 +133,9 @@ public class TerminalInfo {
|
||||
aliasMap.put(NUM_TERMINAL_CMS, NT_CMS_WEB_PROJ);
|
||||
aliasMap.put(NUM15_TERMINAL_CMS, NT_CMS_WEB_PROJ);
|
||||
// 实际上不应该是直接对应于PROJ,默认先对应一个,需要再guess一下,
|
||||
|
||||
aliasMap.put(STR_TERMINAL_PMS, NT_CMS_WEB_PROJ);
|
||||
aliasMap.put(NUM_TERMINAL_PMS, NT_CMS_WEB_PROJ);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -133,6 +144,8 @@ public class TerminalInfo {
|
||||
public static final String NT_CMP_APP_ENT_ZB = "NT_CMP_APP_ENT_ZB";
|
||||
static {
|
||||
aliasMap.put(NT_CMP_APP_ENT_ZB, NT_CMP_APP_ENT_ZB);
|
||||
aliasMap.put(STR_TERMINAL_CEMS, NT_CMS_WEB_PROJ);
|
||||
aliasMap.put(NUM_TERMINAL_CEMS, NT_CMS_WEB_PROJ);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -154,6 +167,7 @@ public class TerminalInfo {
|
||||
aliasMap.put(NT_CM_APP_CM_LEADER, NT_CM_APP_CM_LEADER);
|
||||
aliasMap.put(STR_TERMINAL_CM_LEADER, NT_CM_APP_CM_LEADER);
|
||||
}
|
||||
//貌似还有这么用的:TEAM(2, "cm_leader"),
|
||||
|
||||
/**
|
||||
* 安心筑App-工人
|
||||
@ -202,9 +216,9 @@ public class TerminalInfo {
|
||||
public TerminalInfo(String rawTerminalString) {
|
||||
this.rawTerminalString = rawTerminalString;
|
||||
this.newTerminalString = aliasMap.get(rawTerminalString);
|
||||
//TODO: 为了调试方便,先注释掉这两句。@gaowei
|
||||
//if (this.newTerminalString == null)
|
||||
// throw new IllegalArgumentException("无效的Terminal:" + rawTerminalString);
|
||||
// TODO: 为了调试方便,先注释掉这两句。@gaowei
|
||||
// if (this.newTerminalString == null)
|
||||
// throw new IllegalArgumentException("无效的Terminal:" + rawTerminalString);
|
||||
}
|
||||
|
||||
public TerminalInfo(String rawTerminalString, String newTerminalString) {
|
||||
@ -248,7 +262,7 @@ public class TerminalInfo {
|
||||
public boolean isCMP_APP_ENT_ZB() {
|
||||
return NT_CMP_APP_ENT_ZB.equals(newTerminalString);
|
||||
}
|
||||
|
||||
|
||||
public boolean isCMP_APP_PROJ() {
|
||||
return NT_CMP_APP_PROJ.equals(newTerminalString);
|
||||
}
|
||||
@ -261,5 +275,35 @@ public class TerminalInfo {
|
||||
return NT_CM_APP_CM_WORKER.equals(newTerminalString);
|
||||
}
|
||||
|
||||
public boolean isLegacy(String legacyTerminalString) {
|
||||
if (legacyTerminalString == null)
|
||||
return false;
|
||||
if (this.rawTerminalString.equals(legacyTerminalString))
|
||||
return true;
|
||||
TerminalInfo legacyTM = new TerminalInfo(legacyTerminalString);
|
||||
if (this.NT().equals(legacyTM.NT())) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param terminal
|
||||
* @param enums 各种历史的字符串
|
||||
* @return parse成功就返回enums里的值,否则返回原terminal string
|
||||
*/
|
||||
public static String parseLegacyTerminal(String terminal, String ... enums) {
|
||||
TerminalInfo tm = new TerminalInfo(terminal);
|
||||
for(String e : enums) {
|
||||
if(tm.isLegacy(e))
|
||||
return e;
|
||||
}
|
||||
return terminal;
|
||||
}
|
||||
|
||||
public static boolean legacyEquals(String t1, String t2) {
|
||||
TerminalInfo tm1 = new TerminalInfo(t1);
|
||||
return tm1.isLegacy(t2);
|
||||
}
|
||||
}
|
||||
|
||||
@ -28,6 +28,7 @@ import cn.axzo.framework.auth.domain.UserInfo;
|
||||
import cn.axzo.framework.auth.domain.UserInfoMap;
|
||||
import cn.axzo.framework.auth.enums.EnvEnum;
|
||||
import cn.azxo.framework.common.logger.logback.PodNamespacePropertyDefiner;
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.codec.Base64;
|
||||
import cn.hutool.core.lang.TypeReference;
|
||||
@ -218,12 +219,25 @@ public class ContextInfoBuilderAspect {
|
||||
contextInfo.setSystemAndDeviceInfo(sdInfo);
|
||||
|
||||
contextInfo.setToken(request.getHeader(AuthConstants.HEADER_TOKEN));
|
||||
contextInfo.setTerminalInfo(new TerminalInfo(request.getHeader(AuthConstants.HEADER_TERMINAL)));
|
||||
|
||||
contextInfo.setTenantId(nullSafeParseLong(request.getHeader(AuthConstants.HEADER_TENANT_ID)));
|
||||
contextInfo.setSaasTenantId(nullSafeParseLong(request.getHeader(AuthConstants.HEADER_SAAS_TENANT_ID)));
|
||||
contextInfo.setOuId(nullSafeParseLong(request.getHeader(AuthConstants.HEADER_OU_ID)));
|
||||
contextInfo.setWorkspaceId(nullSafeParseLong(request.getHeader(AuthConstants.HEADER_WORKSPACE_ID)));
|
||||
|
||||
|
||||
String terminalHeader = request.getHeader(AuthConstants.HEADER_TERMINAL);
|
||||
String terminalSession = StpUtil.getLoginDevice();
|
||||
String terminal = terminalHeader;
|
||||
if(null == terminalHeader || "".equals(terminalHeader)){
|
||||
log.warn("请求缺少terminal header,token={}。暂时使用session中的补齐terminal={}。", contextInfo.getToken(), terminalSession);
|
||||
terminal = terminalSession;
|
||||
} else if (TerminalInfo.legacyEquals(terminalHeader, terminalSession)) {
|
||||
log.warn("请求缺少terminal header与session中不一致,token={}。暂时使用request中的terminal={},session terminal={}", contextInfo.getToken(), terminalHeader, terminalSession);
|
||||
terminal = terminalSession;
|
||||
}
|
||||
contextInfo.setTerminalInfo(new TerminalInfo(terminal));
|
||||
|
||||
contextInfo.setVisitTo(request.getHeader(AuthConstants.VISIT_TO));
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user