Commit c38b56ce by yuwei

2.0.0项目初始化

parent a78ae097
package cn.datax.service.data.market.api.call.factory;
import cn.datax.service.data.market.api.call.factory.crypto.Crypto;
public abstract class AbstractFactory {
public abstract Crypto getCrypto(Integer type);
}
package cn.datax.service.data.market.data.masking.factory;
package cn.datax.service.data.market.api.call.factory;
import cn.datax.service.data.market.api.call.factory.crypto.AlgorithmRegistry;
import cn.datax.service.data.market.api.call.factory.crypto.Crypto;
import cn.datax.service.data.market.api.enums.AlgorithmCrypto;
import cn.datax.service.data.market.data.masking.factory.crypto.AlgorithmRegistry;
import cn.datax.service.data.market.data.masking.factory.crypto.Crypto;
public class AlgorithmFactory extends AbstractFactory {
private static final AlgorithmRegistry ALGORITHM_REGISTRY = new AlgorithmRegistry();
@Override
public Crypto getAlgorithm(Integer type) {
public Crypto getCrypto(Integer type) {
AlgorithmCrypto crypto = AlgorithmCrypto.getAlgorithmCrypto(type);
return ALGORITHM_REGISTRY.getAlgorithm(crypto);
}
@Override
public Crypto getRegex(Integer type) {
return null;
}
}
package cn.datax.service.data.market.data.masking.factory;
package cn.datax.service.data.market.api.call.factory;
import cn.datax.service.data.market.api.call.factory.crypto.Crypto;
import cn.datax.service.data.market.api.call.factory.crypto.RegexRegistry;
import cn.datax.service.data.market.api.enums.RegexCrypto;
import cn.datax.service.data.market.data.masking.factory.crypto.Crypto;
import cn.datax.service.data.market.data.masking.factory.crypto.RegexRegistry;
public class RegexFactory extends AbstractFactory {
private static final RegexRegistry REGEX_REGISTRY = new RegexRegistry();
@Override
public Crypto getAlgorithm(Integer type) {
return null;
}
@Override
public Crypto getRegex(Integer type) {
public Crypto getCrypto(Integer type) {
RegexCrypto crypto = RegexCrypto.getRegexCrypto(type);
return REGEX_REGISTRY.getRegex(crypto);
}
......
package cn.datax.service.data.market.data.masking.factory.crypto;
package cn.datax.service.data.market.api.call.factory.crypto;
import cn.hutool.core.util.StrUtil;
import org.apache.commons.lang3.StringUtils;
import javax.crypto.*;
import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;
import java.security.SecureRandom;
import java.util.Base64;
......@@ -12,7 +14,7 @@ public class AESCrypto implements Crypto {
@Override
public String encrypt(String content) {
if (StringUtils.isBlank(content)) {
if (StrUtil.isBlank(content)) {
return null;
}
try {
......@@ -27,9 +29,9 @@ public class AESCrypto implements Crypto {
//5.根据字节数组生成AES密钥
SecretKeySpec key = new SecretKeySpec(enCodeFormat, "AES");
//6.根据指定算法AES生成密码器
javax.crypto.Cipher cipher = javax.crypto.Cipher.getInstance("AES");
Cipher cipher = Cipher.getInstance("AES");
//7.初始化密码器,第一个参数为加密(Encrypt_mode)或者解密解密(Decrypt_mode)操作,第二个参数为使用的KEY
cipher.init(javax.crypto.Cipher.ENCRYPT_MODE, key);
cipher.init(Cipher.ENCRYPT_MODE, key);
//8.根据密码器的初始化方式--加密:将数据加密
byte[] AES_encrypt = cipher.doFinal(content.getBytes(CHARSET_UTF8));
//9.将字符串返回
......@@ -57,7 +59,7 @@ public class AESCrypto implements Crypto {
//5.根据字节数组生成AES密钥
SecretKeySpec key = new SecretKeySpec(enCodeFormat, "AES");
//6.根据指定算法AES生成密码器
javax.crypto.Cipher cipher = javax.crypto.Cipher.getInstance("AES");
Cipher cipher = Cipher.getInstance("AES");
//7.初始化密码器,第一个参数为加密(Encrypt_mode)或者解密解密(Decrypt_mode)操作,第二个参数为使用的KEY
cipher.init(Cipher.DECRYPT_MODE, key);// 初始化
//8.根据密码器的初始化方式--加密:将数据加密
......
package cn.datax.service.data.market.data.masking.factory.crypto;
package cn.datax.service.data.market.api.call.factory.crypto;
import org.apache.commons.lang3.StringUtils;
import javax.crypto.*;
import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;
import java.security.SecureRandom;
import java.util.Base64;
......@@ -21,8 +22,8 @@ public class DESCrypto implements Crypto {
SecretKey secretKey = kGen.generateKey();
byte[] enCodeFormat = secretKey.getEncoded();
SecretKeySpec key = new SecretKeySpec(enCodeFormat, "DES");
javax.crypto.Cipher cipher = javax.crypto.Cipher.getInstance("DES");
cipher.init(javax.crypto.Cipher.ENCRYPT_MODE, key);
Cipher cipher = Cipher.getInstance("DES");
cipher.init(Cipher.ENCRYPT_MODE, key);
byte[] DES_encrypt = cipher.doFinal(content.getBytes(CHARSET_UTF8));
return Base64.getEncoder().encodeToString(DES_encrypt);
} catch (Exception e) {
......@@ -41,7 +42,7 @@ public class DESCrypto implements Crypto {
SecretKey secretKey = kGen.generateKey();
byte[] enCodeFormat = secretKey.getEncoded();
SecretKeySpec key = new SecretKeySpec(enCodeFormat, "DES");
javax.crypto.Cipher cipher = javax.crypto.Cipher.getInstance("DES");
Cipher cipher = Cipher.getInstance("DES");
cipher.init(Cipher.DECRYPT_MODE, key);
byte[] DES_decrypt = cipher.doFinal(Base64.getDecoder().decode(content));
return new String(DES_decrypt, CHARSET_UTF8);
......
......@@ -11,6 +11,9 @@ import cn.datax.common.utils.ThrowableUtil;
import cn.datax.service.data.factory.api.dto.DbSchema;
import cn.datax.service.data.factory.api.entity.DataSourceEntity;
import cn.datax.service.data.factory.api.feign.DataSourceServiceFeign;
import cn.datax.service.data.market.api.call.factory.AbstractFactory;
import cn.datax.service.data.market.api.call.factory.FactoryProducer;
import cn.datax.service.data.market.api.call.factory.crypto.Crypto;
import cn.datax.service.data.market.api.call.service.ApiCallService;
import cn.datax.service.data.market.api.call.utils.SqlBuilderUtil;
import cn.datax.service.data.market.api.call.utils.ThreadUtil;
......@@ -90,20 +93,41 @@ public class ApiCallServiceImpl implements ApiCallService {
ApiMaskEntity apiMask = JSON.parseObject(JSON.toJSONString(maskResult.getData()), ApiMaskEntity.class);
rules = apiMask.getRules();
}
PageResult<Map<String, Object>> pageResult;
try {
pageResult = dbQuery.queryByPage(sqlFilterResult.getSql(), acceptedFilters, offset, pageSize);
} catch (Exception e) {
log.error("全局异常信息ex={}, StackTrace={}", e.getMessage(), ThrowableUtil.getStackTrace(e));
ThreadUtil.getInstance().get().setStatus(0);
ThreadUtil.getInstance().get().setMsg(e.getMessage());
throw new DataException("API调用查询结果集出错");
}
try {
PageResult<Map<String, Object>> pageResult = dbQuery.queryByPage(sqlFilterResult.getSql(), acceptedFilters, offset, pageSize);
if (CollUtil.isNotEmpty(rules)){
// 并行流处理脱敏
// pageResult.getData().parallelStream()
List<FieldRule> finalRules = rules;
pageResult.getData().parallelStream().forEach(m -> {
finalRules.stream().forEach(r -> {
if (m.containsKey(r.getFieldName())) {
Object obj = m.get(r.getFieldName());
if (null != obj){
AbstractFactory factory = FactoryProducer.getFactory(r.getCipherType());
Crypto crypto = factory.getCrypto(r.getCryptType());
String encrypt = crypto.encrypt(String.valueOf(obj));
m.put(r.getFieldName(), encrypt);
}
}
});
});
}
pageResult.setPageNum(pageNum).setPageSize(pageSize);
ThreadUtil.getInstance().get().setCallerSize(pageResult.getData().size());
return pageResult;
} catch (Exception e) {
log.error("全局异常信息ex={}, StackTrace={}", e.getMessage(), ThrowableUtil.getStackTrace(e));
ThreadUtil.getInstance().get().setStatus(0);
ThreadUtil.getInstance().get().setMsg(e.getMessage());
throw new DataException("API调用查询结果集出错");
throw new DataException("API调用数据脱敏出错");
}
pageResult.setPageNum(pageNum).setPageSize(pageSize);
ThreadUtil.getInstance().get().setCallerSize(pageResult.getData().size());
return pageResult;
}
}
package cn.datax.service.data.market.data.masking.factory;
import cn.datax.service.data.market.data.masking.factory.crypto.Crypto;
public abstract class AbstractFactory {
public abstract Crypto getAlgorithm(Integer type);
public abstract Crypto getRegex(Integer type);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment