团校密码修改后下发队列,全局token缓存

dev
wangxuanran 2023-07-04 15:17:42 +08:00
parent e43060ac2b
commit 6651f788e1
19 changed files with 809 additions and 77 deletions

View File

@ -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)
@ -63,6 +66,21 @@ public class GetLogController {
}
}
@POST
@Path("collectAll")
@Produces(MediaType.APPLICATION_JSON)
public String collectAllLogInfo(@Context HttpServletRequest request,
@Context HttpServletResponse response,
@RequestBody Map<String, Object> 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
@Path("collect")
@ -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!");
}
}

View File

@ -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<String, LogTypeEnum> ENUMS = new HashMap<>(16);
public final static Map<String, String> 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;
}
}

View File

@ -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;
/**
* <h1></h1>
@ -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); // 全局请求头
}
/**
* <h1>ip</h1>
* @author xuanran.wang
@ -43,8 +58,8 @@ public class GetLogService {
String localIp = GetLogUtil.getInnerIp();
Set<String> 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;
@ -63,16 +78,79 @@ public class GetLogService {
return ipList;
}
public String collectLogInfo(User loginUser, Map<String, Object> params) throws FileNotFoundException {
/**
* <h1></h1>
* @author xuanran.wang
* @dateTime 2023/7/3 18:53
* @param loginUser
* @param params
* @return ipzip
**/
public List<Map<String, String>> collectLogInfoAll(User loginUser, Map<String, Object> 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<String> logTypeList = (List<String>) params.get("selectLogType");
String resinPath = System.getProperty("user.dir") + File.separator;
List<Map<String, String>> path = GetLogUtil.getLogPathByLogType(ecologyPath, resinPath, logTypeList);
Map<String, Map<String, List<String>>> map = GetLogUtil.getLogFilePath(path, startDate, endDate);
return GetLogUtil.collectLog(ecologyPath, map);
List<Map<String, String>> result = new ArrayList<>();
try {
List<String> ipList = (List<String>) params.get("ipList");
if(CollectionUtils.isNotEmpty(ipList)){
params.remove("ipList");
for (String ip : ipList) {
ip = "http://" + ip;
Map<String, String> 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<String, Object> responseMap = responeVo.getResponseMap();
int code = (int) responseMap.get("code");
if(200 != code){
log.error("ip : [ " + ip + " ], 收集日志接口业务逻辑响应码不为200!");
continue;
}
List<Map<String, String>> zipPath = (List<Map<String, String>>) responseMap.get("data");
if(CollectionUtils.isEmpty(zipPath)){
log.error("ip : [ " + ip + " ], 收集日志接口返回压缩包路径为空!");
continue;
}
result.addAll(zipPath);
}
}
}catch (Exception e){
throw new CustomerException(e);
}
return result;
}
/**
* <h1>ip</h1>
* @author xuanran.wang
* @dateTime 2023/7/3 18:53
* @param loginUser
* @param params
* @return ipzip
**/
public List<Map<String, String>> collectLogInfo(User loginUser, Map<String, Object> 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<String> logTypeList = (List<String>) params.get("logTypeList");
List<Map<String, String>> path = GetLogUtil.getLogPathByLogType(ecologyPath, resinPath, logTypeList);
Map<String, Map<String, List<String>>> map = GetLogUtil.getLogFilePath(path, startDate, endDate);
Map<String, String> 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<>();
}
}

View File

@ -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;
/**
* <h1>ec token util</h1>
*
* @author xuanran.wang
* @date 2023/7/3 19:13
*/
public class EcTokenUtil {
/**
*
*/
private static final Map<String,String> SYSTEM_CACHE = new HashMap<>();
/**
* ecology(appid)
*/
private static final String APPID = "cus_get_log";
private static final HttpUtils httpUtils = new HttpUtils();
public static Map<String, String> getEcTokenHeader(String address){
Map<String, String> 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<String, String> 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<String, Object> 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<String, String> 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<String, Object> map = responeVo.getResponseMap();
return Util.null2DefaultStr(map.get("token"),"");
}catch (Exception e){
throw new CustomerException("get token error : ",e);
}
}
}

View File

