From f471cb83fc9d2e098cf940a912421e3534e18d29 Mon Sep 17 00:00:00 2001 From: "1437892690@qq.com" <1437892690@qq.com> Date: Mon, 2 Sep 2024 15:12:16 +0800 Subject: [PATCH 1/6] =?UTF-8?q?[=E5=8A=9F=E8=83=BD]=20=E5=90=8E=E7=AB=AF-?= =?UTF-8?q?=E5=BA=9F=E5=BC=83public=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 关联 #[1234808854773760]后端-废弃public接口 http://192.168.0.96:8090/demo/rdm.html#/task-detail/939050947543040/939050947543050/1234808854773760 --- .../dto/AuthenticationInfoVo.java | 124 +++++++++++++ .../neatlogic/autoexecrunner/dto/JwtVo.java | 168 ++++++++++++++++++ .../neatlogic/autoexecrunner/dto/UserVo.java | 23 ++- 3 files changed, 314 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/neatlogic/autoexecrunner/dto/AuthenticationInfoVo.java create mode 100644 src/main/java/com/neatlogic/autoexecrunner/dto/JwtVo.java diff --git a/src/main/java/com/neatlogic/autoexecrunner/dto/AuthenticationInfoVo.java b/src/main/java/com/neatlogic/autoexecrunner/dto/AuthenticationInfoVo.java new file mode 100644 index 0000000..ebb87f1 --- /dev/null +++ b/src/main/java/com/neatlogic/autoexecrunner/dto/AuthenticationInfoVo.java @@ -0,0 +1,124 @@ +/*Copyright (C) 2024 深圳极向量科技有限公司 All Rights Reserved. + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see .*/ + +package com.neatlogic.autoexecrunner.dto; + +import com.alibaba.fastjson.JSONObject; +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.collections4.MapUtils; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +public class AuthenticationInfoVo { + private String userUuid; + private final List userUuidList = new ArrayList<>(); + private final List teamUuidList = new ArrayList<>(); + private final List roleUuidList = new ArrayList<>(); + private Set headerSet = new HashSet<>(); //使用到的header + private JSONObject originHeader = new JSONObject(); //原始请求的header + + + public boolean validUser(List userUuidList) { + return userUuidList.contains(userUuid); + } + + public boolean validTeam(List pTeamUuidList) { + if (CollectionUtils.isNotEmpty(pTeamUuidList)) { + for (String teamUuid : pTeamUuidList) { + if (teamUuidList.stream().anyMatch(d -> d.equals(teamUuid))) { + return true; + } + } + } + return false; + } + + public boolean validRole(List pRoleUuidList) { + if (CollectionUtils.isNotEmpty(pRoleUuidList)) { + for (String roleUuid : pRoleUuidList) { + if (roleUuidList.stream().anyMatch(d -> d.equals(roleUuid))) { + return true; + } + } + } + return false; + } + + public AuthenticationInfoVo() { + + } + + public AuthenticationInfoVo(String userUuid) { + this.userUuid = userUuid; + } + + public AuthenticationInfoVo(String userUuid, List teamUuidList, List roleUuidList, Set headerSet, JSONObject originHeader) { + this.userUuid = userUuid; + this.teamUuidList.addAll(teamUuidList); + this.roleUuidList.addAll(roleUuidList); + this.headerSet.addAll(headerSet); + this.originHeader = originHeader; + } + + public AuthenticationInfoVo(List userUuidList, List teamUuidList, List roleUuidList, Set headerSet) { + this.userUuidList.addAll(userUuidList); + this.teamUuidList.addAll(teamUuidList); + this.roleUuidList.addAll(roleUuidList); + this.headerSet.addAll(headerSet); + } + + public String getUserUuid() { + return userUuid; + } + + public void setUserUuid(String userUuid) { + this.userUuid = userUuid; + } + + public List getUserUuidList() { + return userUuidList; + } + + public List getTeamUuidList() { + return teamUuidList; + } + + public List getRoleUuidList() { + return roleUuidList; + } + + public Set getHeaderSet() { + return headerSet; + } + + public void setHeaderSet(Set headerSet) { + this.headerSet = headerSet; + } + + public JSONObject getOriginHeader() { + return originHeader; + } + + public void setOriginHeader(JSONObject originHeader) { + this.originHeader = originHeader; + } + + public boolean isNotNull() { + return CollectionUtils.isNotEmpty(userUuidList) || CollectionUtils.isNotEmpty(teamUuidList) || CollectionUtils.isNotEmpty(roleUuidList) || MapUtils.isNotEmpty(originHeader) || CollectionUtils.isNotEmpty(headerSet); + } +} diff --git a/src/main/java/com/neatlogic/autoexecrunner/dto/JwtVo.java b/src/main/java/com/neatlogic/autoexecrunner/dto/JwtVo.java new file mode 100644 index 0000000..ff342f1 --- /dev/null +++ b/src/main/java/com/neatlogic/autoexecrunner/dto/JwtVo.java @@ -0,0 +1,168 @@ +package com.neatlogic.autoexecrunner.dto; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.neatlogic.autoexecrunner.constvalue.ApiParamType; +import com.neatlogic.autoexecrunner.restful.annotation.EntityField; +import org.apache.commons.lang3.StringUtils; + +import java.io.Serializable; +import java.nio.charset.StandardCharsets; +import java.util.Base64; + +public class JwtVo implements Serializable { + private String cc; + private String jwthead; + private String jwtbody; + private String jwtsign; + @EntityField(name = "创建时间", type = ApiParamType.STRING) + private Long tokenCreateTime; + + @EntityField(name = "是否校验tokenCreateTime", type = ApiParamType.STRING) + private boolean isValidTokenCreateTime = true; + + @EntityField(name = "token", type = ApiParamType.STRING) + private String token; + + @EntityField(name = "token哈希", type = ApiParamType.STRING) + private String tokenHash; + + @EntityField(name = "登录认证 请求headers", type = ApiParamType.STRING) + JSONObject headers = new JSONObject(); + + public JwtVo() { + + } + + public JwtVo(UserVo checkUserVo, Long tokenCreateTime, AuthenticationInfoVo authenticationInfoVo) { + JSONObject jwtBodyObj = new JSONObject(); + jwtBodyObj.put("useruuid", checkUserVo.getUuid()); + jwtBodyObj.put("userid", checkUserVo.getUserId()); + jwtBodyObj.put("username", checkUserVo.getUserName()); + jwtBodyObj.put("tenant", checkUserVo.getTenant()); + jwtBodyObj.put("isSuperAdmin", checkUserVo.getIsSuperAdmin()); + jwtBodyObj.put("createTime", tokenCreateTime); +// if (RequestContext.get() != null && RequestContext.get().getRequest() != null) { +// JSONObject headers = new JSONObject(); +// //补充设备header,防止移动端和pc端session互相影响 +// String deviceHeader = RequestContext.get().getRequest().getHeader("Device"); +// if(StringUtils.isNotBlank(deviceHeader)){ +// headers.put("Device", deviceHeader); +// } +// if (CollectionUtils.isNotEmpty(authenticationInfoVo.getHeaderSet())) { +// for (String header : authenticationInfoVo.getHeaderSet()) { +// String value = RequestContext.get().getRequest().getHeader(header); +// if(value != null) { +// headers.put(header, value); +// } +// } +// } +// if (MapUtils.isNotEmpty(headers)) { +// jwtBodyObj.put("headers", headers.toString()); +// } +// this.headers = headers; +// } + this.setTokenCreateTime(tokenCreateTime); + jwtbody = Base64.getUrlEncoder().encodeToString(jwtBodyObj.toJSONString().getBytes()); + } + + public JwtVo(String[] jwtParts) { + this.jwthead = jwtParts[0]; + this.jwtbody = jwtParts[1]; + this.jwtsign = jwtParts[2]; + } + + public String getCc() { + return cc; + } + + public void setCc(String cc) { + this.cc = cc; + } + + public String getJwthead() { + if (StringUtils.isBlank(jwthead)) { + JSONObject jwtHeadObj = new JSONObject(); + jwtHeadObj.put("alg", "HS256"); + jwtHeadObj.put("typ", "JWT"); + jwthead = Base64.getUrlEncoder().encodeToString(jwtHeadObj.toJSONString().getBytes()); + } + return jwthead; + } + + public String getJwtbody() { + return jwtbody; + } + + public void setJwthead(String jwthead) { + this.jwthead = jwthead; + } + + public void setJwtbody(String jwtbody) { + this.jwtbody = jwtbody; + } + + public String getJwtsign() { + return jwtsign; + } + + public void setJwtsign(String jwtsign) { + this.jwtsign = jwtsign; + } + + public Long getTokenCreateTime() { + return tokenCreateTime; + } + + public void setTokenCreateTime(Long tokenCreateTime) { + this.tokenCreateTime = tokenCreateTime; + } + +// public String getTokenHash() { +// if (StringUtils.isBlank(tokenHash)) { +// tokenHash = Md5Util.encryptMD5(getToken()); +// } +// return tokenHash; +// } + + public String getToken() { + if (StringUtils.isBlank(token)) { + String jwtBody = new String(Base64.getUrlDecoder().decode(getJwtbody()), StandardCharsets.UTF_8); + JSONObject jwtBodyObj = JSON.parseObject(jwtBody); + JSONObject tokenJson = new JSONObject(); + tokenJson.put("tenant", jwtBodyObj.getString("tenant")); + tokenJson.put("useruuid", jwtBodyObj.getString("useruuid")); + if (jwtBodyObj.containsKey("headers")) { + tokenJson.put("headers", jwtBodyObj.getString("headers")); + } + token = tokenJson.toJSONString(); + } + return token; + } + +// public void setValidTokenCreateTime(boolean validTokenCreateTime) { +// isValidTokenCreateTime = validTokenCreateTime; +// } +// +// public boolean isNotValidTokenCreateTime() { +// return Config.ENABLE_NO_SECRET() || !Config.ENABLE_VALID_TOKEN_FCD() || !isValidTokenCreateTime; +// +// } + +// public boolean validTokenCreateTime(Long userSessionTokenCreateTime) { +// if (isNotValidTokenCreateTime()) { +// return true; +// } +// return Objects.equals(userSessionTokenCreateTime, getTokenCreateTime()); +// } +// +// +// public JSONObject getHeaders() { +// if (MapUtils.isEmpty(headers) && StringUtils.isNotBlank(jwtbody)) { +// String jwtBody = new String(Base64.getUrlDecoder().decode(jwtbody), StandardCharsets.UTF_8); +// JSONObject jwtBodyObj = JSONObject.parseObject(jwtBody); +// return jwtBodyObj.getJSONObject("headers"); +// } +// return headers; +// } +} diff --git a/src/main/java/com/neatlogic/autoexecrunner/dto/UserVo.java b/src/main/java/com/neatlogic/autoexecrunner/dto/UserVo.java index 763a77c..2b335a3 100755 --- a/src/main/java/com/neatlogic/autoexecrunner/dto/UserVo.java +++ b/src/main/java/com/neatlogic/autoexecrunner/dto/UserVo.java @@ -71,6 +71,13 @@ public class UserVo implements Serializable { @JSONField(serialize=false) private String authorization; + @EntityField(name = "是否超级管理员", type = ApiParamType.BOOLEAN) + private Boolean isSuperAdmin; + + @JSONField(serialize = false) + @EntityField(name = "jwtVo", type = ApiParamType.BOOLEAN) + private JwtVo jwtVo; + public UserVo() { } @@ -343,5 +350,19 @@ public class UserVo implements Serializable { this.authorization = authorization; } - + public Boolean getIsSuperAdmin() { + return isSuperAdmin; + } + + public void setIsSuperAdmin(Boolean superAdmin) { + isSuperAdmin = superAdmin; + } + + public JwtVo getJwtVo() { + return jwtVo; + } + + public void setJwtVo(JwtVo jwtVo) { + this.jwtVo = jwtVo; + } } -- Gitee From 18ff0899649c2aedd6dd4c8a22bbdb8ea27b09b3 Mon Sep 17 00:00:00 2001 From: "1437892690@qq.com" <1437892690@qq.com> Date: Mon, 2 Sep 2024 15:14:08 +0800 Subject: [PATCH 2/6] =?UTF-8?q?[=E5=8A=9F=E8=83=BD]=20=E5=90=8E=E7=AB=AF-?= =?UTF-8?q?=E5=BA=9F=E5=BC=83public=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 关联 #[1234808854773760]后端-废弃public接口 http://192.168.0.96:8090/demo/rdm.html#/task-detail/939050947543040/939050947543050/1234808854773760 --- .../filter/core/LoginAuthHandlerBase.java | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/src/main/java/com/neatlogic/autoexecrunner/filter/core/LoginAuthHandlerBase.java b/src/main/java/com/neatlogic/autoexecrunner/filter/core/LoginAuthHandlerBase.java index 1f94707..1102a4c 100755 --- a/src/main/java/com/neatlogic/autoexecrunner/filter/core/LoginAuthHandlerBase.java +++ b/src/main/java/com/neatlogic/autoexecrunner/filter/core/LoginAuthHandlerBase.java @@ -1,15 +1,23 @@ package com.neatlogic.autoexecrunner.filter.core; +import com.neatlogic.autoexecrunner.common.config.Config; +import com.neatlogic.autoexecrunner.dto.AuthenticationInfoVo; +import com.neatlogic.autoexecrunner.dto.JwtVo; import com.neatlogic.autoexecrunner.dto.UserVo; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.context.annotation.DependsOn; +import javax.crypto.Mac; +import javax.crypto.spec.SecretKeySpec; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import java.io.ByteArrayOutputStream; import java.io.IOException; +import java.util.Base64; +import java.util.zip.GZIPOutputStream; @DependsOn("loginService") public abstract class LoginAuthHandlerBase implements ILoginAuthHandler { @@ -31,4 +39,46 @@ public abstract class LoginAuthHandlerBase implements ILoginAuthHandler { } public abstract UserVo myAuth(HttpServletRequest request) throws ServletException, IOException; + + /** + * 生成jwt对象 + * + * @param checkUserVo 用户 + * @return jwt对象 + * @throws Exception 异常 + */ + public static JwtVo buildJwt(UserVo checkUserVo, AuthenticationInfoVo authenticationInfoVo) throws Exception { + Long tokenCreateTime = System.currentTimeMillis(); + JwtVo jwtVo = new JwtVo(checkUserVo, tokenCreateTime, authenticationInfoVo); + SecretKeySpec signingKey = new SecretKeySpec(Config.JWT_SECRET().getBytes(), "HmacSHA1"); + Mac mac; + mac = Mac.getInstance("HmacSHA1"); + mac.init(signingKey); + byte[] rawHmac = mac.doFinal((jwtVo.getJwthead() + "." + jwtVo.getJwtbody()).getBytes()); + String jwtsign = Base64.getUrlEncoder().encodeToString(rawHmac); + // 压缩cookie内容 + String c = "Bearer_" + jwtVo.getJwthead() + "." + jwtVo.getJwtbody() + "." + jwtsign; + checkUserVo.setAuthorization(c); + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + GZIPOutputStream gzipOutputStream = new GZIPOutputStream(bos); + gzipOutputStream.write(c.getBytes()); + gzipOutputStream.close(); + String cc = Base64.getEncoder().encodeToString(bos.toByteArray()); + bos.close(); + jwtVo.setCc(cc); + jwtVo.setJwtsign(jwtsign); + checkUserVo.setJwtVo(jwtVo); + return jwtVo; + } + + /** + * 生成jwt对象 + * + * @param checkUserVo 用户 + * @return jwt对象 + * @throws Exception 异常 + */ + public static JwtVo buildJwt(UserVo checkUserVo) throws Exception { + return buildJwt(checkUserVo, new AuthenticationInfoVo()); + } } -- Gitee From 5c869b7ca49f1908f96c2c89c1a74ac610e005bf Mon Sep 17 00:00:00 2001 From: "1437892690@qq.com" <1437892690@qq.com> Date: Mon, 2 Sep 2024 15:15:18 +0800 Subject: [PATCH 3/6] =?UTF-8?q?[=E5=8A=9F=E8=83=BD]=20=E5=90=8E=E7=AB=AF-?= =?UTF-8?q?=E5=BA=9F=E5=BC=83public=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 关联 #[1234808854773760]后端-废弃public接口 http://192.168.0.96:8090/demo/rdm.html#/task-detail/939050947543040/939050947543050/1234808854773760 --- .../com/neatlogic/autoexecrunner/constvalue/SystemUser.java | 6 +++++- .../com/neatlogic/autoexecrunner/service/TagentService.java | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/neatlogic/autoexecrunner/constvalue/SystemUser.java b/src/main/java/com/neatlogic/autoexecrunner/constvalue/SystemUser.java index 4a1c198..ace9048 100755 --- a/src/main/java/com/neatlogic/autoexecrunner/constvalue/SystemUser.java +++ b/src/main/java/com/neatlogic/autoexecrunner/constvalue/SystemUser.java @@ -1,6 +1,7 @@ package com.neatlogic.autoexecrunner.constvalue; +import com.neatlogic.autoexecrunner.asynchronization.threadlocal.TenantContext; import com.neatlogic.autoexecrunner.dto.UserVo; /** @@ -17,7 +18,7 @@ public enum SystemUser { private String userName; private String timezone = "+8:00"; - private SystemUser(String userId, String userUuid, String userName) { + SystemUser(String userId, String userUuid, String userName) { this.userId = userId; this.userUuid = userUuid; this.userName = userName; @@ -44,6 +45,9 @@ public enum SystemUser { userVo.setUuid(userUuid); userVo.setUserId(userId); userVo.setUserName(userName); + userVo.setIsDelete(0); + userVo.setIsActive(1); + userVo.setTenant(TenantContext.get() != null ? TenantContext.get().getTenantUuid() : null); return userVo; } diff --git a/src/main/java/com/neatlogic/autoexecrunner/service/TagentService.java b/src/main/java/com/neatlogic/autoexecrunner/service/TagentService.java index 5c2833f..9e01fe8 100755 --- a/src/main/java/com/neatlogic/autoexecrunner/service/TagentService.java +++ b/src/main/java/com/neatlogic/autoexecrunner/service/TagentService.java @@ -13,5 +13,5 @@ public interface TagentService { * @param execInfo 执行信息 * @return 执行转发结果 */ - boolean forwardNeatlogicWeb(JSONObject jsonObj, String url, StringBuilder execInfo); + boolean forwardNeatlogicWeb(JSONObject jsonObj, String url, StringBuilder execInfo) throws Exception; } -- Gitee From e375495dd0d62ccbcf604b9dfbdbead5860eee6b Mon Sep 17 00:00:00 2001 From: "1437892690@qq.com" <1437892690@qq.com> Date: Mon, 2 Sep 2024 15:16:01 +0800 Subject: [PATCH 4/6] =?UTF-8?q?[=E5=8A=9F=E8=83=BD]=20=E5=90=8E=E7=AB=AF-?= =?UTF-8?q?=E5=BA=9F=E5=BC=83public=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 关联 #[1234808854773760]后端-废弃public接口 http://192.168.0.96:8090/demo/rdm.html#/task-detail/939050947543040/939050947543050/1234808854773760 --- .../neatlogic/autoexecrunner/api/tagent/TagentRegisterApi.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/neatlogic/autoexecrunner/api/tagent/TagentRegisterApi.java b/src/main/java/com/neatlogic/autoexecrunner/api/tagent/TagentRegisterApi.java index b0d16bf..1841e3e 100755 --- a/src/main/java/com/neatlogic/autoexecrunner/api/tagent/TagentRegisterApi.java +++ b/src/main/java/com/neatlogic/autoexecrunner/api/tagent/TagentRegisterApi.java @@ -31,7 +31,7 @@ public class TagentRegisterApi extends PublicApiComponentBase { JSONObject result = new JSONObject(); StringBuilder execInfo = new StringBuilder(); try { - String url = String.format("%s/public/api/rest/%s", Config.NEATLOGIC_ROOT(), Constant.ACTION_REGISTER_TAGENT); + String url = String.format("%s/api/rest/%s", Config.NEATLOGIC_ROOT(), Constant.ACTION_REGISTER_TAGENT); status = tagentService.forwardNeatlogicWeb(jsonObj,url,execInfo); } catch (Exception ex) { execInfo.append("runner exec error :").append(ExceptionUtils.getStackTrace(ex)); -- Gitee From 6c56968eca2040736e3cdb97fa551ffdae4434c5 Mon Sep 17 00:00:00 2001 From: "1437892690@qq.com" <1437892690@qq.com> Date: Mon, 2 Sep 2024 15:16:38 +0800 Subject: [PATCH 5/6] =?UTF-8?q?[=E5=8A=9F=E8=83=BD]=20=E5=90=8E=E7=AB=AF-?= =?UTF-8?q?=E5=BA=9F=E5=BC=83public=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 关联 #[1234808854773760]后端-废弃public接口 http://192.168.0.96:8090/demo/rdm.html#/task-detail/939050947543040/939050947543050/1234808854773760 --- .../autoexecrunner/service/TagentServiceImpl.java | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/neatlogic/autoexecrunner/service/TagentServiceImpl.java b/src/main/java/com/neatlogic/autoexecrunner/service/TagentServiceImpl.java index 5387633..859a737 100755 --- a/src/main/java/com/neatlogic/autoexecrunner/service/TagentServiceImpl.java +++ b/src/main/java/com/neatlogic/autoexecrunner/service/TagentServiceImpl.java @@ -2,10 +2,12 @@ package com.neatlogic.autoexecrunner.service; import com.alibaba.fastjson.JSONObject; import com.neatlogic.autoexecrunner.asynchronization.threadlocal.UserContext; -import com.neatlogic.autoexecrunner.common.config.TagentConfig; import com.neatlogic.autoexecrunner.common.tagent.IpUtil; import com.neatlogic.autoexecrunner.constvalue.AuthenticateType; +import com.neatlogic.autoexecrunner.constvalue.SystemUser; import com.neatlogic.autoexecrunner.dto.RestVo; +import com.neatlogic.autoexecrunner.dto.UserVo; +import com.neatlogic.autoexecrunner.filter.core.LoginAuthHandlerBase; import com.neatlogic.autoexecrunner.util.RestUtil; import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; @@ -18,18 +20,17 @@ import org.springframework.stereotype.Service; public class TagentServiceImpl implements TagentService { @Override - public boolean forwardNeatlogicWeb(JSONObject jsonObj, String url, StringBuilder execInfo) { + public boolean forwardNeatlogicWeb(JSONObject jsonObj, String url, StringBuilder execInfo) throws Exception { boolean status = false; if (jsonObj.containsKey("mgmtIp") && StringUtils.isNotBlank(jsonObj.getString("mgmtIp"))) { jsonObj.put("ip", jsonObj.getString("mgmtIp")); } else { jsonObj.put("ip", IpUtil.getIpAddr(UserContext.get().getRequest())); } - RestVo restVo = new RestVo(url, AuthenticateType.BASIC.getValue(), jsonObj); - restVo.setTenant(jsonObj.getString("tenant")); - restVo.setAuthType(TagentConfig.AUTH_TYPE); - restVo.setUsername(TagentConfig.ACCESS_KEY); - restVo.setPassword(TagentConfig.ACCESS_SECRET); + RestVo restVo = new RestVo(url, jsonObj, AuthenticateType.BEARER.getValue(), jsonObj.getString("tenant")); + UserVo userVo = SystemUser.SYSTEM.getUserVo(); + LoginAuthHandlerBase.buildJwt(userVo); + restVo.setToken(userVo.getAuthorization()); String httpResult = RestUtil.sendRequest(restVo); if (StringUtils.isNotBlank(httpResult)) { JSONObject resultJson = JSONObject.parseObject(httpResult); -- Gitee From 86c70342cd7517f8b023eb559d637667fbcd9f27 Mon Sep 17 00:00:00 2001 From: "1437892690@qq.com" <1437892690@qq.com> Date: Mon, 2 Sep 2024 15:18:09 +0800 Subject: [PATCH 6/6] =?UTF-8?q?[=E5=8A=9F=E8=83=BD]=20=E5=90=8E=E7=AB=AF-?= =?UTF-8?q?=E5=BA=9F=E5=BC=83public=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 关联 #[1234808854773760]后端-废弃public接口 http://192.168.0.96:8090/demo/rdm.html#/task-detail/939050947543040/939050947543050/1234808854773760 --- .../tagent/server/NettyServerHandler.java | 29 +++++++++++-------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/neatlogic/autoexecrunner/tagent/server/NettyServerHandler.java b/src/main/java/com/neatlogic/autoexecrunner/tagent/server/NettyServerHandler.java index 01de5ec..d13e917 100644 --- a/src/main/java/com/neatlogic/autoexecrunner/tagent/server/NettyServerHandler.java +++ b/src/main/java/com/neatlogic/autoexecrunner/tagent/server/NettyServerHandler.java @@ -10,10 +10,13 @@ import com.neatlogic.autoexecrunner.common.config.TagentConfig; import com.neatlogic.autoexecrunner.common.tagent.Constant; import com.neatlogic.autoexecrunner.common.tagent.NettyUtil; import com.neatlogic.autoexecrunner.constvalue.AuthenticateType; +import com.neatlogic.autoexecrunner.constvalue.SystemUser; import com.neatlogic.autoexecrunner.dto.RestVo; +import com.neatlogic.autoexecrunner.dto.UserVo; import com.neatlogic.autoexecrunner.exception.tagent.TagentActionFailedException; import com.neatlogic.autoexecrunner.exception.tagent.TagentNettyTenantIsNullException; import com.neatlogic.autoexecrunner.exception.ConnectRefusedException; +import com.neatlogic.autoexecrunner.filter.core.LoginAuthHandlerBase; import com.neatlogic.autoexecrunner.threadpool.tagent.HeartbeatThreadPool; import com.neatlogic.autoexecrunner.util.RestUtil; import io.netty.channel.ChannelHandler; @@ -66,17 +69,17 @@ public class NettyServerHandler extends SimpleChannelInboundHandler { * 客户端断开连接 */ @Override - public void channelInactive(ChannelHandlerContext ctx) { + public void channelInactive(ChannelHandlerContext ctx) throws Exception { agentInactive(ctx); } @Override - public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) { + public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { agentInactive(ctx); log.error(cause.getMessage()); } - private void agentInactive(ChannelHandlerContext ctx) { + private void agentInactive(ChannelHandlerContext ctx) throws Exception { String agentIp = NettyUtil.getConnectInfo(ctx, "remote")[0]; Integer listenPort = ctx.channel().attr(AGENT_LISTEN_PORT_KEY).get(); String tenant = ctx.channel().attr(AGENT_LISTEN_TENANT_KEY).get(); @@ -113,12 +116,12 @@ public class NettyServerHandler extends SimpleChannelInboundHandler { String result = StringUtils.EMPTY; JSONObject resultJson = new JSONObject(); RestVo restVo = null; - String url = String.format("%s/public/api/rest/%s", Config.NEATLOGIC_ROOT(), Constant.ACTION_UPDATE_TAGENT); + String url = String.format("%s/api/rest/%s", Config.NEATLOGIC_ROOT(), Constant.ACTION_UPDATE_TAGENT); try { - restVo = new RestVo(url, AuthenticateType.BASIC.getValue(), JSONObject.parseObject(JSON.toJSONString(params))); - restVo.setTenant(tenant); - restVo.setUsername(Config.ACCESS_KEY()); - restVo.setPassword(Config.ACCESS_SECRET()); + restVo = new RestVo(url, JSONObject.parseObject(JSON.toJSONString(params)), AuthenticateType.BEARER.getValue(), tenant); + UserVo userVo = SystemUser.SYSTEM.getUserVo(); + LoginAuthHandlerBase.buildJwt(userVo); + restVo.setToken(userVo.getAuthorization()); result = RestUtil.sendRequest(restVo); resultJson = JSONObject.parseObject(result); if (!resultJson.containsKey("Status") || !"OK".equals(resultJson.getString("Status"))) { @@ -192,10 +195,12 @@ public class NettyServerHandler extends SimpleChannelInboundHandler { String agentActionExecRes = StringUtils.EMPTY; JSONObject resultJson = new JSONObject(); RestVo restVo = null; - restVo = new RestVo(String.format("%s/public/api/rest/%s", Config.NEATLOGIC_ROOT(), Constant.ACTION_UPDATE_TAGENT_INFO), AuthenticateType.BASIC.getValue(), JSONObject.parseObject(JSON.toJSONString(params)));// 调用neatlogic的Tagent信息更新接口 - restVo.setTenant(params.get("tenant")); - restVo.setUsername(Config.ACCESS_KEY()); - restVo.setPassword(Config.ACCESS_SECRET()); + String url = String.format("%s/api/rest/%s", Config.NEATLOGIC_ROOT(), Constant.ACTION_UPDATE_TAGENT_INFO); + String tenant = params.get("tenant"); + restVo = new RestVo(url, JSONObject.parseObject(JSON.toJSONString(params)), AuthenticateType.BEARER.getValue(), tenant); + UserVo userVo = SystemUser.SYSTEM.getUserVo(); + LoginAuthHandlerBase.buildJwt(userVo); + restVo.setToken(userVo.getAuthorization()); agentActionExecRes = RestUtil.sendRequest(restVo); resultJson = JSONObject.parseObject(agentActionExecRes); if (!resultJson.containsKey("Status") || !"OK".equals(resultJson.getString("Status"))) { -- Gitee