From 6651f788e1538a31bfbaa0be7aa1194e6ee6b143 Mon Sep 17 00:00:00 2001 From: wangxuanran <3055088966@qq.com> Date: Tue, 4 Jul 2023 15:17:42 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9B=A2=E6=A0=A1=E5=AF=86=E7=A0=81=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E5=90=8E=E4=B8=8B=E5=8F=91=E9=98=9F=E5=88=97,?= =?UTF-8?q?=E5=85=A8=E5=B1=80token=E7=BC=93=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../getlog/controller/GetLogController.java | 20 ++- .../common/getlog/enums/LogTypeEnum.java | 33 +++-- .../common/getlog/service/GetLogService.java | 108 ++++++++++++-- .../common/getlog/util/EcTokenUtil.java | 117 +++++++++++++++ .../common/getlog/util/GetLogUtil.java | 54 +++---- .../controller/UserUpdateToMQController.java | 4 +- .../shyl/service/UserUpdateToMQService.java | 34 ++++- .../shyl/service/impl/UpdateHrmInfoAop.java | 135 ++++++++++++++++++ .../config/service/DealWithMapping.java | 8 +- .../interfaces/CusAbstractTokenConf.java | 84 +++++++++++ .../common/interfaces/CusDataDecipher.java | 15 ++ .../wang/common/util/RequestMasterPlate.java | 5 + .../xuanran/wang/common/util/TokenUtil.java | 71 +++++++++ .../sh_bigdata/common/entity/CusSuccess.java | 2 +- .../shyl_mq/entity/SentryLnesaTokenConf.java | 60 ++++++++ .../service/impl/PassWordServiceImpl.java | 28 ++-- .../wang/shyl_mq/util/RocketConsumerUtil.java | 62 ++++++++ .../java/ebu7dev1/common/getlog/CusTest.java | 24 ++++ .../wang/shyl/dataasync/TestPassword.java | 22 ++- 19 files changed, 809 insertions(+), 77 deletions(-) create mode 100644 src/main/java/com/api/ebu7dev1/common/getlog/util/EcTokenUtil.java create mode 100644 src/main/java/com/customization/shyl/service/impl/UpdateHrmInfoAop.java create mode 100644 src/main/java/weaver/xuanran/wang/common/interfaces/CusAbstractTokenConf.java create mode 100644 src/main/java/weaver/xuanran/wang/common/interfaces/CusDataDecipher.java create mode 100644 src/main/java/weaver/xuanran/wang/common/util/TokenUtil.java create mode 100644 src/main/java/weaver/xuanran/wang/shyl_mq/entity/SentryLnesaTokenConf.java diff --git a/src/main/java/com/api/ebu7dev1/common/getlog/controller/GetLogController.java b/src/main/java/com/api/ebu7dev1/common/getlog/controller/GetLogController.java index 7634ea7..094f782 100644 --- a/src/main/java/com/api/ebu7dev1/common/getlog/controller/GetLogController.java +++ b/src/main/java/com/api/ebu7dev1/common/getlog/controller/GetLogController.java @@ -8,6 +8,7 @@ import io.swagger.v3.oas.annotations.parameters.RequestBody; import org.apache.log4j.Logger; import weaver.hrm.HrmUserVarify; import weaver.hrm.User; +import weaver.interfaces.schedule.IpSelectUtil; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -19,6 +20,7 @@ import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import java.util.HashMap; +import java.util.List; import java.util.Map; /** @@ -35,6 +37,7 @@ public class GetLogController { private final GetLogService service = new GetLogService(); + @GET @Path("ipList") @Produces(MediaType.APPLICATION_JSON) @@ -62,6 +65,21 @@ public class GetLogController { return Response.ok(ApiResult.error("system error!"), MediaType.APPLICATION_JSON).build(); } } + + @POST + @Path("collectAll") + @Produces(MediaType.APPLICATION_JSON) + public String collectAllLogInfo(@Context HttpServletRequest request, + @Context HttpServletResponse response, + @RequestBody Map params) { + try { + User loginUser = HrmUserVarify.getUser(request, response); + return ApiResult.success(service.collectLogInfoAll(loginUser, params)); + } catch (Exception e) { + log.error("收集全部日志出错" + Util.getErrString(e)); + return ApiResult.error("system error!"); + } + } @POST @@ -76,7 +94,7 @@ public class GetLogController { params.put("ecologyPath", path); return ApiResult.success(service.collectLogInfo(loginUser, params)); } catch (Exception e) { - log.error("下载文件出错:" + Util.getErrString(e)); + log.error("收集单台服务器日志出错:" + Util.getErrString(e)); return ApiResult.error("system error!"); } } diff --git a/src/main/java/com/api/ebu7dev1/common/getlog/enums/LogTypeEnum.java b/src/main/java/com/api/ebu7dev1/common/getlog/enums/LogTypeEnum.java index 09c8ca9..8a8b9a7 100644 --- a/src/main/java/com/api/ebu7dev1/common/getlog/enums/LogTypeEnum.java +++ b/src/main/java/com/api/ebu7dev1/common/getlog/enums/LogTypeEnum.java @@ -16,32 +16,39 @@ import java.util.Map; * @date 2023/7/1 16:24 */ public enum LogTypeEnum { - THREAD(1, "0", "log" + File.separator + "thread","thread"), - ECOLOGY(1, "1", "log","ecology"), - RESIN(0, "2", "log","Resin"), - SECURITY(1, "3","WEB-INF" + File.separator + "securitylog","security"), - INTEGRATION(1,"4", "log" + File.separator + "integration","integration"), - SQL(1, "5", "log" + File.separator + "sql","sql"), - UTIL_CUS(1,"6", "log" + File.separator + "cus" + File.separator + "util_cus","util_cus"), - SQL_LOG(1,"7","log" + File.separator + "cus" + File.separator + "sql_log","sql_log"), - HTTP_UTIL(1,"8","log" + File.separator + "cus" + File.separator + "http_util","http_util"); + THREAD(1, "0", "log" + File.separator + "thread","thread",""), + ECOLOGY(1, "1", "log","ecology",""), + RESIN(0, "2", "log","Resin",""), + SECURITY(1, "3","WEB-INF" + File.separator + "securitylog","security",""), + INTEGRATION(1,"4", "log" + File.separator + "integration","integration",""), + SQL(1, "5", "log" + File.separator + "sql","sql",""), + UTIL_CUS(1,"6", "log" + File.separator + "cus" + File.separator + "util_cus","util_cus",("util_cus" + File.separator)), + SQL_LOG(1,"7","log" + File.separator + "cus" + File.separator + "sql_log","sql_log", ("sql_log" + File.separator)), + HTTP_UTIL(1,"8","log" + File.separator + "cus" + File.separator + "http_util","http_util", ("http_util" + File.separator)); private final Integer logBelongType; private final String value; private final String logPath; private final String key; - LogTypeEnum(Integer logBelongType, String value, String logPath,String key) { + private final String zipFolderName; + LogTypeEnum(Integer logBelongType, String value, String logPath,String key, String zipFolderName) { this.logBelongType = logBelongType; this.value = value; this.logPath = logPath; this.key = key; + this.zipFolderName = zipFolderName; } public final static Map ENUMS = new HashMap<>(16); - + public final static Map KEY_ZIP_FOLDER = new HashMap<>(16); static { for (LogTypeEnum typeEnum : EnumSet.allOf(LogTypeEnum.class)){ ENUMS.put(typeEnum.value,typeEnum); } } + static { + for (LogTypeEnum typeEnum : EnumSet.allOf(LogTypeEnum.class)){ + KEY_ZIP_FOLDER.put(typeEnum.key, typeEnum.zipFolderName); + } + } public String getValue() { return value; } @@ -55,4 +62,8 @@ public enum LogTypeEnum { public String getKey() { return key; } + + public String getZipFolderName() { + return zipFolderName; + } } diff --git a/src/main/java/com/api/ebu7dev1/common/getlog/service/GetLogService.java b/src/main/java/com/api/ebu7dev1/common/getlog/service/GetLogService.java index 57f317c..02152c8 100644 --- a/src/main/java/com/api/ebu7dev1/common/getlog/service/GetLogService.java +++ b/src/main/java/com/api/ebu7dev1/common/getlog/service/GetLogService.java @@ -1,16 +1,23 @@ package com.api.ebu7dev1.common.getlog.service; import aiyh.utils.Util; +import aiyh.utils.excention.CustomerException; +import aiyh.utils.httpUtil.ResponeVo; +import aiyh.utils.httpUtil.util.HttpUtils; +import com.api.ebu7dev1.common.getlog.util.EcTokenUtil; import com.api.ebu7dev1.common.getlog.util.GetLogUtil; import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.lang3.StringUtils; +import org.apache.log4j.Logger; import weaver.hrm.User; +import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import java.io.File; import java.io.FileNotFoundException; -import java.util.List; -import java.util.Map; -import java.util.Set; +import java.util.*; + +import static net.qiyuesuo.sdk.bean.template.MimeType.zip; /** *

获取日志

@@ -24,6 +31,14 @@ public class GetLogService { return null; } + private final Logger log = Util.getLogger("cus_get_log"); + + private final HttpUtils httpUtils = new HttpUtils(); + + { + httpUtils.getGlobalCache().header.put("Content-Type", MediaType.APPLICATION_JSON); // 全局请求头 + } + /** *

获取所有的ip地址

* @author xuanran.wang @@ -43,8 +58,8 @@ public class GetLogService { String localIp = GetLogUtil.getInnerIp(); Set ipList = GetLogUtil.readEcologyProp(weaverPropertiesPath); if(CollectionUtils.isEmpty(ipList)){ - String resinBinPath = resinPath + "bin" + File.separator + "startresin.sh"; - ipList.addAll(GetLogUtil.readResinProp(resinBinPath)); + String resinBinPath = resinPath + "bin" + File.separator; + ipList.addAll(GetLogUtil.readResinProp(resinBinPath + "startresin.sh")); } if (ipList.size() != 0) {//没有集群的时候 boolean status = false; @@ -62,17 +77,80 @@ public class GetLogService { } return ipList; } - - public String collectLogInfo(User loginUser, Map params) throws FileNotFoundException { + + /** + *

<收集全部节点日志/h1> + * @author xuanran.wang + * @dateTime 2023/7/3 18:53 + * @param loginUser 登录人 + * @param params 参数 + * @return 全部ip的日志zip路径 + **/ + public List> collectLogInfoAll(User loginUser, Map params) throws FileNotFoundException { GetLogUtil.checkUser(loginUser); - String startDate = Util.null2String(params.get("startDate")); - String endDate = Util.null2String(params.get("endDate")); - String ecologyPath = Util.null2String(params.get("ecologyPath")); - List logTypeList = (List) params.get("selectLogType"); - String resinPath = System.getProperty("user.dir") + File.separator; - List> path = GetLogUtil.getLogPathByLogType(ecologyPath, resinPath, logTypeList); - Map>> map = GetLogUtil.getLogFilePath(path, startDate, endDate); - return GetLogUtil.collectLog(ecologyPath, map); + List> result = new ArrayList<>(); + try { + List ipList = (List) params.get("ipList"); + if(CollectionUtils.isNotEmpty(ipList)){ + params.remove("ipList"); + for (String ip : ipList) { + ip = "http://" + ip; + Map header; + try { + header = EcTokenUtil.getEcTokenHeader(ip); + }catch (Exception e){ + throw new CustomerException("获取ec_token失败!", e); + } + ResponeVo responeVo = httpUtils.apiPost(ip + "/api/ebu7-dev1/common/log/collect", params, header); + if(200 != responeVo.getCode()) { + log.error("ip : [ " + ip + " ], 收集日志接口网络状态码不为200!"); + continue; + } + Map responseMap = responeVo.getResponseMap(); + int code = (int) responseMap.get("code"); + if(200 != code){ + log.error("ip : [ " + ip + " ], 收集日志接口业务逻辑响应码不为200!"); + continue; + } + List> zipPath = (List>) responseMap.get("data"); + if(CollectionUtils.isEmpty(zipPath)){ + log.error("ip : [ " + ip + " ], 收集日志接口返回压缩包路径为空!"); + continue; + } + result.addAll(zipPath); + } + } + }catch (Exception e){ + throw new CustomerException(e); + } + return result; + } + + /** + *

收集单台ip的日志

+ * @author xuanran.wang + * @dateTime 2023/7/3 18:53 + * @param loginUser 登录人 + * @param params 参数 + * @return 单台ip的zip路径 + **/ + public List> collectLogInfo(User loginUser, Map params) { + GetLogUtil.checkUser(loginUser); + try { + String startDate = Util.null2String(params.get("startDate")); + String endDate = Util.null2String(params.get("endDate")); + String ecologyPath = Util.null2String(params.get("ecologyPath")); + String resinPath = System.getProperty("user.dir") + File.separator; + List logTypeList = (List) params.get("logTypeList"); + List> path = GetLogUtil.getLogPathByLogType(ecologyPath, resinPath, logTypeList); + Map>> map = GetLogUtil.getLogFilePath(path, startDate, endDate); + Map res = GetLogUtil.collectLog(ecologyPath, map); + return Collections.singletonList(res); + }catch (Exception e){ + log.error("collectLogInfo error : " + e.getMessage()); + log.error(Util.getErrString(e)); + return new ArrayList<>(); + } } diff --git a/src/main/java/com/api/ebu7dev1/common/getlog/util/EcTokenUtil.java b/src/main/java/com/api/ebu7dev1/common/getlog/util/EcTokenUtil.java new file mode 100644 index 0000000..76ecf95 --- /dev/null +++ b/src/main/java/com/api/ebu7dev1/common/getlog/util/EcTokenUtil.java @@ -0,0 +1,117 @@ +package com.api.ebu7dev1.common.getlog.util; + +import aiyh.utils.Util; +import aiyh.utils.excention.CustomerException; +import aiyh.utils.httpUtil.ResponeVo; +import aiyh.utils.httpUtil.util.HttpUtils; +import cn.hutool.core.util.CharsetUtil; +import cn.hutool.core.util.StrUtil; +import cn.hutool.crypto.asymmetric.KeyType; +import cn.hutool.crypto.asymmetric.RSA; +import cn.hutool.http.HttpRequest; +import cn.hutool.json.JSONUtil; +import com.icbc.api.internal.apache.http.impl.cookie.S; + +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; + +/** + *

ec token util

+ * + * @author xuanran.wang + * @date 2023/7/3 19:13 + */ +public class EcTokenUtil { + /** + * 模拟缓存服务 + */ + private static final Map SYSTEM_CACHE = new HashMap<>(); + /** + * ecology系统发放的授权许可证(appid) + */ + private static final String APPID = "cus_get_log"; + + private static final HttpUtils httpUtils = new HttpUtils(); + + public static Map getEcTokenHeader(String address){ + Map header = new HashMap<>(); + String token = geToken(address); + String spk = SYSTEM_CACHE.get("SERVER_PUBLIC_KEY"); + //封装请求头参数 + RSA rsa = new RSA(null,spk); + //对用户信息进行加密传输,暂仅支持传输OA用户ID + String encryptUserid = rsa.encryptBase64("1",CharsetUtil.CHARSET_UTF_8,KeyType.PublicKey); + header.put("appid",APPID); + header.put("token",token); + header.put("userid",encryptUserid); + return header; + } + + public static void regist(String address){ + //获取当前系统RSA加密的公钥 + RSA rsa = new RSA(); + String publicKey = rsa.getPublicKeyBase64(); + String privateKey = rsa.getPrivateKeyBase64(); + // 客户端RSA私钥 + SYSTEM_CACHE.put("LOCAL_PRIVATE_KEY",privateKey); + // 客户端RSA公钥 + SYSTEM_CACHE.put("LOCAL_PUBLIC_KEY",publicKey); + Map header = new HashMap<>(); + header.put("appid",APPID); + header.put("cpk",publicKey); + try { + ResponeVo responeVo = httpUtils.apiPost(address + "/api/ec/dev/auth/regist", new HashMap<>(), header); + if(responeVo.getCode() != 200){ + throw new CustomerException("/api/ec/dev/auth/applytoken 接口网络状态码不为200"); + } + Map map = responeVo.getResponseMap(); + // 打印ECOLOGY响应信息 + //ECOLOGY返回的系统公钥 + SYSTEM_CACHE.put("SERVER_PUBLIC_KEY", StrUtil.nullToEmpty((String)map.get("spk"))); + //ECOLOGY返回的系统密钥 + SYSTEM_CACHE.put("SERVER_SECRET",StrUtil.nullToEmpty((String)map.get("secrit"))); + }catch (Exception e){ + throw new CustomerException("applytoken error : ",e); + } + + } + + + /** + * 第二步: + * + * 通过第一步中注册系统返回信息进行获取token信息 + */ + public static String geToken(String address){ + // 从系统缓存或者数据库中获取ECOLOGY系统公钥和Secret信息 + String secret = SYSTEM_CACHE.get("SERVER_SECRET"); + String spk = SYSTEM_CACHE.get("SERVER_PUBLIC_KEY"); + // 如果为空,说明还未进行注册,调用注册接口进行注册认证与数据更新 + if (Objects.isNull(secret)||Objects.isNull(spk)){ + regist(address); + // 重新获取最新ECOLOGY系统公钥和Secret信息 + secret = SYSTEM_CACHE.get("SERVER_SECRET"); + spk = SYSTEM_CACHE.get("SERVER_PUBLIC_KEY"); + } + // 公钥加密,所以RSA对象私钥为null + RSA rsa = new RSA(null,spk); + //对秘钥进行加密传输,防止篡改数据 + String encryptSecret = rsa.encryptBase64(secret, CharsetUtil.CHARSET_UTF_8, KeyType.PublicKey); + Map header = new HashMap<>(); + header.put("appid",APPID); + header.put("secret",encryptSecret); + //调用ECOLOGY系统接口进行注册 + try { + ResponeVo responeVo = httpUtils.apiPost(address + "/api/ec/dev/auth/applytoken", new HashMap<>(), header); + if(responeVo.getCode() != 200){ + throw new CustomerException("/api/ec/dev/auth/applytoken 接口网络状态码不为200"); + } + Map map = responeVo.getResponseMap(); + return Util.null2DefaultStr(map.get("token"),""); + }catch (Exception e){ + throw new CustomerException("get token error : ",e); + } + } + +} diff --git a/src/main/java/com/api/ebu7dev1/common/getlog/util/GetLogUtil.java b/src/main/java/com/api/ebu7dev1/common/getlog/util/GetLogUtil.java index 4a5126e..ca0b6fb 100644 --- a/src/main/java/com/api/ebu7dev1/common/getlog/util/GetLogUtil.java +++ b/src/main/java/com/api/ebu7dev1/common/getlog/util/GetLogUtil.java @@ -9,6 +9,7 @@ import java.util.*; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; +import aiyh.utils.Util; import aiyh.utils.excention.CustomerException; import com.api.ebu7dev1.common.getlog.enums.LogTypeEnum; import org.apache.commons.io.IOUtils; @@ -27,8 +28,6 @@ public class GetLogUtil { throw new CustomerException("无权限查看!"); } } - - /** *

读取ec weaver.properties配置文件 返回集群ip

* @@ -276,19 +275,26 @@ public class GetLogUtil { return res; } - public static String collectLog(String ecologyPath, Map>> pathListKeyMap) throws FileNotFoundException { + public static Map collectLog(String ecologyPath, Map>> pathListKeyMap) throws FileNotFoundException { + Map result = new HashMap<>(); FileOutputStream fos; - String outPath = ecologyPath + File.separator + "getlog" + File.separator + "log" + File.separator + (System.currentTimeMillis() / 1000); + ecologyPath += File.separator; + String mills = String.valueOf((System.currentTimeMillis() / 1000)); + String res = "getlog" + File.separator + "log" + File.separator + mills; + ecologyPath += res; File outFile = null; try { - outFile = new File(outPath); + outFile = new File(ecologyPath); if (!outFile.exists()) { outFile.mkdirs(); } } catch (Exception e) { e.printStackTrace(); } - String outLogPath = outFile + File.separator + getInnerIp() + "_downLog.zip"; + String innerIp = getInnerIp(); + String zipFile = File.separator + innerIp + "_downLog.zip"; + String outLogPath = outFile + zipFile; + res = res + zipFile; fos = new FileOutputStream(outLogPath); try { ZipOutputStream zos = new ZipOutputStream(fos); @@ -301,34 +307,18 @@ public class GetLogUtil { String basePath = date + File.separator; List pathList = pathKeyList.getValue(); for (String path : pathList) { - if ("sqllog".equals(key)) { - basePath += ("sqllog" + File.separator); - } - if ("monitorevent".equals(key)) { - basePath += ("event" + File.separator); - } - if ("monitorlog".equals(key)) { - basePath += ("monitorlog" + File.separator); - } - if (key.equals("cus")) { - basePath += ("cus" + File.separator); - } - if (key.equals("util_cus")) { - basePath += ("util_cus" + File.separator); - } - if (key.equals("sql_log")) { - basePath += ("sql_log" + File.separator); - } - if (key.equals("http_util")) { - basePath += ("http_util" + File.separator); + String zipFolder; + try { + zipFolder = LogTypeEnum.KEY_ZIP_FOLDER.get(key); + }catch (Exception e){ + Util.getLogger().error("the key = " + key + " not found in LogTypeEnum.KEY_ZIP_FOLDER"); + continue; } + basePath += zipFolder; compressbyType(path, zos, basePath); } } } - - System.out.println("日志文件地址 : " + outLogPath); - try { zos.close(); } catch (Exception es) { @@ -338,9 +328,11 @@ public class GetLogUtil { fos.close(); } } catch (Exception e) { - + Util.getLogger().error("collectLog error ", e); } - return outLogPath; + result.put("ip", innerIp); + result.put("zipPath", res); + return result; } /** diff --git a/src/main/java/com/api/xuanran/wang/shyl/controller/UserUpdateToMQController.java b/src/main/java/com/api/xuanran/wang/shyl/controller/UserUpdateToMQController.java index a0b5f89..3c30409 100644 --- a/src/main/java/com/api/xuanran/wang/shyl/controller/UserUpdateToMQController.java +++ b/src/main/java/com/api/xuanran/wang/shyl/controller/UserUpdateToMQController.java @@ -46,8 +46,8 @@ public class UserUpdateToMQController { userUpdateToMQService.toMQ(id, onlyMark, configName, debug); return ApiResult.success(null); }catch (Exception e){ - log.error(Util.logStr("MeetingController error ! {}", e.getMessage())); - return ApiResult.error(500,"会议取消接口发生异常! 异常信息 :[ " + e.getMessage() + " ]"); + log.error(Util.logStr("updateUserInfoToMQ error ! {}", e.getMessage())); + return ApiResult.error(500,"用户信息更新! 异常信息 :[ " + e.getMessage() + " ]"); } } diff --git a/src/main/java/com/api/xuanran/wang/shyl/service/UserUpdateToMQService.java b/src/main/java/com/api/xuanran/wang/shyl/service/UserUpdateToMQService.java index c19c2dc..04556e1 100644 --- a/src/main/java/com/api/xuanran/wang/shyl/service/UserUpdateToMQService.java +++ b/src/main/java/com/api/xuanran/wang/shyl/service/UserUpdateToMQService.java @@ -32,15 +32,47 @@ public class UserUpdateToMQService { private static final String HRM_TABLE = "hrmresource"; + /** + *

将人员信息发送到队列中

+ * @author xuanran.wang + * @dateTime 2023/7/3 14:14 + * @param id 人员id + * @param onlyMark 配置唯一标识 + * @param configName 配置文件名称 + * @param debug 是否开启debug + **/ public void toMQ(String id, String onlyMark, String configName, String debug){ + toMQ(id, onlyMark, configName, debug, null); + } + + /** + *

将人员信息发送到队列中

+ * @author xuanran.wang + * @dateTime 2023/7/3 14:15 + * @param id 人员id + * @param onlyMark 配置唯一标识 + * @param configName 配置文件名称 + * @param debug 是否开启debug + * @param otherParams 其他参数 + **/ + public void toMQ(String id, + String onlyMark, + String configName, + String debug, + Map otherParams){ Map userMap = producerMapper.queryUserInfo(id); if(MapUtils.isEmpty(userMap)){ + // 2300545611688368314 + // 2300545891688368314 logger.error(Util.logStr("userId: {}, userInfo is empty!")); return; } + if(MapUtils.isNotEmpty(otherParams)){ + userMap.putAll(otherParams); + } RequestMappingConfig config = dealWithMapping.treeDealWithUniqueCode(onlyMark); dealWithMapping.setMainTable(HRM_TABLE); Map param = dealWithMapping.getRequestParam(userMap, config); @@ -48,7 +80,7 @@ public class UserUpdateToMQService { logger.error(Util.logStr("userId:{}, 生成json为空!",id)); return; } - if(StringUtils.isNotBlank(debug)){ + if("1".equals(debug)){ logger.info("update user json : \n" + JSONObject.toJSONString(param)); return; } diff --git a/src/main/java/com/customization/shyl/service/impl/UpdateHrmInfoAop.java b/src/main/java/com/customization/shyl/service/impl/UpdateHrmInfoAop.java new file mode 100644 index 0000000..1a21a89 --- /dev/null +++ b/src/main/java/com/customization/shyl/service/impl/UpdateHrmInfoAop.java @@ -0,0 +1,135 @@ +package com.customization.shyl.service.impl; + +import aiyh.utils.Util; +import aiyh.utils.excention.CustomerException; +import aiyh.utils.zwl.common.ToolUtil; +import com.api.xuanran.wang.shyl.service.UserUpdateToMQService; +import com.weaverboot.frame.ioc.anno.classAnno.WeaIocReplaceComponent; +import com.weaverboot.frame.ioc.anno.methodAnno.WeaReplaceBefore; +import com.weaverboot.frame.ioc.handler.replace.weaReplaceParam.impl.WeaBeforeReplaceParam; +import org.apache.commons.lang3.StringUtils; +import weaver.file.Prop; +import weaver.hrm.HrmUserVarify; +import weaver.hrm.User; +import weaver.rsa.security.RSA; +import weaver.xuanran.wang.shyl_mq.util.RocketConsumerUtil; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + *

修改密码后 将密码加密放到队列中

+ * + * @author xuanran.wang + * @date 2023/7/3 13:35 + */ +@WeaIocReplaceComponent("UpdateHrmInfoAop") +public class UpdateHrmInfoAop { + + private UserUpdateToMQService service = null; + + /** + * 人员信息修改后 + * @param weaBeforeReplaceParam 拦截参数 + */ + @WeaReplaceBefore(value = "/api/hrm/password/changePassword", order = 1, description = "人员信息修改前 进行拦截") + public void passwordUpdateBefore(WeaBeforeReplaceParam weaBeforeReplaceParam) { + Map paramMap = weaBeforeReplaceParam.getParamMap(); + String newPassword = Util.null2DefaultStr(paramMap.get("passwordnew"),""); + if(StringUtils.isBlank(newPassword)){ + Util.getLogger().error("下发队列新密码不能为空!"); + return; + } + Map configMap = getMQConfigMap(); + HttpServletRequest request = weaBeforeReplaceParam.getRequest(); + HttpServletResponse response = weaBeforeReplaceParam.getResponse(); + User user = HrmUserVarify.getUser(request, response); + String oaPassWordOnlyMark = configMap.get("oaPassWordOnlyMark"); + String oaPassWordTopicConfigName = configMap.get("oaPassWordTopicConfigName"); + String decryPassword = RocketConsumerUtil.encryptContent(newPassword); + Map map = new HashMap<>(); + map.put("decryPassword", decryPassword); + service.toMQ(String.valueOf(user.getUID()),oaPassWordOnlyMark, oaPassWordTopicConfigName, configMap.get("sendMQ"), map); + } + + /** + * 人员信息修改后 + * @param weaBeforeReplaceParam 拦截参数 + */ + @WeaReplaceBefore(value = "/api/hrm/systeminfo/save", order = 1, description = "人员信息修改前 进行拦截") + public void hrmSave(WeaBeforeReplaceParam weaBeforeReplaceParam) { + try { + Map configMap = getMQConfigMap(); + String oaPassWordOnlyMark = configMap.get("oaPassWordOnlyMark"); + String oaPassWordTopicConfigName = configMap.get("oaPassWordTopicConfigName"); + HttpServletRequest request = weaBeforeReplaceParam.getRequest(); + if(service == null){ + service = new UserUpdateToMQService(); + } + String id = Util.null2DefaultStr(request.getParameter("id"),""); + if(StringUtils.isBlank(id)){ + Util.getLogger().error("从接口中获取人员id为空!"); + return; + } + // 解密后的密码 + String decryPassword = RocketConsumerUtil.encryptContent(Util.null2DefaultStr(parsePassword(request),"")); + Map map = new HashMap<>(); + map.put("decryPassword", decryPassword); + if(StringUtils.isBlank(decryPassword)){ + Util.getLogger().error("解密之后密码为空!"); + return; + } + service.toMQ(id,oaPassWordOnlyMark, oaPassWordTopicConfigName, configMap.get("sendMQ"), map); + }catch (Exception e){ + Util.getLogger().error("/api/hrm/systeminfo/save 拦截前置接口出错! " + e.getMessage()); + Util.getErrString(e); + } + } + + /** + *

解密请求中的密码

+ * @author xuanran.wang + * @dateTime 2023/7/3 14:10 + * @param request 请求对象 + * @return 解密后的数据 + **/ + private String parsePassword(HttpServletRequest request){ + String password = weaver.general.Util.null2String(request.getParameter("password")); + String loginId = weaver.general.Util.null2String(request.getParameter("loginid")); + boolean isRsa = "1".equals(Prop.getPropValue("openRSA", "isrsaopen")); + ArrayList passwordList = new ArrayList<>(); + if (isRsa) { + passwordList.add(password); + RSA rsa = new RSA(); + List list = rsa.decryptList(request, passwordList); + return Util.null2DefaultStr(list.get(0),""); + } + Util.getLogger().info("loginId : [ " + loginId + " ], password : [ " + password + " ]"); + return password; + } + + /** + *

获取密码修改队列 配置项

+ * @author xuanran.wang + * @dateTime 2023/7/3 14:59 + * @return 获取密码修改队列 配置项 + **/ + public Map getMQConfigMap(){ + ToolUtil toolUtil = new ToolUtil(); + String oaPassWordOnlyMark = toolUtil.getSystemParamValue("oaPassWordOnlyMark"); + String oaPassWordTopicConfigName = toolUtil.getSystemParamValue("oaPassWordTopicConfigName"); + if(StringUtils.isBlank(oaPassWordOnlyMark) || StringUtils.isBlank(oaPassWordTopicConfigName)){ + throw new CustomerException("系统参数配置表没配置oaPassWordOnlyMark或者oaPassWordTopicConfigName!"); + } + String sendMQ = Util.null2DefaultStr(toolUtil.getSystemParamValue("sendMQ"), ""); + Map res = new HashMap<>(); + res.put("oaPassWordOnlyMark", oaPassWordOnlyMark); + res.put("oaPassWordTopicConfigName", oaPassWordTopicConfigName); + res.put("sendMQ", sendMQ); + return res; + } +} diff --git a/src/main/java/weaver/xiao/commons/config/service/DealWithMapping.java b/src/main/java/weaver/xiao/commons/config/service/DealWithMapping.java index 94b1c6a..7b1f579 100644 --- a/src/main/java/weaver/xiao/commons/config/service/DealWithMapping.java +++ b/src/main/java/weaver/xiao/commons/config/service/DealWithMapping.java @@ -5,6 +5,7 @@ import com.google.common.base.Strings; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; +import org.apache.commons.collections.MapUtils; import org.apache.commons.lang3.StringUtils; import org.apache.log4j.Logger; import weaver.conn.RecordSet; @@ -783,7 +784,12 @@ public class DealWithMapping extends ToolUtil { } break; case CUS_FIELD: { - value = detailMap.get(valueContext.trim()); + if(MapUtils.isNotEmpty(mainMap)){ + value = mainMap.get(valueContext.trim()); + } + if ("1".equals(childSource) && MapUtils.isNotEmpty(detailMap)) { + value = detailMap.get(valueContext.trim()); + } } break; case CUS_MAPPER_SQL: { diff --git a/src/main/java/weaver/xuanran/wang/common/interfaces/CusAbstractTokenConf.java b/src/main/java/weaver/xuanran/wang/common/interfaces/CusAbstractTokenConf.java new file mode 100644 index 0000000..b9dec4b --- /dev/null +++ b/src/main/java/weaver/xuanran/wang/common/interfaces/CusAbstractTokenConf.java @@ -0,0 +1,84 @@ +package weaver.xuanran.wang.common.interfaces; + +import aiyh.utils.zwl.common.ToolUtil; +import weaver.general.TimeUtil; +import weaver.xuanran.wang.common.entity.CusSuccess; +import weaver.xuanran.wang.common.util.RequestMasterPlate; + +import java.util.Map; + +/** + *

抽象token

+ * + * @author xuanran.wang + * @date 2023/7/4 10:48 + */ +public abstract class CusAbstractTokenConf { + protected final RequestMasterPlate requestMasterPlate = new RequestMasterPlate(); + protected final ToolUtil toolUtil = new ToolUtil(); + /** + *

token

+ **/ + protected String token; + /** + *

时效时间

+ **/ + protected Long expiresIn; + /** + *

创建时间

+ **/ + protected String createTime; + /** + *

过期时间

+ **/ + protected Long expiryTime; + /** + *

设置token

+ **/ + protected abstract String setToken(Map response); + /** + *

设置时效时间

+ **/ + protected abstract Long setExpiresIn(Map response); + /** + *

设置过期时间

+ **/ + protected abstract Long setExpiryTime(Map response); + /** + *

token接口 成功参数

+ **/ + protected abstract CusSuccess buildSuccess(); + /** + *

从http接口获取token

+ **/ + public abstract Map tokenByHttp(); + + /** + *

为子类设置属性

+ * @author xuanran.wang + * @dateTime 2023/7/4 13:44 + * @param response 接口响应 + **/ + public void buildTokenObj(Map response){ + this.token = setToken(response); + this.expiresIn = setExpiresIn(response); + this.expiryTime = setExpiryTime(response); + this.createTime = TimeUtil.getCurrentTimeString(); + } + + public String getToken(){ + return this.token; + } + + public Long getExpiresIn() { + return expiresIn; + } + + public String getCreateTime() { + return createTime; + } + + public Long getExpiryTime() { + return expiryTime; + } +} diff --git a/src/main/java/weaver/xuanran/wang/common/interfaces/CusDataDecipher.java b/src/main/java/weaver/xuanran/wang/common/interfaces/CusDataDecipher.java new file mode 100644 index 0000000..d084c0d --- /dev/null +++ b/src/main/java/weaver/xuanran/wang/common/interfaces/CusDataDecipher.java @@ -0,0 +1,15 @@ +package weaver.xuanran.wang.common.interfaces; + +import aiyh.utils.httpUtil.ResponeVo; + +import java.util.Map; + +/** + *

自定义解密类

+ * + * @author xuanran.wang + * @date 2023/7/4 10:43 + */ +public interface CusDataDecipher { + Map decoder(ResponeVo responeVo); +} diff --git a/src/main/java/weaver/xuanran/wang/common/util/RequestMasterPlate.java b/src/main/java/weaver/xuanran/wang/common/util/RequestMasterPlate.java index 1288eef..668aea8 100644 --- a/src/main/java/weaver/xuanran/wang/common/util/RequestMasterPlate.java +++ b/src/main/java/weaver/xuanran/wang/common/util/RequestMasterPlate.java @@ -9,8 +9,10 @@ import org.apache.commons.lang3.StringUtils; import org.apache.log4j.Logger; import weaver.xuanran.wang.common.entity.CusSuccess; +import javax.ws.rs.core.MediaType; import java.io.IOException; import java.util.Map; +import java.util.Objects; /** *

请求模版方法

@@ -51,6 +53,9 @@ public class RequestMasterPlate { responseVo.getEntityString())); // 相应内容 throw new CustomerException(Util.logStr("can not fetch [{}]", url)); // 自定义异常类 create 2022/3/9 2:20 PM 构建日志字符串 } + if(Objects.isNull(cusSuccess)){ + return (T) responseVo.getResponseMap(); + } Map response; if(cusSuccess.getCusDataDecipher() != null){ response = cusSuccess.getCusDataDecipher().decoder(responseVo); diff --git a/src/main/java/weaver/xuanran/wang/common/util/TokenUtil.java b/src/main/java/weaver/xuanran/wang/common/util/TokenUtil.java new file mode 100644 index 0000000..61c6045 --- /dev/null +++ b/src/main/java/weaver/xuanran/wang/common/util/TokenUtil.java @@ -0,0 +1,71 @@ +package weaver.xuanran.wang.common.util; + +import aiyh.utils.Util; +import aiyh.utils.excention.CustomerException; +import com.alibaba.fastjson.JSONObject; +import org.apache.log4j.Logger; +import weaver.xuanran.wang.common.interfaces.CusAbstractTokenConf; + +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; + +/** + *

全局缓存token 超时自动请求处理

+ * + * @author xuanran.wang + * @date 2023/7/4 10:31 + */ +public class TokenUtil { + private static final Map TOKEN_MAP = new HashMap<>(8); + /** + *

从本地缓存中获取token

+ * @author xuanran.wang + * @dateTime 2023/7/4 13:44 + * @param key 指定key + * @param conf token配置对象 + * @return token + **/ + public static String getToken(String key, CusAbstractTokenConf conf){ + if(Objects.isNull(conf)){ + throw new CustomerException("conf cant not be null!"); + } + CusAbstractTokenConf token = TOKEN_MAP.get(key); + if(token == null){ + synchronized (TokenUtil.class){ + token = TOKEN_MAP.get(key); + if(token == null){ + return getTokenByHttp(key, conf); + } + } + } + long expiryTime = token.getExpiryTime(); + if(System.currentTimeMillis() >= expiryTime){ + synchronized (TokenUtil.class){ + expiryTime = token.getExpiryTime(); + if(System.currentTimeMillis() >= expiryTime){ + return getTokenByHttp(key, conf); + } + } + } + return token.getToken(); + } + + /** + *

发请求获取token

+ * @author xuanran.wang + * @dateTime 2023/7/4 13:45 + * @param key 缓存标识标识 + * @param obj token配置对象 + * @return token + **/ + private static synchronized String getTokenByHttp(String key, CusAbstractTokenConf obj){ + Map response = obj.tokenByHttp(); + obj.buildTokenObj(response); + TOKEN_MAP.put(key, obj); + Util.getLogger().info("TOKEN_MAP : " + JSONObject.toJSONString(TOKEN_MAP)); + return obj.getToken(); + } + + +} diff --git a/src/main/java/weaver/xuanran/wang/sh_bigdata/common/entity/CusSuccess.java b/src/main/java/weaver/xuanran/wang/sh_bigdata/common/entity/CusSuccess.java index 1750741..29833ac 100644 --- a/src/main/java/weaver/xuanran/wang/sh_bigdata/common/entity/CusSuccess.java +++ b/src/main/java/weaver/xuanran/wang/sh_bigdata/common/entity/CusSuccess.java @@ -4,7 +4,7 @@ import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; import lombok.NoArgsConstructor; -import weaver.xuanran.wang.sh_bigdata.common.service.CusDataDecipher; +import weaver.xuanran.wang.common.service.CusDataDecipher; /** diff --git a/src/main/java/weaver/xuanran/wang/shyl_mq/entity/SentryLnesaTokenConf.java b/src/main/java/weaver/xuanran/wang/shyl_mq/entity/SentryLnesaTokenConf.java new file mode 100644 index 0000000..c3a8762 --- /dev/null +++ b/src/main/java/weaver/xuanran/wang/shyl_mq/entity/SentryLnesaTokenConf.java @@ -0,0 +1,60 @@ +package weaver.xuanran.wang.shyl_mq.entity; + +import aiyh.utils.Util; +import aiyh.utils.excention.CustomerException; +import org.apache.commons.lang3.StringUtils; +import weaver.xuanran.wang.common.entity.CusSuccess; +import weaver.xuanran.wang.common.interfaces.CusAbstractTokenConf; + +import java.util.HashMap; +import java.util.Map; + +/** + *

硬件token

+ * + * @author xuanran.wang + * @date 2023/7/4 10:37 + */ +public class SentryLnesaTokenConf extends CusAbstractTokenConf { + public static final String TOKEN_KEY = "sentryLnesaToken"; + private static final CusSuccess TOKEN_SUCCESS = CusSuccess.builder() + .errorMsg("msg") + .successField("code") + .successValue(0) + .dataKey("data") + .build(); + @Override + protected String setToken(Map response) { + return Util.null2DefaultStr(response.get("access_token"),""); + } + + @Override + protected Long setExpiresIn(Map response) { + return Long.parseLong(Util.null2DefaultStr(response.get("expires_in"),"0")); + } + + @Override + protected Long setExpiryTime(Map response) { + long expiresIn = Long.parseLong(Util.null2DefaultStr(response.get("expires_in"), "0")); + if(expiresIn == 0){ + return 0L; + } + long timeMillis = System.currentTimeMillis(); + timeMillis += (expiresIn - (5 * 60)) * 1000; + return timeMillis; + } + + @Override + protected CusSuccess buildSuccess() { + return TOKEN_SUCCESS; + } + + @Override + public Map tokenByHttp() { + String url = toolUtil.getSystemParamValue("kqtokenurl"); + if(StringUtils.isBlank(url)){ + throw new CustomerException("在系统参数配置表[ uf_systemconfig ] 中没有配置,参数名为 : [ kqtokenurl ] 的配置项!"); + } + return requestMasterPlate.apiGet(url, new HashMap<>(), new HashMap<>(), this.buildSuccess()); + } +} diff --git a/src/main/java/weaver/xuanran/wang/shyl_mq/service/impl/PassWordServiceImpl.java b/src/main/java/weaver/xuanran/wang/shyl_mq/service/impl/PassWordServiceImpl.java index 4a5198c..2c572f4 100644 --- a/src/main/java/weaver/xuanran/wang/shyl_mq/service/impl/PassWordServiceImpl.java +++ b/src/main/java/weaver/xuanran/wang/shyl_mq/service/impl/PassWordServiceImpl.java @@ -2,13 +2,23 @@ package weaver.xuanran.wang.shyl_mq.service.impl; import aiyh.utils.Util; import aiyh.utils.excention.CustomerException; +import aiyh.utils.httpUtil.util.HttpUtils; import com.alibaba.fastjson.JSONObject; import org.apache.commons.lang3.StringUtils; import org.apache.log4j.Logger; import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus; +import weaver.xuanran.wang.common.entity.CusSuccess; +import weaver.xuanran.wang.common.util.RequestMasterPlate; +import weaver.xuanran.wang.common.util.TokenUtil; import weaver.xuanran.wang.shyl_mq.entity.MQMessage; import weaver.xuanran.wang.shyl_mq.entity.ModifyPassWord; +import weaver.xuanran.wang.shyl_mq.entity.SentryLnesaTokenConf; import weaver.xuanran.wang.shyl_mq.service.CusInfoActionService; +import weaver.xuanran.wang.shyl_mq.util.RocketConsumerUtil; + +import javax.ws.rs.core.MediaType; +import java.util.HashMap; +import java.util.Map; /** *

密码修改业务方法

@@ -20,10 +30,12 @@ public class PassWordServiceImpl extends CusInfoActionService { private Logger logger = Util.getLogger("mq-consumer-password"); + { if(null == logger){ logger = Util.getLogger("mq-consumer-password"); } + } @Override @@ -42,14 +54,13 @@ public class PassWordServiceImpl extends CusInfoActionService { String content = message.getContent(); ModifyPassWord passWord = JSONObject.parseObject(content, ModifyPassWord.class); logger.info(Util.logStr("cusPassWordAction messageId: {},UserInfo : {} ",message.getId(),JSONObject.toJSONString(passWord))); -// String outKey = passWord.getId(); -// String hrmId = consumerMapper.getHrmIdByOutKey(outKey); -// if(StringUtils.isBlank(hrmId)){ -// throw new CustomerException(Util.logStr("the userId is {} , no personnel information found in oa!", outKey)); -// } -// if (!consumerMapper.updatePasswordById(hrmId, Util.getEncrypt(passWord.getPassword()))) { -// throw new CustomerException("update user password error!"); -// } + String hrmId= passWord.getId(); + if(StringUtils.isBlank(hrmId)){ + throw new CustomerException(Util.logStr("the userId is {} , id is null!", hrmId)); + } + if (!consumerMapper.updatePasswordById(hrmId, Util.getEncrypt(RocketConsumerUtil.decryptContent(passWord.getPassword())))) { + throw new CustomerException("update user password error!"); + } writeInOA(message.getId()); return ConsumeConcurrentlyStatus.CONSUME_SUCCESS; } catch (Exception e) { @@ -61,4 +72,5 @@ public class PassWordServiceImpl extends CusInfoActionService { public ConsumeConcurrentlyStatus cusUpdateAction(MQMessage message) { return ConsumeConcurrentlyStatus.CONSUME_SUCCESS; } + } diff --git a/src/main/java/weaver/xuanran/wang/shyl_mq/util/RocketConsumerUtil.java b/src/main/java/weaver/xuanran/wang/shyl_mq/util/RocketConsumerUtil.java index 3227443..a7931a3 100644 --- a/src/main/java/weaver/xuanran/wang/shyl_mq/util/RocketConsumerUtil.java +++ b/src/main/java/weaver/xuanran/wang/shyl_mq/util/RocketConsumerUtil.java @@ -18,14 +18,19 @@ import org.apache.rocketmq.common.message.Message; import org.apache.rocketmq.common.message.MessageExt; import org.apache.rocketmq.remoting.common.RemotingHelper; import org.apache.rocketmq.remoting.exception.RemotingException; +import weaver.xuanran.wang.common.entity.CusSuccess; import weaver.xuanran.wang.common.util.CusInfoToOAUtil; +import weaver.xuanran.wang.common.util.RequestMasterPlate; +import weaver.xuanran.wang.common.util.TokenUtil; import weaver.xuanran.wang.shyl_mq.RocketMQFactory; import weaver.xuanran.wang.shyl_mq.constant.RocketMQConstant; import weaver.xuanran.wang.shyl_mq.entity.MQMessage; +import weaver.xuanran.wang.shyl_mq.entity.SentryLnesaTokenConf; import weaver.xuanran.wang.shyl_mq.mapper.ConsumerMapper; import weaver.xuanran.wang.shyl_mq.service.CusInfoActionService; import weaver.zwl.common.ToolUtil; +import javax.ws.rs.core.MediaType; import java.nio.charset.StandardCharsets; import java.util.*; @@ -43,6 +48,11 @@ public class RocketConsumerUtil { private static final ToolUtil tool = new ToolUtil(); private static final int ERROR_LOG_ID; private static final ToolUtil toolUtil = new ToolUtil(); + private static final RequestMasterPlate masterPlate = new RequestMasterPlate(); + public static final CusSuccess CRYPT_SUCCESS = + CusSuccess.builder().errorMsg("msg").successField("code").successValue(0).build(); + + private static final SentryLnesaTokenConf tokenConf = new SentryLnesaTokenConf(); static { ERROR_LOG_ID = Util.getIntValue(tool.getSystemParamValue("mqErrorLogModelId"), -1); @@ -218,5 +228,57 @@ public class RocketConsumerUtil { } while (!sendOk); } + /** + *

进行数据解密

+ * @author xuanran.wang + * @dateTime 2023/7/4 14:26 + * @param content 加密后的内容 + * @return 解密后的数据 + **/ + public static String decryptContent(String content){ + String decryptUrl = Util.null2DefaultStr(toolUtil.getSystemParamValue("decryptUrl"), ""); + if(StringUtils.isBlank(decryptUrl)){ + throw new CustomerException("请先在系统参数配置表 [ uf_systemconf ] 中配置 [ decryptUrl ] 参数"); + } + Map map = new HashMap<>(); + map.put("cipherText", content); + String token = TokenUtil.getToken(SentryLnesaTokenConf.TOKEN_KEY, tokenConf); + Map header = new HashMap<>(); + header.put("Content-Type", MediaType.APPLICATION_JSON); + header.put("Authorization", "Bearer " + token); + Map result = masterPlate.apiPost(decryptUrl, map, header, RocketConsumerUtil.CRYPT_SUCCESS); + String decry = Util.null2DefaultStr(result.get("data"), ""); + if(StringUtils.isBlank(decry)){ + throw new CustomerException("解密接口返回数据为空! 请求参数 : [ " + JSONObject.toJSONString(map) + " ]"); + } + return decry; + } + + /** + *

进行数据加密

+ * @author xuanran.wang + * @dateTime 2023/7/4 14:26 + * @param content 加密后的内容 + * @return 解密后的数据 + **/ + public static String encryptContent(String content){ + String encryptUrl = Util.null2DefaultStr(toolUtil.getSystemParamValue("encryptUrl"), ""); + if(StringUtils.isBlank(encryptUrl)){ + throw new CustomerException("请先在系统参数配置表 [ uf_systemconf ] 中配置 [ decryptUrl ] 参数"); + } + Map map = new HashMap<>(); + map.put("plain", content); + String token = TokenUtil.getToken(SentryLnesaTokenConf.TOKEN_KEY, tokenConf); + Map header = new HashMap<>(); + header.put("Content-Type", MediaType.APPLICATION_FORM_URLENCODED); + header.put("Authorization", "Bearer " + token); + Map result = masterPlate.apiGet(encryptUrl, map, header, RocketConsumerUtil.CRYPT_SUCCESS); + String encrypt = Util.null2DefaultStr(result.get("data"), ""); + if(StringUtils.isBlank(encrypt)){ + throw new CustomerException("加密接口返回数据为空! 请求参数 : [ " + JSONObject.toJSONString(map) + " ]"); + } + return encrypt; + } + } diff --git a/src/test/java/ebu7dev1/common/getlog/CusTest.java b/src/test/java/ebu7dev1/common/getlog/CusTest.java index ade6442..950d872 100644 --- a/src/test/java/ebu7dev1/common/getlog/CusTest.java +++ b/src/test/java/ebu7dev1/common/getlog/CusTest.java @@ -1,13 +1,18 @@ package ebu7dev1.common.getlog; +import aiyh.utils.httpUtil.ResponeVo; +import aiyh.utils.httpUtil.util.HttpUtils; import basetest.BaseTest; import com.alibaba.fastjson.JSONObject; import com.api.ebu7dev1.common.getlog.service.GetLogService; +import com.api.ebu7dev1.common.getlog.util.EcTokenUtil; import com.api.ebu7dev1.common.getlog.util.GetLogUtil; import org.junit.Test; +import javax.ws.rs.core.MediaType; import java.io.FileNotFoundException; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import java.util.Map; @@ -21,6 +26,11 @@ public class CusTest extends BaseTest { private final GetLogService service = new GetLogService(); + private final HttpUtils httpUtils = new HttpUtils(); + { + httpUtils.getGlobalCache().header.put("Content-Type", MediaType.APPLICATION_JSON); // 全局请求头 + } + @Test public void testA() throws FileNotFoundException { List list = new ArrayList<>(); @@ -35,4 +45,18 @@ public class CusTest extends BaseTest { System.out.println(JSONObject.toJSONString(map)); // GetLogUtil.com(base, map); } + + @Test + public void testB(){ +// String address = "https://ecology.yeyaguitu.cn/"; + String address = "http://10.0.4.12:8090/api/ec/dev/auth/regist"; + Map header = EcTokenUtil.getEcTokenHeader(address); + System.out.println("header : " + header); + try { + ResponeVo responeVo = httpUtils.apiGet(address + "/api/ebu7-dev1/common/log/ipList", header); + System.out.println("responeVo : " + JSONObject.toJSONString(responeVo)); + }catch (Exception e){ + System.out.println("e : " + e.getMessage()); + } + } } diff --git a/src/test/java/xuanran/wang/shyl/dataasync/TestPassword.java b/src/test/java/xuanran/wang/shyl/dataasync/TestPassword.java index 3882ba3..8a641c4 100644 --- a/src/test/java/xuanran/wang/shyl/dataasync/TestPassword.java +++ b/src/test/java/xuanran/wang/shyl/dataasync/TestPassword.java @@ -1,10 +1,15 @@ package xuanran.wang.shyl.dataasync; import basetest.BaseTest; +import com.alibaba.fastjson.JSONObject; +import com.api.xuanran.wang.shyl.service.UserUpdateToMQService; import org.junit.Test; -import weaver.rsa.security.RSA; +import weaver.xuanran.wang.common.interfaces.CusAbstractTokenConf; +import weaver.xuanran.wang.common.util.TokenUtil; +import weaver.xuanran.wang.shyl_mq.entity.SentryLnesaTokenConf; +import weaver.xuanran.wang.shyl_mq.util.RocketConsumerUtil; -import java.util.List; +import java.util.Map; /** *

@@ -13,10 +18,15 @@ import java.util.List; * @date 2023/7/3 11:49 */ public class TestPassword extends BaseTest { + private final UserUpdateToMQService service = new UserUpdateToMQService(); @Test - public void testA(){ - RSA var15 = new RSA(); - String decrypt = var15.decrypt("cY5Y2bIDOnQCGfmmAHTH6g48qhAw+b3DbAPndeT1KxkK0z5K5kyBA5cbE8mfJYdjhK6WQ2W5/YfIHAWDNQxP1UCGzFSjmBbUkx5oJFlhm0G+s/AwsxqsiFU2uFVqKpyfJP/Xdm0ux6bNfUSu8KoqfrB6h6HonGPmXQc2fATQ66urHC7mnpvC6XGOQ/0K7z0grcLv59PuKU5AkZpn2LZ/qMeaGWkAaBOB2Ko9xc8lBnvppyN23cozde2CVyoD8s59otp543oSN6MFHpkLVk2C1Uew8arZhEP+04VJdGhABtLX1H5X+N/hG20dlH5HxWlvYkc6H9qaKv89XvcXdg072Q==``RSA``"); - System.out.println(decrypt); + public void testA() throws InterruptedException { + String encryptContent = RocketConsumerUtil.encryptContent("wxr12345435"); + System.out.println("encryptContent : " + encryptContent); + + Thread.sleep(60000); + String decryptContent = RocketConsumerUtil.decryptContent(encryptContent); + System.out.println("decryptContent : " + decryptContent ); + } }