Commit 6c951e9a by fudahua

feat:下载加密解密过滤

parent 2f2163d9
package com.gic.cloud.data.hook.service;
import com.alibaba.dubbo.common.utils.StringUtils;
import com.ctrip.framework.apollo.Config;
import com.ctrip.framework.apollo.ConfigService;
import com.gic.cloud.data.hook.api.entity.FlatQueryCondition;
import com.gic.cloud.data.hook.service.impl.FreeQueryServiceImpl;
import com.gic.data.shield.SdkEnv;
......@@ -50,6 +52,14 @@ public class DecryptUtils {
}
}
public static String decrypt(String enterpriseId,String encryptString) {
if (DecryptUtils.checkDecrypt(enterpriseId)){
return DecryptUtils.decrypt(encryptString);
}else{
return encryptString;
}
}
public static String dataSecurityProcessUserName(String userName){
if(StringUtils.isBlank(userName)){
return userName;
......@@ -73,4 +83,23 @@ public class DecryptUtils {
return false;
}
/**
* 是否需要解密
* @param enterpriseId
* @return
*/
public static boolean checkDecrypt(String enterpriseId) {
Config appConfig = ConfigService.getAppConfig();
String entIds = appConfig.getProperty("decrypt-enterprise", "1");
if (entIds.equals("-1")) {
return false;
}else if (entIds.equals("1")) {
return true;
}else if (entIds.contains(enterpriseId)) {
return false;
}else{
return true;
}
}
}
......@@ -169,14 +169,14 @@ public class CsvResultSetHelper implements ResultSetHelper {
// 数据处理
if (doDesensi) { // 如果需要脱敏处理
if(allFields != null && isName(columnName)){
result.add(DecryptUtils.dataSecurityProcessUserName(DecryptUtils.decrypt(resultSet.getString(columnName))));
result.add(DecryptUtils.dataSecurityProcessUserName(DecryptUtils.decrypt(enterpriseId,resultSet.getString(columnName))));
} else if(allFields == null && FilterFieldUtils.FILETERS_USER_NAME.contains(columnName)) {
result.add(DecryptUtils.dataSecurityProcessUserName(resultSet.getString(i+1)));
} else {
result.add("******");
if(needDecryptByEnt && isPhoneNumber(columnName)){
//导出数据中需要增加加密列,先解密再加密
String value = DecryptUtils.getInstance().decrypt(resultSet.getString(i+1));
String value = DecryptUtils.getInstance().decrypt(enterpriseId,resultSet.getString(i+1));
if(org.apache.commons.lang3.StringUtils.isNotBlank(value)){
byte[] bytes = rsa.encrypt(StrUtil.bytes(value, CharsetUtil.UTF_8), KeyType.PublicKey);
String encode = Base64.encode(bytes);
......@@ -190,7 +190,7 @@ public class CsvResultSetHelper implements ResultSetHelper {
String tmpResult = resultSet.getString(i+1);
if (tmpResult != null && tmpResult.length() > 0) {
//tmpResult = DecryptUtils.getInstance().decrypt(tmpResult);
tmpResult = DecryptUtils.getInstance().decrypt(tmpResult);
tmpResult = DecryptUtils.getInstance().decrypt(enterpriseId,tmpResult);
if(tmpResult.startsWith("0")){
tmpResult = tmpResult + "\t";
}
......
......@@ -241,6 +241,7 @@ public class FlatQueryResultServiceImpl implements IFlatQueryResultService {
log.debug("getFlatQueryResult", "自助指标查询来自 " + enterpriseIds.get(0));
// 定义返回值
FlatQueryResult result = new FlatQueryResult();
String enterpriseId = enterpriseIds.get(0);
// 定义查询语句
String queryFull = this.buildFlatQuerySQL(
true, // 查询用途
......@@ -324,11 +325,11 @@ public class FlatQueryResultServiceImpl implements IFlatQueryResultService {
if(queryDataType == QueryDataType.FULL){
String preResult = rs.getString(fieldColumnIndex);
if(dataPermission == 1 && FilterFieldUtils.FILTERS_PHONE_ONLY.contains(fieldName)){
fieldResult = DecryptUtils.decrypt(preResult);
fieldResult = DecryptUtils.decrypt(enterpriseId,preResult);
} else if(dataPermission == 2 && FilterFieldUtils.FILTERS_PHONE_AND_CARD.contains(fieldName)){
fieldResult = DecryptUtils.decrypt(preResult);
fieldResult = DecryptUtils.decrypt(enterpriseId,preResult);
} else if (FilterFieldUtils.FILETERS_USER_NAME.contains(fieldName)){
fieldResult = DecryptUtils.decrypt(preResult);
fieldResult = DecryptUtils.decrypt(enterpriseId,preResult);
} else fieldResult = rs.getObject(fieldColumnIndex);
} else {
if(dataPermission == 1 && FilterFieldUtils.FILTERS_PHONE_ONLY.contains(fieldName)){
......@@ -336,7 +337,7 @@ public class FlatQueryResultServiceImpl implements IFlatQueryResultService {
} else if(dataPermission == 2 && FilterFieldUtils.FILTERS_PHONE_AND_CARD.contains(fieldName)){
fieldResult = "******";
} else if(FilterFieldUtils.FILETERS_USER_NAME.contains(fieldName)){
fieldResult = DecryptUtils.dataSecurityProcessUserName(DecryptUtils.decrypt(rs.getObject(fieldColumnIndex)+""));
fieldResult = DecryptUtils.dataSecurityProcessUserName(DecryptUtils.decrypt(enterpriseId,rs.getObject(fieldColumnIndex)+""));
} else fieldResult = rs.getObject(fieldColumnIndex);
}
......
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