@ -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("无权限查看!");
}
}
/**
* <h1>ec weaver.properties ip</h1>
*
@ -276,19 +275,26 @@ public class GetLogUtil {
return res;
}
public static String collectLog(String ecologyPath, Map<String, Map<String, List<String>>> pathListKeyMap) throws FileNotFoundException {
public static Map<String, String> collectLog(String ecologyPath, Map<String, Map<String, List<String>>> pathListKeyMap) throws FileNotFoundException {
Map<String, String> 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<String> 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;
}
/**

View File

@ -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() + " ]");
}
}

View File

@ -32,15 +32,47 @@ public class UserUpdateToMQService {
private static final String HRM_TABLE = "hrmresource";
/**
* <h1></h1>
* @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);
}
/**
* <h1></h1>
* @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<String, Object> otherParams){
Map<String, Object> 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<String, Object> 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;
}

View File

@ -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;
/**
* <h1> </h1>
*
* @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<String, String> 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<String, Object> 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<String, String> 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<String, Object> 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);
}
}
/**
* <h1></h1>
* @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<String> 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;
}
/**
* <h1> </h1>
* @author xuanran.wang
* @dateTime 2023/7/3 14:59
* @return
**/
public Map<String, String> 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<String, String> res = new HashMap<>();
res.put("oaPassWordOnlyMark", oaPassWordOnlyMark);
res.put("oaPassWordTopicConfigName", oaPassWordTopicConfigName);
res.put("sendMQ", sendMQ);
return res;
}
}

View File

@ -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: {

View File

@ -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;
/**
* <h1>token</h1>
*
* @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();
/**
* <h2>token</h2>
**/
protected String token;
/**
* <h2></h2>
**/
protected Long expiresIn;
/**
* <h2></h2>
**/
protected String createTime;
/**
* <h2></h2>
**/
protected Long expiryTime;
/**
* <h2>token</h2>
**/
protected abstract String setToken(Map<String, Object> response);
/**
* <h2></h2>
**/
protected abstract Long setExpiresIn(Map<String, Object> response);
/**
* <h2></h2>
**/
protected abstract Long setExpiryTime(Map<String, Object> response);
/**
* <h2>token </h2>
**/
protected abstract CusSuccess buildSuccess();
/**
* <h2>httptoken</h2>
**/
public abstract Map<String, Object> tokenByHttp();
/**
* <h1></h1>
* @author xuanran.wang
* @dateTime 2023/7/4 13:44
* @param response
**/
public void buildTokenObj(Map<String, Object> 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;
}
}

View File

@ -0,0 +1,15 @@
package weaver.xuanran.wang.common.interfaces;
import aiyh.utils.httpUtil.ResponeVo;
import java.util.Map;
/**
* <h1></h1>
*
* @author xuanran.wang
* @date 2023/7/4 10:43
*/
public interface CusDataDecipher {
Map<String, Object> decoder(ResponeVo responeVo);
}

View File

@ -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;
/**
* <h1></h1>
@ -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<String, Object> response;
if(cusSuccess.getCusDataDecipher() != null){
response = cusSuccess.getCusDataDecipher().decoder(responseVo);

View File

@ -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;
/**
* <h1>token </h1>
*
* @author xuanran.wang
* @date 2023/7/4 10:31
*/
public class TokenUtil {
private static final Map<String, CusAbstractTokenConf> TOKEN_MAP = new HashMap<>(8);
/**
* <h1>token</h1>
* @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();
}
/**
* <h1>token</h1>
* @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<String, Object> response = obj.tokenByHttp();
obj.buildTokenObj(response);
TOKEN_MAP.put(key, obj);
Util.getLogger().info("TOKEN_MAP : " + JSONObject.toJSONString(TOKEN_MAP));
return obj.getToken();
}
}

View File

@ -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;
/**

View File

@ -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;
/**
* <h1>token</h1>
*
* @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<String, Object> response) {
return Util.null2DefaultStr(response.get("access_token"),"");
}
@Override
protected Long setExpiresIn(Map<String, Object> response) {
return Long.parseLong(Util.null2DefaultStr(response.get("expires_in"),"0"));
}
@Override
protected Long setExpiryTime(Map<String, Object> 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<String, Object> 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());
}
}

View File

@ -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;
/**
* <h1></h1>
@ -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;
}
}

View File

@ -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);
}
/**
* <h1></h1>
* @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<String, Object> map = new HashMap<>();
map.put("cipherText", content);
String token = TokenUtil.getToken(SentryLnesaTokenConf.TOKEN_KEY, tokenConf);
Map<String, String> header = new HashMap<>();
header.put("Content-Type", MediaType.APPLICATION_JSON);
header.put("Authorization", "Bearer " + token);
Map<String, Object> 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;
}
/**
* <h1></h1>
* @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<String, Object> map = new HashMap<>();
map.put("plain", content);
String token = TokenUtil.getToken(SentryLnesaTokenConf.TOKEN_KEY, tokenConf);
Map<String, String> header = new HashMap<>();
header.put("Content-Type", MediaType.APPLICATION_FORM_URLENCODED);
header.put("Authorization", "Bearer " + token);
Map<String, Object> 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;
}
}

View File

@ -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<String> 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<String, String> 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());
}
}
}

View File

@ -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;
/**
* <h1></h1>
@ -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 );
}
}