Commit f481f72e by wuchao

新版本

parent b080293c
package com.chenyang.nse.bussiness.controller.core;
import com.chenyang.nse.bussiness.commmon.json.RespHelper;
import com.chenyang.nse.bussiness.commmon.json.Response;
import com.chenyang.nse.bussiness.config.PropertiesLoaderUtils;
import com.chenyang.nse.bussiness.dao.table.core.notice.SysLogDao;
import com.chenyang.nse.bussiness.entity.orm.table.core.notice.MailInformation;
import com.chenyang.nse.bussiness.entity.orm.table.core.notice.SnmpTrapInfomation;
import com.chenyang.nse.bussiness.entity.orm.table.core.notice.SyslogInfomation;
import com.chenyang.nse.bussiness.service.core.MailService;
import com.chenyang.nse.bussiness.service.core.SnmpTrapService;
import com.chenyang.nse.bussiness.tools.syslog.MySyslogClient;
import com.chenyang.nse.bussiness.tools.thread.GenericAsyProcess;
import com.chenyang.nse.bussiness.tools.trapServer.SnmpTrapSender;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.stream.Collectors;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping({"/core/dblog"})
public class DblogController {
private static Logger logger = LoggerFactory.getLogger(DblogController.class);
@Autowired
private MailService mailService;
@Autowired
private SnmpTrapService snmpTrapService;
@Autowired
private SysLogDao sysLogDao;
@Autowired
private JavaMailSender jms;
private static Properties props = new Properties();
private static String mailSubject = "";
private static String mailContent = "";
private static String mailTo = "";
@RequestMapping({"/sendAlertInfo"})
@ResponseBody
public Response sendAlertInfo(@RequestParam Map<String, String> params, HttpServletRequest request, HttpServletResponse response, Model model) {
String alarmtype = (String)params.get("alarmtype");
String alarmid = (String)params.get("alarmid");
if (StringUtils.isNotBlank(alarmtype)) {
if (alarmtype.equals("0")) {
List<MailInformation> mailList = this.mailService.queryAll();
if (StringUtils.isNotBlank(alarmid)) {
mailList = (List)mailList.stream().filter((log) -> log.getId().equalsIgnoreCase(alarmid)).collect(Collectors.toList());
}
if (mailList.size() > 0) {
MailInformation mail = (MailInformation)mailList.get(0);
mail.setMailsubject(mail.getMailsubject() == null ? mailSubject : mail.getMailsubject());
mail.setMailto(mailTo);
mail.setMailbody(mail.getMailbody() == null ? mailContent : mail.getMailbody());
GenericAsyProcess.asyCommitThreadPool("sendSimpleMail", this.mailService, mail);
}
} else if (alarmtype.equals("1")) {
List<SnmpTrapInfomation> snmpList = this.snmpTrapService.queryAll();
if (StringUtils.isNotBlank(alarmid)) {
snmpList = (List)snmpList.stream().filter((log) -> log.getId().equalsIgnoreCase(alarmid)).collect(Collectors.toList());
}
if (snmpList.size() > 0) {
SnmpTrapInfomation snmp = (SnmpTrapInfomation)snmpList.get(0);
SnmpTrapSender snmpTrapSender = new SnmpTrapSender();
GenericAsyProcess.asyCommitThreadPool("sendSnpm", snmpTrapSender, snmp.getSnmp_server_ip(), snmp.getPort());
}
} else if (alarmtype.equals("2")) {
List<SyslogInfomation> syslogList = this.sysLogDao.queryAll();
if (StringUtils.isNotBlank(alarmid)) {
syslogList = (List)syslogList.stream().filter((log) -> log.getId().equalsIgnoreCase(alarmid)).collect(Collectors.toList());
}
if (syslogList.size() > 0) {
SyslogInfomation syslog = (SyslogInfomation)syslogList.get(0);
MySyslogClient syslogClient = new MySyslogClient();
GenericAsyProcess.asyCommitThreadPool("sendSyslog", syslogClient, syslog.getHostname(), syslog.getPort().intValue());
}
}
}
return RespHelper.successResp();
}
static {
try {
props = PropertiesLoaderUtils.loadAllProperties("config.properties");
mailSubject = props.getProperty("mailSubject");
mailContent = props.getProperty("mailContent");
mailTo = props.getProperty("mailTo");
} catch (IOException e) {
e.printStackTrace();
}
}
}
package com.chenyang.nse.bussiness.controller.core;
import com.chenyang.nse.bussiness.commmon.json.RespHelper;
import com.chenyang.nse.bussiness.commmon.json.Response;
import com.chenyang.nse.bussiness.entity.orm.table.core.desensitizationtask.DesensitizationAlgorithm;
import com.chenyang.nse.bussiness.entity.orm.table.core.desensitizationtask.DesensitizationAlgorithmType;
import com.chenyang.nse.bussiness.service.core.DesensitizationAlgorithmService;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
@RequestMapping({"/core/desensitizationAlgorithm"})
public class DesensitizationAlgorithmController {
private static final Logger ddmauditLogger = LoggerFactory.getLogger("ddmauditLogger");
private static final Logger operationLogger = LoggerFactory.getLogger("operationLogger");
@Autowired
private DesensitizationAlgorithmService desensitizationAlgorithmService;
@GetMapping({"/querytype"})
@ResponseBody
public Response getType() {
List<DesensitizationAlgorithmType> desensitizationAlgorithmTypes = this.desensitizationAlgorithmService.queryTypeAll();
return RespHelper.successResp(desensitizationAlgorithmTypes);
}
@GetMapping({"/queryinfo"})
@ResponseBody
public Response getAlgorithmTypeInfo(@RequestParam("typeid") String typeid) {
List<DesensitizationAlgorithm> desensitizationAlgorithms = this.desensitizationAlgorithmService.queryInfoById(typeid);
return RespHelper.successResp(desensitizationAlgorithms);
}
@GetMapping({"/queryFunctionList"})
@ResponseBody
public Response queryFunction() {
List<DesensitizationAlgorithm> desensitizationAlgorithms = this.desensitizationAlgorithmService.queryAll();
return RespHelper.successResp(desensitizationAlgorithms);
}
@GetMapping({"/queryFunctionInfo"})
@ResponseBody
public Response queryFunctionInfo(String name) {
DesensitizationAlgorithm desensitizationAlgorithm = this.desensitizationAlgorithmService.queryInfoByName(name);
return RespHelper.successResp(desensitizationAlgorithm);
}
}
This source diff could not be displayed because it is too large. You can view the blob instead.
package com.chenyang.nse.bussiness.dao.table.core.desensitizationtask;
import com.chenyang.nse.bussiness.dao.BaseDao;
import com.chenyang.nse.bussiness.entity.orm.table.core.desensitizationtask.DesensitizationAlgorithm;
import org.springframework.stereotype.Repository;
@Repository
public class DesensitizationAlgorithmDao extends BaseDao<DesensitizationAlgorithm, String> {
}
package com.chenyang.nse.bussiness.dao.table.core.desensitizationtask;
import com.chenyang.nse.bussiness.dao.BaseDao;
import com.chenyang.nse.bussiness.entity.orm.table.core.desensitizationtask.DesensitizationAlgorithmType;
import org.springframework.stereotype.Repository;
@Repository
public class DesensitizationAlgorithmTypeDao extends BaseDao<DesensitizationAlgorithmType, String> {
}
package com.chenyang.nse.bussiness.dao.table.core.desensitizationtask;
import com.chenyang.nse.bussiness.dao.BaseDao;
import com.chenyang.nse.bussiness.entity.orm.table.core.desensitizationtask.DesensitizationDataSourcefield;
import org.springframework.stereotype.Repository;
@Repository
public class DesensitizationDataSourcefieldDao extends BaseDao<DesensitizationDataSourcefield, String> {
}
package com.chenyang.nse.bussiness.dao.table.core.desensitizationtask;
import com.chenyang.nse.bussiness.dao.BaseDao;
import com.chenyang.nse.bussiness.entity.orm.table.core.desensitizationtask.DesensitizationDataTargetfield;
import org.springframework.stereotype.Repository;
@Repository
public class DesensitizationDataTargetfieldDao extends BaseDao<DesensitizationDataTargetfield, String> {
}
package com.chenyang.nse.bussiness.dao.table.core.desensitizationtask;
import com.chenyang.nse.bussiness.dao.BaseDao;
import com.chenyang.nse.bussiness.dao.PageInfo;
import com.chenyang.nse.bussiness.entity.orm.table.core.desensitizationtask.DesensitizationDatamapping;
import com.chenyang.nse.bussiness.tools.xml.XmlTool;
import java.math.BigInteger;
import java.util.List;
import java.util.Map;
import org.hibernate.transform.Transformers;
import org.springframework.stereotype.Repository;
@Repository
public class DesensitizationDatamappingDao extends BaseDao<DesensitizationDatamapping, String> {
public List<Map<String, String>> getDatamappingInfo(String sourcesystemtype, String targetsystemtype) {
String sql = XmlTool.getSql("desensitizationdatamapping", "getDatamappingInfo");
List<Map<String, String>> list = this.getSession().createNativeQuery(sql).setParameter("sourcesystemtype", sourcesystemtype).setParameter("targetsystemtype", targetsystemtype).setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP).getResultList();
return list;
}
public List<Map<String, String>> getDatamappingInfo1(PageInfo pageinfo, String sourcesystemtype, String targetsystemtype) {
String sql = XmlTool.getSql("desensitizationdatamapping", "getDatamappingInfo1");
List<Map<String, String>> list = this.getSession().createNativeQuery(sql).setParameter("sourcesystemtype", sourcesystemtype).setParameter("targetsystemtype", targetsystemtype).setParameter("startno", (pageinfo.getPageno() - 1) * pageinfo.getPagesize()).setParameter("pagesize", pageinfo.getPagesize()).setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP).getResultList();
return list;
}
public BigInteger getDatamappingCount(String sourcesystemtype, String targetsystemtype) {
String sql = XmlTool.getSql("desensitizationdatamapping", "getDatamappingCount");
List<Map<String, BigInteger>> list = this.getSession().createNativeQuery(sql).setParameter("sourcesystemtype", sourcesystemtype).setParameter("targetsystemtype", targetsystemtype).setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP).getResultList();
return (BigInteger)((Map)list.get(0)).get("count");
}
public void updateIsdefault(String sql) {
this.getSession().createNativeQuery(sql.toString()).executeUpdate();
}
public List<Map<String, String>> getPwctypeBySourceType(String sourcesystemtype, String targetsystemtype, String sourcefieldname) {
String sql = XmlTool.getSql("desensitizationdatamapping", "getPwctypeBySourceType");
List<Map<String, String>> list = this.getSession().createNativeQuery(sql).setParameter("sourcesystemtype", sourcesystemtype).setParameter("targetsystemtype", targetsystemtype).setParameter("sourcefieldname", sourcefieldname).setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP).getResultList();
return list;
}
public List<Map<String, String>> getPwctypeList(String sourcesystemtype, String targetsystemtype) {
String sql = XmlTool.getSql("desensitizationdatamapping", "getPwctypeList");
List<Map<String, String>> list = this.getSession().createNativeQuery(sql).setParameter("sourcesystemtype", sourcesystemtype).setParameter("targetsystemtype", targetsystemtype).setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP).getResultList();
return list;
}
}
package com.chenyang.nse.bussiness.dao.table.core.desensitizationtask;
import com.chenyang.nse.bussiness.dao.BaseDao;
import com.chenyang.nse.bussiness.entity.orm.table.core.desensitizationtask.DesensitizationFile;
import org.springframework.stereotype.Repository;
@Repository
public class DesensitizationFileDao extends BaseDao<DesensitizationFile, String> {
}
package com.chenyang.nse.bussiness.dean.impl;
import com.datech.DaToSHCA.DaToSHCA;
import com.datech.DaToSHCA.da_handle;
import com.chenyang.nse.bussiness.dao.table.core.scheduler.TCoreSchedulerKmLogDao;
import com.chenyang.nse.bussiness.dao.table.core.scheduler.TCoreSchedulerKmRulesDao;
import com.chenyang.nse.bussiness.entity.orm.table.core.scheduler.TCoreSchedulerKmLog;
import com.chenyang.nse.bussiness.entity.orm.table.core.scheduler.TCoreSchedulerKmRules;
import com.chenyang.nse.bussiness.local.service.TestService;
import com.chenyang.nse.bussiness.service.key.KeyManagerService;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
@Service("DeAnTestServiceImpl")
public class DeAnTestServiceImpl implements TestService {
@Autowired
private TCoreSchedulerKmRulesDao tCoreSchedulerKmRulesDao;
@Autowired
private TCoreSchedulerKmLogDao tCoreSchedulerKmLogDao;
@Autowired
protected KeyManagerService keyManagerService;
public static da_handle tmpHandle = new da_handle();
public static DaToSHCA tmpTest = new DaToSHCA();
private static final Logger LOGGER = LoggerFactory.getLogger(DeAnTestServiceImpl.class);
@Autowired
protected JdbcTemplate jdbcTemplate;
private static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
public void test() {
try {
TestResult result = this.testDeAn();
this.saveTestResult(result);
} catch (Exception e) {
LOGGER.error(e.getMessage(), e);
}
}
public void initSecretKey() {
}
private void saveTestResult(TestResult result) {
TCoreSchedulerKmLog tCoreSchedulerKmLog = new TCoreSchedulerKmLog();
tCoreSchedulerKmLog.setId(UUID.randomUUID().toString().replace("-", ""));
tCoreSchedulerKmLog.setCreatetime(new Date());
tCoreSchedulerKmLog.setTestTime(new Date());
List<TCoreSchedulerKmRules> tCoreSchedulerKmRulesList = this.tCoreSchedulerKmRulesDao.queryAll();
if (null != tCoreSchedulerKmRulesList && tCoreSchedulerKmRulesList.size() > 0) {
tCoreSchedulerKmLog.setRulestype(((TCoreSchedulerKmRules)tCoreSchedulerKmRulesList.get(0)).getRulestype());
if (((TCoreSchedulerKmRules)tCoreSchedulerKmRulesList.get(0)).getHowtime().equals("")) {
tCoreSchedulerKmLog.setPollingRule("每天");
} else {
String[] arr1 = ((TCoreSchedulerKmRules)tCoreSchedulerKmRulesList.get(0)).getHowtime().split(",");
StringBuilder logBuilder = new StringBuilder();
for(int i = 0; i < arr1.length; ++i) {
if ("1".equals(arr1[i])) {
logBuilder.append("周一");
}
if ("2".equals(arr1[i])) {
logBuilder.append("周二");
}
if ("3".equals(arr1[i])) {
logBuilder.append("周三");
}
if ("4".equals(arr1[i])) {
logBuilder.append("周四");
}
if ("5".equals(arr1[i])) {
logBuilder.append("周五");
}
if ("6".equals(arr1[i])) {
logBuilder.append("周六");
}
if ("7".equals(arr1[i])) {
logBuilder.append("周日");
}
}
String pollingRule = "";
if (null != logBuilder && !"".equals(logBuilder)) {
pollingRule = logBuilder.toString();
tCoreSchedulerKmLog.setPollingRule(pollingRule);
}
}
} else {
tCoreSchedulerKmLog.setPollingRule("每天");
tCoreSchedulerKmLog.setRulestype("0");
}
if (result.success) {
tCoreSchedulerKmLog.setTestResult("1");
} else {
tCoreSchedulerKmLog.setTestResult("0");
}
if (null != result.message && !"".equals(result.message.toString())) {
tCoreSchedulerKmLog.setTestDetail(result.message.toString());
}
this.tCoreSchedulerKmLogDao.save(tCoreSchedulerKmLog);
}
private TestResult testDeAn() {
TestResult result = new TestResult();
Boolean testBool = this.testDecryptKey(result.message);
if (testBool) {
result.success = true;
}
return result;
}
private Boolean testDecryptKey(StringBuffer sb) {
sb.append(sdf.format(new Date()) + " INFO - 开始执行加密机加密校验:\r\n");
try {
Map<String, String> map = this.keyManagerService.showKeyParams("7");
boolean OpenFlag = tmpTest.DA_OpenHsmServer(tmpHandle, (String)map.get("ip"), Integer.parseInt((String)map.get("port")));
if (!OpenFlag) {
sb.append(sdf.format(new Date()) + " ERROR - [ERROR] DA_OpenHsmServer error ...");
return false;
}
sb.append(sdf.format(new Date()) + " INFO - [SUCCESS] DA_OpenHsmServer success ...");
byte[] inputData = tmpTest.DA_GenRandom(tmpHandle, 16);
String encrypt = tmpTest.DA_EncKeyNum(tmpHandle, (String)map.get("salg"), Integer.parseInt((String)map.get("keynum")), inputData);
if (null != encrypt && encrypt.length() > 0) {
sb.append(sdf.format(new Date()) + " INFO - 加密机加密成功。\r\n");
}
sb.append(sdf.format(new Date()) + " INFO - 开始执行加密机解密校验:\r\n");
byte[] decrypt = tmpTest.DA_DncKeyNum(tmpHandle, (String)map.get("salg"), Integer.parseInt((String)map.get("keynum")), encrypt);
if (null != decrypt && decrypt.length > 0) {
sb.append(sdf.format(new Date()) + " INFO - 加密机解密成功。\r\n");
}
tmpTest.DA_CloseHsmServer(tmpHandle);
} catch (Exception e) {
if (sb.toString().contains("加密机加密成功")) {
sb.append(sdf.format(new Date()) + " ERR - 校验加密机解密失败,异常为:");
} else {
sb.append(sdf.format(new Date()) + " ERR - 校验加密机加密失败,异常为:");
}
this.printException(sb, e);
sb.append("。\r\n");
return false;
}
return true;
}
private void printException(StringBuffer sb, Exception exception) {
sb.append(exception.toString());
}
static class TestResult {
boolean success = false;
StringBuffer message = new StringBuffer();
}
}
package com.chenyang.nse.bussiness.engine.ghca.webservice;
import java.net.MalformedURLException;
import java.net.URL;
import javax.xml.namespace.QName;
import javax.xml.ws.Service;
import javax.xml.ws.WebEndpoint;
import javax.xml.ws.WebServiceClient;
import javax.xml.ws.WebServiceException;
import javax.xml.ws.WebServiceFeature;
@WebServiceClient(
name = "DesensitizationEngineInterfaceImplService",
targetNamespace = "http://webservice/",
wsdlLocation = "http://127.0.0.1:12346/engine?wsdl"
)
public class DesensitizationEngineInterfaceImplService extends Service {
private static final URL DESENSITIZATIONENGINEINTERFACEIMPLSERVICE_WSDL_LOCATION;
private static final WebServiceException DESENSITIZATIONENGINEINTERFACEIMPLSERVICE_EXCEPTION;
private static final QName DESENSITIZATIONENGINEINTERFACEIMPLSERVICE_QNAME = new QName("http://webservice/", "DesensitizationEngineInterfaceImplService");
public DesensitizationEngineInterfaceImplService() {
super(__getWsdlLocation(), DESENSITIZATIONENGINEINTERFACEIMPLSERVICE_QNAME);
}
public DesensitizationEngineInterfaceImplService(WebServiceFeature... features) {
super(__getWsdlLocation(), DESENSITIZATIONENGINEINTERFACEIMPLSERVICE_QNAME, features);
}
public DesensitizationEngineInterfaceImplService(URL wsdlLocation) {
super(wsdlLocation, DESENSITIZATIONENGINEINTERFACEIMPLSERVICE_QNAME);
}
public DesensitizationEngineInterfaceImplService(URL wsdlLocation, WebServiceFeature... features) {
super(wsdlLocation, DESENSITIZATIONENGINEINTERFACEIMPLSERVICE_QNAME, features);
}
public DesensitizationEngineInterfaceImplService(URL wsdlLocation, QName serviceName) {
super(wsdlLocation, serviceName);
}
public DesensitizationEngineInterfaceImplService(URL wsdlLocation, QName serviceName, WebServiceFeature... features) {
super(wsdlLocation, serviceName, features);
}
@WebEndpoint(
name = "DesensitizationEngineInterfaceImplPort"
)
public DesensitizationEngineInterfaceImpl getDesensitizationEngineInterfaceImplPort() {
return (DesensitizationEngineInterfaceImpl)super.getPort(new QName("http://webservice/", "DesensitizationEngineInterfaceImplPort"), DesensitizationEngineInterfaceImpl.class);
}
@WebEndpoint(
name = "DesensitizationEngineInterfaceImplPort"
)
public DesensitizationEngineInterfaceImpl getDesensitizationEngineInterfaceImplPort(WebServiceFeature... features) {
return (DesensitizationEngineInterfaceImpl)super.getPort(new QName("http://webservice/", "DesensitizationEngineInterfaceImplPort"), DesensitizationEngineInterfaceImpl.class, features);
}
private static URL __getWsdlLocation() {
if (DESENSITIZATIONENGINEINTERFACEIMPLSERVICE_EXCEPTION != null) {
throw DESENSITIZATIONENGINEINTERFACEIMPLSERVICE_EXCEPTION;
} else {
return DESENSITIZATIONENGINEINTERFACEIMPLSERVICE_WSDL_LOCATION;
}
}
static {
URL url = null;
WebServiceException e = null;
try {
url = new URL("http://127.0.0.1:12346/engine?wsdl");
} catch (MalformedURLException ex) {
e = new WebServiceException(ex);
}
DESENSITIZATIONENGINEINTERFACEIMPLSERVICE_WSDL_LOCATION = url;
DESENSITIZATIONENGINEINTERFACEIMPLSERVICE_EXCEPTION = e;
}
}
package com.chenyang.nse.bussiness.entity.db;
import com.chenyang.nse.bussiness.enumeration.EdbType;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.apache.commons.lang3.StringUtils;
import org.apache.hive.jdbc.HiveQueryResultSet;
public class DbInfo {
private String databaseProductName;
private String databaseProductVersion;
private String driverVersion;
private String typeInfo;
public DbInfo() {
}
public DbInfo(String databaseProductName, String databaseProductVersion, String driverVersion, String typeInfo) {
this.databaseProductName = databaseProductName;
this.databaseProductVersion = databaseProductVersion;
this.driverVersion = driverVersion;
this.typeInfo = typeInfo;
}
public String getDatabaseProductName() {
return this.databaseProductName;
}
public void setDatabaseProductName(String databaseProductName) {
this.databaseProductName = databaseProductName;
}
public String getDatabaseProductVersion() {
return this.databaseProductVersion;
}
public void setDatabaseProductVersion(String databaseProductVersion) {
this.databaseProductVersion = databaseProductVersion;
}
public String getDriverVersion() {
return this.driverVersion;
}
public void setDriverVersion(String driverVersion) {
this.driverVersion = driverVersion;
}
public String getTypeInfo() {
return this.typeInfo;
}
public void setTypeInfo(String typeInfo) {
this.typeInfo = typeInfo;
}
public String toString() {
return "DbInfo [databaseProductName=" + this.databaseProductName + ", databaseProductVersion=" + this.databaseProductVersion + ", driverVersion=" + this.driverVersion + ", typeInfo=" + this.typeInfo + "]";
}
public static DbInfo getDbInfoByConnection(Connection conn) {
DbInfo dbinfo = null;
if (conn == null) {
return dbinfo;
} else {
DatabaseMetaData dbmd = null;
ResultSet rs = null;
try {
try {
dbmd = conn.getMetaData();
try {
rs = dbmd.getTypeInfo();
} catch (Exception var22) {
if (dbmd.getDatabaseProductName().toLowerCase().contains("postgres")) {
dbinfo = new DbInfo("GAUSS", dbmd.getDatabaseProductVersion(), dbmd.getDriverVersion(), (String)null);
DbInfo url = dbinfo;
return url;
}
}
try {
if (rs instanceof HiveQueryResultSet) {
if (conn.getMetaData().getURL().contains("transportMode")) {
dbinfo = new DbInfo("HIVE_TDH", dbmd.getDatabaseProductVersion(), (String)null, (String)null);
DbInfo var31 = dbinfo;
return var31;
}
dbinfo = new DbInfo("HIVE", dbmd.getDatabaseProductVersion(), dbmd.getDriverVersion(), (String)null);
DbInfo var30 = dbinfo;
return var30;
}
} catch (Exception var21) {
dbinfo = new DbInfo("HIVE_TDH", dbmd.getDatabaseProductVersion(), (String)null, (String)null);
DbInfo var32 = dbinfo;
return var32;
}
String type = null;
String url = dbmd.getURL();
if (StringUtils.isNotBlank(url) && url.contains("jdbc:oceanbase")) {
dbinfo = new DbInfo("OCEANBASE", dbmd.getDatabaseProductVersion(), dbmd.getDriverVersion(), type);
return dbinfo;
}
dbinfo = new DbInfo(dbmd.getDatabaseProductName(), dbmd.getDatabaseProductVersion(), dbmd.getDriverVersion(), type);
} catch (SQLException e) {
e.printStackTrace();
}
return dbinfo;
} finally {
try {
if (rs != null) {
rs.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}
public static EdbType getEdbTypeByConnection(Connection conn) {
DbInfo dbinfo = getDbInfoByConnection(conn);
String dbtype = dbinfo.getDatabaseProductName();
if (dbtype.replaceAll(" ", "").toUpperCase().contains("SQLSERVER")) {
return EdbType.MSSQLSERVER;
} else if (!dbtype.toUpperCase().equals("ASE") && !dbtype.replaceAll(" ", "").equalsIgnoreCase("AdaptiveServerEnterprise")) {
if (dbtype.toUpperCase().equals("HIVE_TDH")) {
return EdbType.HIVE_TDH;
} else if (dbtype.toUpperCase().equals("HIVE")) {
return EdbType.HIVE;
} else if (dbtype.equalsIgnoreCase("POSTGRESQL")) {
return EdbType.GREENPLUM;
} else if (dbtype.equalsIgnoreCase("HDB")) {
return EdbType.HANA;
} else {
for(String item : EdbType.getDbTypeList()) {
if (dbtype.toUpperCase().contains(item)) {
return EdbType.getEdbTypeByDbcode(item);
}
}
return null;
}
} else {
return EdbType.SYBASE;
}
}
}
package com.chenyang.nse.bussiness.entity.orm.table.core.desensitizationimgtask;
import com.chenyang.nse.bussiness.entity.orm.table.TBaseEntity;
import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.Table;
@Entity
@Table(
name = "DESENSITIZATIONIMGINFO"
)
public class DesensitizationImgInfo extends TBaseEntity implements Serializable {
private static final long serialVersionUID = -1L;
private String sourceDirPath;
private String maskingImgType;
private String maskingContent;
private String targetDirPath;
private String taskid;
public String getSourceDirPath() {
return this.sourceDirPath;
}
public void setSourceDirPath(String sourceDirPath) {
this.sourceDirPath = sourceDirPath;
}
public String getMaskingImgType() {
return this.maskingImgType;
}
public void setMaskingImgType(String maskingImgType) {
this.maskingImgType = maskingImgType;
}
public String getMaskingContent() {
return this.maskingContent;
}
public void setMaskingContent(String maskingContent) {
this.maskingContent = maskingContent;
}
public String getTargetDirPath() {
return this.targetDirPath;
}
public void setTargetDirPath(String targetDirPath) {
this.targetDirPath = targetDirPath;
}
public static long getSerialversionuid() {
return -1L;
}
public String getTaskid() {
return this.taskid;
}
public void setTaskid(String taskid) {
this.taskid = taskid;
}
}
package com.chenyang.nse.bussiness.entity.orm.table.core.desensitizationtask;
import com.chenyang.nse.bussiness.entity.orm.table.TBaseEntity;
import javax.persistence.Entity;
import javax.persistence.Table;
@Entity
@Table(
name = "t_console_algorithm"
)
public class DesensitizationAlgorithm extends TBaseEntity {
private String name;
private String remark;
private String inputtype;
private String outtype;
private String testexample;
private String algorithmtypeid;
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
public String getRemark() {
return this.remark;
}
public void setRemark(String remark) {
this.remark = remark;
}
public String getInputtype() {
return this.inputtype;
}
public void setInputtype(String inputtype) {
this.inputtype = inputtype;
}
public String getOuttype() {
return this.outtype;
}
public void setOuttype(String outtype) {
this.outtype = outtype;
}
public String getTestexample() {
return this.testexample;
}
public void setTestexample(String testexample) {
this.testexample = testexample;
}
public String getAlgorithmtypeid() {
return this.algorithmtypeid;
}
public void setAlgorithmtypeid(String algorithmtypeid) {
this.algorithmtypeid = algorithmtypeid;
}
}
package com.chenyang.nse.bussiness.entity.orm.table.core.desensitizationtask;
import com.chenyang.nse.bussiness.entity.orm.table.TBaseEntity;
import javax.persistence.Entity;
import javax.persistence.Table;
@Entity
@Table(
name = "DESENSITIZATION_DATA_TARGETFIELD"
)
public class DesensitizationDataTargetfield extends TBaseEntity {
private String datasystemtype;
private String fieldname;
public DesensitizationDataTargetfield() {
}
public DesensitizationDataTargetfield(String datasystemtype, String fieldname) {
this.datasystemtype = datasystemtype;
this.fieldname = fieldname;
}
public String getDatasystemtype() {
return this.datasystemtype;
}
public void setDatasystemtype(String datasystemtype) {
this.datasystemtype = datasystemtype;
}
public String getFieldname() {
return this.fieldname;
}
public void setFieldname(String fieldname) {
this.fieldname = fieldname;
}
public String toString() {
return "TConsoleDatamappingJdbcfield [datasystemtype=" + this.datasystemtype + ", fieldname=" + this.fieldname + "]";
}
public int hashCode() {
int prime = 31;
int result = 1;
result = 31 * result + (this.datasystemtype == null ? 0 : this.datasystemtype.hashCode());
result = 31 * result + (this.fieldname == null ? 0 : this.fieldname.hashCode());
return result;
}
public boolean equals(Object obj) {
if (this == obj) {
return true;
} else if (obj == null) {
return false;
} else if (this.getClass() != obj.getClass()) {
return false;
} else {
DesensitizationDataTargetfield other = (DesensitizationDataTargetfield)obj;
if (this.datasystemtype == null) {
if (other.datasystemtype != null) {
return false;
}
} else if (!this.datasystemtype.equals(other.datasystemtype)) {
return false;
}
if (this.fieldname == null) {
if (other.fieldname != null) {
return false;
}
} else if (!this.fieldname.equals(other.fieldname)) {
return false;
}
return true;
}
}
}
package com.chenyang.nse.bussiness.entity.orm.table.core.desensitizationtask;
import com.chenyang.nse.bussiness.entity.orm.table.TBaseEntity;
import javax.persistence.Entity;
import javax.persistence.Table;
@Entity
@Table(
name = "DESENSITIZATION_DATA_MAPPING"
)
public class DesensitizationDatamapping extends TBaseEntity {
private String sourcefieldid;
private String targetfieldid;
private String targetlength;
private String targetdecimal;
private String isdefault;
private String targetsystemtype;
private String sourcesystemtype;
private String pwcsrclength;
private String pwcsrcscale;
private String pwcsqlength;
private String pwcsqscale;
private String pwcdateformat;
private String sourcedefault;
public String getSourcedefault() {
return this.sourcedefault;
}
public void setSourcedefault(String sourcedefault) {
this.sourcedefault = sourcedefault;
}
public String getPwcdateformat() {
return this.pwcdateformat;
}
public void setPwcdateformat(String pwcdateformat) {
this.pwcdateformat = pwcdateformat;
}
public String getPwcsrclength() {
return this.pwcsrclength;
}
public void setPwcsrclength(String pwcsrclength) {
this.pwcsrclength = pwcsrclength;
}
public String getPwcsrcscale() {
return this.pwcsrcscale;
}
public void setPwcsrcscale(String pwcsrcscale) {
this.pwcsrcscale = pwcsrcscale;
}
public String getPwcsqlength() {
return this.pwcsqlength;
}
public void setPwcsqlength(String pwcsqlength) {
this.pwcsqlength = pwcsqlength;
}
public String getPwcsqscale() {
return this.pwcsqscale;
}
public void setPwcsqscale(String pwcsqscale) {
this.pwcsqscale = pwcsqscale;
}
public String getSourcesystemtype() {
return this.sourcesystemtype;
}
public void setSourcesystemtype(String sourcesystemtype) {
this.sourcesystemtype = sourcesystemtype;
}
public String getIsdefault() {
return this.isdefault;
}
public void setIsdefault(String isdefault) {
this.isdefault = isdefault;
}
public DesensitizationDatamapping() {
}
public DesensitizationDatamapping(String sourcefieldid, String targetfieldid, String targetlength, String targetdecimal, String targetsystemtype) {
this.sourcefieldid = sourcefieldid;
this.targetfieldid = targetfieldid;
this.targetlength = targetlength;
this.targetdecimal = targetdecimal;
this.targetsystemtype = targetsystemtype;
}
public String getSourcefieldid() {
return this.sourcefieldid;
}
public void setSourcefieldid(String sourcefieldid) {
this.sourcefieldid = sourcefieldid;
}
public String getTargetfieldid() {
return this.targetfieldid;
}
public void setTargetfieldid(String targetfieldid) {
this.targetfieldid = targetfieldid;
}
public String getTargetlength() {
return this.targetlength;
}
public void setTargetlength(String targetlength) {
this.targetlength = targetlength;
}
public String getTargetdecimal() {
return this.targetdecimal;
}
public void setTargetdecimal(String targetdecimal) {
this.targetdecimal = targetdecimal;
}
public String getTargetsystemtype() {
return this.targetsystemtype;
}
public void setTargetsystemtype(String targetsystemtype) {
this.targetsystemtype = targetsystemtype;
}
public String toString() {
return "TConsoleDatamappingInfo [sourcefieldid=" + this.sourcefieldid + ", targetfieldid=" + this.targetfieldid + ", targetlength=" + this.targetlength + ", targetdecimal=" + this.targetdecimal + ", targetsystemtype=" + this.targetsystemtype + "]";
}
public int hashCode() {
int prime = 31;
int result = 1;
result = 31 * result + (this.sourcefieldid == null ? 0 : this.sourcefieldid.hashCode());
result = 31 * result + (this.targetdecimal == null ? 0 : this.targetdecimal.hashCode());
result = 31 * result + (this.targetfieldid == null ? 0 : this.targetfieldid.hashCode());
result = 31 * result + (this.targetlength == null ? 0 : this.targetlength.hashCode());
result = 31 * result + (this.targetsystemtype == null ? 0 : this.targetsystemtype.hashCode());
return result;
}
public boolean equals(Object obj) {
if (this == obj) {
return true;
} else if (obj == null) {
return false;
} else if (this.getClass() != obj.getClass()) {
return false;
} else {
DesensitizationDatamapping other = (DesensitizationDatamapping)obj;
if (this.sourcefieldid == null) {
if (other.sourcefieldid != null) {
return false;
}
} else if (!this.sourcefieldid.equals(other.sourcefieldid)) {
return false;
}
if (this.targetdecimal == null) {
if (other.targetdecimal != null) {
return false;
}
} else if (!this.targetdecimal.equals(other.targetdecimal)) {
return false;
}
if (this.targetfieldid == null) {
if (other.targetfieldid != null) {
return false;
}
} else if (!this.targetfieldid.equals(other.targetfieldid)) {
return false;
}
if (this.targetlength == null) {
if (other.targetlength != null) {
return false;
}
} else if (!this.targetlength.equals(other.targetlength)) {
return false;
}
if (this.targetsystemtype == null) {
if (other.targetsystemtype != null) {
return false;
}
} else if (!this.targetsystemtype.equals(other.targetsystemtype)) {
return false;
}
return true;
}
}
}
package com.chenyang.nse.bussiness.entity.orm.table.core.desensitizationtask;
import com.chenyang.nse.bussiness.entity.orm.table.TBaseEntity;
import javax.persistence.Entity;
import javax.persistence.Table;
@Entity
@Table(
name = "DESENSITIZATIONFILE"
)
public class DesensitizationFile extends TBaseEntity {
private String filedir;
private String codepage;
private String suffix;
private String dateformat;
private String delimiters;
private String quotecharacter;
private int filetype;
private String ip;
private String port;
private String username;
private String userpassword;
private String taskid;
private String repeatEmptyCharacter;
private String divisionType;
public String getRepeatEmptyCharacter() {
return this.repeatEmptyCharacter;
}
public void setRepeatEmptyCharacter(String repeatEmptyCharacter) {
this.repeatEmptyCharacter = repeatEmptyCharacter;
}
public String getDivisionType() {
return this.divisionType;
}
public void setDivisionType(String divisionType) {
this.divisionType = divisionType;
}
public String getFiledir() {
return this.filedir;
}
public void setFiledir(String filedir) {
this.filedir = filedir;
}
public String getCodepage() {
return this.codepage;
}
public void setCodepage(String codepage) {
this.codepage = codepage;
}
public String getSuffix() {
return this.suffix;
}
public void setSuffix(String suffix) {
this.suffix = suffix;
}
public String getDateformat() {
return this.dateformat;
}
public void setDateformat(String dateformat) {
this.dateformat = dateformat;
}
public String getDelimiters() {
return this.delimiters;
}
public void setDelimiters(String delimiters) {
this.delimiters = delimiters;
}
public String getQuotecharacter() {
return this.quotecharacter;
}
public void setQuotecharacter(String quotecharacter) {
this.quotecharacter = quotecharacter;
}
public int getFiletype() {
return this.filetype;
}
public void setFiletype(int filetype) {
this.filetype = filetype;
}
public String getIp() {
return this.ip;
}
public void setIp(String ip) {
this.ip = ip;
}
public String getPort() {
return this.port;
}
public void setPort(String port) {
this.port = port;
}
public String getUsername() {
return this.username;
}
public void setUsername(String username) {
this.username = username;
}
public String getUserpassword() {
return this.userpassword;
}
public void setUserpassword(String userpassword) {
this.userpassword = userpassword;
}
public String getTaskid() {
return this.taskid;
}
public void setTaskid(String taskid) {
this.taskid = taskid;
}
}
package com.chenyang.nse.bussiness.entity.orm.table.core.rule.conditions;
import com.chenyang.nse.bussiness.entity.orm.table.TBaseEntity;
import javax.persistence.Entity;
import javax.persistence.Table;
@Entity
@Table(
name = "t_console_dbuserconditions"
)
public class DbuserConditions extends TBaseEntity {
private String matchsymbol;
private String matchval;
private String ruleid;
public String getMatchsymbol() {
return this.matchsymbol;
}
public void setMatchsymbol(String matchsymbol) {
this.matchsymbol = matchsymbol;
}
public String getMatchval() {
return this.matchval;
}
public void setMatchval(String matchval) {
this.matchval = matchval;
}
public String getRuleid() {
return this.ruleid;
}
public void setRuleid(String ruleid) {
this.ruleid = ruleid;
}
}
package com.chenyang.nse.bussiness.entity.vo;
public class DBTableVO implements Comparable<DBTableVO> {
private String datasystemid;
private String schema;
private String tablename;
private String status;
public DBTableVO() {
}
public DBTableVO(String datasystemid, String schema, String tablename, String status) {
this.datasystemid = datasystemid;
this.schema = schema;
this.tablename = tablename;
this.status = status;
}
public String getDatasystemid() {
return this.datasystemid;
}
public void setDatasystemid(String datasystemid) {
this.datasystemid = datasystemid;
}
public String getSchema() {
return this.schema;
}
public void setSchema(String schema) {
this.schema = schema;
}
public String getTablename() {
return this.tablename;
}
public void setTablename(String tablename) {
this.tablename = tablename;
}
public String getStatus() {
return this.status;
}
public void setStatus(String status) {
this.status = status;
}
public String toString() {
return "DBTableVO [datasystemid=" + this.datasystemid + ", schema=" + this.schema + ", tablename=" + this.tablename + ", status=\" + status + \"]";
}
public int hashCode() {
int prime = 31;
int result = 1;
result = 31 * result + (this.datasystemid == null ? 0 : this.datasystemid.hashCode());
result = 31 * result + (this.schema == null ? 0 : this.schema.hashCode());
result = 31 * result + (this.status == null ? 0 : this.status.hashCode());
result = 31 * result + (this.tablename == null ? 0 : this.tablename.hashCode());
return result;
}
public boolean equals(Object obj) {
if (this == obj) {
return true;
} else if (obj == null) {
return false;
} else if (this.getClass() != obj.getClass()) {
return false;
} else {
DBTableVO other = (DBTableVO)obj;
if (this.datasystemid == null) {
if (other.datasystemid != null) {
return false;
}
} else if (!this.datasystemid.equals(other.datasystemid)) {
return false;
}
if (this.schema == null) {
if (other.schema != null) {
return false;
}
} else if (!this.schema.equals(other.schema)) {
return false;
}
if (this.status == null) {
if (other.status != null) {
return false;
}
} else if (!this.status.equals(other.status)) {
return false;
}
if (this.tablename == null) {
if (other.tablename != null) {
return false;
}
} else if (!this.tablename.equals(other.tablename)) {
return false;
}
return true;
}
}
public int compareTo(DBTableVO v) {
return this.getTablename().compareTo(v.getTablename());
}
}
package com.chenyang.nse.bussiness.job;
import com.chenyang.nse.bussiness.config.PropertiesLoaderUtils;
import com.chenyang.nse.bussiness.service.core.SchedulerService;
import com.chenyang.nse.bussiness.tools.io.FileTool;
import java.io.IOException;
import java.util.Properties;
import org.quartz.DisallowConcurrentExecution;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.context.support.SpringBeanAutowiringSupport;
@DisallowConcurrentExecution
public class DelefolderTaskJob implements Job {
@Autowired
private SchedulerService schedulerService;
public void execute(JobExecutionContext context) throws JobExecutionException {
SpringBeanAutowiringSupport.processInjectionBasedOnCurrentContext(this);
try {
System.out.println("开始删除文件任务啦");
new Properties();
try {
Properties e = PropertiesLoaderUtils.loadAllProperties("config.properties");
String path = "/F:/java/.metadata/.plugins/org.eclipse.wst.server.core/tmp1/wtpwebapps/ghca-platform/WEB-INF/classes/";
path = this.getClass().getClassLoader().getResource("").getPath();
path = path.replaceAll("WEB-INF/classes/", "");
path = path.substring(1, path.length());
System.out.println(path);
FileTool.delAllFile(path + e.getProperty("file_down_path"));
FileTool.delAllFile(path + e.getProperty("file_up_path"));
} catch (IOException e) {
e.printStackTrace();
}
System.out.println("删除文件任务执行完成啦");
} catch (Exception e) {
e.printStackTrace();
}
}
}
package com.chenyang.nse.bussiness.service.console;
import com.chenyang.nse.bussiness.dao.PageInfo;
import com.chenyang.nse.bussiness.entity.orm.table.core.desensitizationtask.DesensitizationDataTargetfield;
import com.chenyang.nse.bussiness.entity.orm.table.core.desensitizationtask.DesensitizationDatamapping;
import com.chenyang.nse.bussiness.entity.vo.DataGridVO;
import java.math.BigInteger;
import java.util.List;
import java.util.Map;
public interface DesensitizationDataMappingService {
List<Map<String, String>> getDatamappingInfo(String sourcesystemtype, String targetsystemtype);
List<Map<String, String>> getDatamappingInfo1(PageInfo pageinfo, String sourcesystemtype, String targetsystemtype);
BigInteger getDatamappingCount(String sourcesystemtype, String targetsystemtype);
DataGridVO<DesensitizationDatamapping> selectDatamappingInfo(PageInfo pageinfo, String sourcesystemtype, String targetsystemtype);
List<DesensitizationDataTargetfield> getTargetFieldByType(String datasystemtype);
void modifyDataInfo(Map<String, String> map);
void deletedatainfo(String mappingid, String sourceid);
void insertDataInfo(Map<String, String> map);
void removedatainfo(String sourcefieldid);
List<Map<String, String>> getPwctypeBySourceType(String sourcesystemtype, String targetsystemtype, String sourcefieldname);
List<Map<String, String>> getPwctypeBySourcelist(String sourcesystemtype, String targetsystemtype);
}
package com.chenyang.nse.bussiness.test;
import java.io.UnsupportedEncodingException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
public class Db2test {
public static void main(String[] args) throws ClassNotFoundException, SQLException, UnsupportedEncodingException {
String url = "jdbc:db2://192.168.2.216:50000/ghca";
String driver = "com.ibm.db2.jcc.DB2Driver";
String passwd = "db2inst1";
String user = "db2inst1";
Class.forName(driver);
Connection conn = DriverManager.getConnection(url, passwd, user);
PreparedStatement ps = null;
createTable(conn, ps);
ps.close();
conn.close();
System.out.println("over");
}
public static void createTable(Connection conn, PreparedStatement ps) throws SQLException {
String sql = "CREATE TABLE YSL.EXPLAIN_STREAM(\tEXPLAIN_REQUESTER VARCHAR(128) NOT NULL,EXPLAIN_TIME TIMESTAMP NOT NULL,SOURCE_NAME VARCHAR(128) NOT NULL,SOURCE_SCHEMA VARCHAR(128) NOT NULL,SOURCE_VERSION VARCHAR(64) NOT NULL,EXPLAIN_LEVEL CHAR(1) NOT NULL,STMTNO INTEGER NOT NULL,SECTNO INTEGER NOT NULL,STREAM_ID INTEGER,SOURCE_TYPE CHAR(1),SOURCE_ID INTEGER,TARGET_TYPE CHAR(1),TARGET_ID INTEGER,OBJECT_SCHEMA VARCHAR(128),OBJECT_NAME VARCHAR(128),STREAM_COUNT DOUBLE,COLUMN_COUNT SMALLINT,PREDICATE_ID INTEGER,COLUMN_NAMES CLOB,PMID SMALLINT,SINGLE_NODE CHAR(5),PARTITION_COLUMNS CLOB,SEQUENCE_SIZES CLOB) ";
ps = conn.prepareStatement(sql);
ps.execute();
}
}
package com.chenyang.nse.bussiness.tools.encryption;
import com.chenyang.nse.bussiness.config.PropertiesLoaderUtils;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
import java.security.InvalidKeyException;
import java.security.Key;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.security.Security;
import java.security.spec.InvalidKeySpecException;
import java.util.Properties;
import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.KeyGenerator;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.DESedeKeySpec;
import org.apache.commons.codec.DecoderException;
import org.apache.commons.codec.binary.Hex;
import org.apache.commons.lang3.StringUtils;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.bouncycastle.pqc.math.linearalgebra.ByteUtils;
public class DES3Util {
private static final String ENCODING = "UTF-8";
public static final String ALGORITHM_NAME = "DESede";
public static final int DEFAULT_KEY_SIZE = 168;
private static final String ALGORITHM_NAME_CBC_PADDING = "DESede/CBC/PKCS5Padding";
private static final String ALGORITHM_NAME_ECB_PADDING = "DESede/ECB/PKCS5Padding";
private static Properties properties;
private static String ENCRYPT_LIKE_SPLIT;
private static final String ENCRYPT_LIKE_OPEN = "1";
public static String generateKey() throws Exception {
return new String(Hex.encodeHex(generateKey(168), false));
}
static byte[] generateKey(int keySize) throws Exception {
KeyGenerator kg = KeyGenerator.getInstance("DESede");
kg.init(keySize, new SecureRandom());
return kg.generateKey().getEncoded();
}
private static Key getSecretKey(byte[] key) {
try {
DESedeKeySpec spec = new DESedeKeySpec(key);
SecretKeyFactory keyfactory = SecretKeyFactory.getInstance("DESede");
return keyfactory.generateSecret(spec);
} catch (InvalidKeyException var3) {
throw new RuntimeException("DES获取密钥出现错误,非法key异常");
} catch (NoSuchAlgorithmException var4) {
throw new RuntimeException("DES获取密钥出现错误,算法异常");
} catch (InvalidKeySpecException var5) {
throw new RuntimeException("DES获取密钥出现错误,密钥规范异常");
}
}
public static String encryptEcb(String hexKey, String paramStr, String isLike, String keepfirst, String encdigit, String twoindex, String... encryptMode) throws DecoderException, NoSuchPaddingException, IllegalBlockSizeException, UnsupportedEncodingException, NoSuchAlgorithmException, InvalidKeySpecException, BadPaddingException, InvalidKeyException {
try {
String cipherText = "";
byte[] key = hexKey.getBytes(StandardCharsets.UTF_8);
Key secretKey = getSecretKey(key);
String prefix = null;
String enc = paramStr;
String suffix = null;
String encryptModeSwitch = "ECB";
if (encryptMode.length > 0) {
encryptModeSwitch = encryptMode[0];
}
if (!StringUtils.isBlank(keepfirst)) {
if (!"0".equals(keepfirst) && !"1".equals(keepfirst)) {
if (!"2".equals(keepfirst)) {
return paramStr;
}
int first = 0;
if (StringUtils.isNotBlank(encdigit)) {
first = Integer.parseInt(encdigit);
}
int last = 0;
if (StringUtils.isNotBlank(twoindex)) {
last = Integer.parseInt(twoindex);
}
if (first + last >= paramStr.length() || first >= paramStr.length() || last >= paramStr.length()) {
return paramStr;
}
prefix = paramStr.substring(0, first);
enc = paramStr.substring(first, paramStr.length() - last);
suffix = paramStr.substring(paramStr.length() - last);
} else if (StringUtils.isNotBlank(encdigit)) {
if (Integer.parseInt(encdigit) >= paramStr.length()) {
return paramStr;
}
if (Integer.parseInt(encdigit) != 0) {
if ("0".equals(keepfirst)) {
prefix = paramStr.substring(0, Integer.parseInt(encdigit));
enc = paramStr.substring(Integer.parseInt(encdigit));
} else if ("1".equals(keepfirst)) {
enc = paramStr.substring(0, paramStr.length() - Integer.parseInt(encdigit));
suffix = paramStr.substring(paramStr.length() - Integer.parseInt(encdigit));
}
}
}
}
if ("1".equals(isLike)) {
StringBuilder sb = new StringBuilder();
int i = 0;
while(i < enc.length()) {
char c = enc.charAt(i);
byte[] srcData = (c + "").getBytes("UTF-8");
byte[] cipherArray = new byte[0];
switch (encryptModeSwitch) {
case "ECB":
cipherArray = encrypt_Ecb_Padding(secretKey, srcData);
default:
cipherText = ByteUtils.toHexString(cipherArray);
sb.append(cipherText).append(ENCRYPT_LIKE_SPLIT);
++i;
}
}
cipherText = sb.deleteCharAt(sb.length() - 1).toString();
} else {
byte[] srcData = enc.getBytes("UTF-8");
byte[] cipherArray = new byte[0];
switch (encryptModeSwitch) {
case "ECB":
cipherArray = encrypt_Ecb_Padding(secretKey, srcData);
default:
cipherText = ByteUtils.toHexString(cipherArray);
}
}
if ("0".equals(keepfirst) && null != prefix) {
cipherText = prefix + cipherText;
} else if ("1".equals(keepfirst) && null != suffix) {
cipherText = cipherText + suffix;
} else if ("2".equals(keepfirst)) {
if (null != prefix) {
cipherText = prefix + cipherText;
}
if (null != suffix) {
cipherText = cipherText + suffix;
}
}
return cipherText;
} catch (Exception var21) {
return paramStr;
}
}
public static byte[] encrypt_Ecb_Padding(Key key, byte[] data) throws Exception {
Cipher cipher = generateEcbCipher("DESede/ECB/PKCS5Padding", 1, key);
return cipher.doFinal(data);
}
private static Cipher generateEcbCipher(String algorithmName, int mode, Key key) throws Exception {
Cipher cipher = Cipher.getInstance("DESede/ECB/PKCS5Padding");
cipher.init(mode, key);
return cipher;
}
public static String decryptEcb(String hexKey, String paramStr, String isLike, String keepfirst, String encdigit, String twoindex, String... encryptMode) throws Exception {
String decryptStr = "";
try {
byte[] srcData = new byte[0];
byte[] key = hexKey.getBytes(StandardCharsets.UTF_8);
Key secretKey = getSecretKey(key);
String prefix = null;
String enc = paramStr;
String suffix = null;
String encryptModeSwitch = "ECB";
if (encryptMode.length > 0) {
encryptModeSwitch = encryptMode[0];
}
if (!StringUtils.isBlank(encdigit)) {
if (!"0".equals(keepfirst) && !"1".equals(keepfirst)) {
if (!"2".equals(keepfirst)) {
return paramStr;
}
int first = 0;
if (StringUtils.isNotBlank(encdigit)) {
first = Integer.parseInt(encdigit);
}
int last = 0;
if (StringUtils.isNotBlank(twoindex)) {
last = Integer.parseInt(twoindex);
}
if (first + last >= paramStr.length() || first >= paramStr.length() || last >= paramStr.length()) {
return paramStr;
}
prefix = paramStr.substring(0, first);
enc = paramStr.substring(first, paramStr.length() - last);
suffix = paramStr.substring(paramStr.length() - last);
} else if (StringUtils.isNotBlank(encdigit)) {
if (Integer.parseInt(encdigit) >= paramStr.length()) {
return paramStr;
}
if (Integer.parseInt(encdigit) != 0) {
if ("0".equals(keepfirst)) {
prefix = paramStr.substring(0, Integer.parseInt(encdigit));
enc = paramStr.substring(Integer.parseInt(encdigit));
} else if ("1".equals(keepfirst)) {
suffix = paramStr.substring(paramStr.length() - Integer.parseInt(encdigit));
enc = paramStr.substring(0, paramStr.length() - Integer.parseInt(encdigit));
}
}
}
}
if ("1".equals(isLike)) {
StringBuilder sb = new StringBuilder();
String[] split = enc.split(ENCRYPT_LIKE_SPLIT);
for(String s : split) {
byte[] cipherData = ByteUtils.fromHexString(s);
try {
switch (encryptModeSwitch) {
case "ECB":
srcData = decrypt_Ecb_Padding(secretKey, cipherData);
default:
decryptStr = new String(srcData, "UTF-8");
sb.append(decryptStr);
}
} catch (Exception e) {
e.printStackTrace();
}
}
decryptStr = sb.toString();
} else {
byte[] cipherData = ByteUtils.fromHexString(enc);
switch (encryptModeSwitch) {
case "ECB":
srcData = decrypt_Ecb_Padding(secretKey, cipherData);
default:
decryptStr = new String(srcData, "UTF-8");
}
}
if ("0".equals(keepfirst) && null != prefix) {
decryptStr = prefix + decryptStr;
} else if ("1".equals(keepfirst) && null != suffix) {
decryptStr = decryptStr + suffix;
} else if ("2".equals(keepfirst)) {
if (null != prefix) {
decryptStr = prefix + decryptStr;
}
if (null != suffix) {
decryptStr = decryptStr + suffix;
}
}
return decryptStr;
} catch (Exception e) {
throw e;
}
}
public static byte[] decrypt_Ecb_Padding(Key key, byte[] cipherText) throws Exception {
Cipher cipher = generateEcbCipher("DESede/ECB/PKCS5Padding", 2, key);
return cipher.doFinal(cipherText);
}
public static void main(String[] args) throws Exception {
System.out.println("------------------3DES加密之ECB加密、解密------------------");
String desKey = generateKey();
String plainText = "https://blog.csdn.net/Alian_1223";
System.out.println("ECB加密原始数据:" + plainText);
System.out.println("ECB加密密钥:" + desKey);
String encode = encryptEcb(desKey, plainText, "1", "0", "0", "0", "ECB");
System.out.println("ECB加密后的数据:" + encode);
String decodeStr = decryptEcb(desKey, encode, "1", "0", "0", "0", "ECB");
System.out.println("ECB解密后转字符串数据:" + decodeStr);
}
static {
try {
properties = PropertiesLoaderUtils.loadAllProperties("config.properties");
ENCRYPT_LIKE_SPLIT = properties.get("encryption.like.split").toString();
} catch (IOException e) {
e.printStackTrace();
}
Security.addProvider(new BouncyCastleProvider());
}
}
package com.chenyang.nse.bussiness.tools.logger.dblog;
import com.alibaba.fastjson.JSONObject;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.graylog2.syslog4j.Syslog;
import org.graylog2.syslog4j.SyslogIF;
import org.graylog2.syslog4j.impl.net.udp.UDPNetSyslogConfig;
public class DblogClient {
private static final String HOST = "192.168.2.218";
private static final int PORT = 40000;
private static final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
public static void inputAuditLog(String username, String sql) {
JSONObject jsonObject = new JSONObject();
jsonObject.put("datetime", sdf.format(new Date()));
jsonObject.put("username", username);
jsonObject.put("sql", sql);
jsonObject.put("type", "2");
generate(jsonObject.toString());
}
public static void inputMaksingLog(String username, String sql, String columnLabel, String oldValue, String newValue, String expression) {
JSONObject jsonObject = new JSONObject();
jsonObject.put("datetime", sdf.format(new Date()));
jsonObject.put("username", username);
jsonObject.put("sql", sql);
jsonObject.put("columnLabel", columnLabel);
jsonObject.put("oldValue", oldValue);
jsonObject.put("newValue", newValue);
jsonObject.put("expression", expression);
jsonObject.put("type", "1");
generate(jsonObject.toString());
}
public static void inputMaksingLog(String jsonstr) {
generate(jsonstr);
}
private static void generate(String message) {
SyslogIF syslog = Syslog.getInstance("udp");
UDPNetSyslogConfig udpConfig = (UDPNetSyslogConfig)syslog.getConfig();
udpConfig.setMaxMessageLength(10240);
syslog.getConfig().setHost("192.168.2.218");
syslog.getConfig().setPort(40000);
try {
message = message.replaceAll("%(?![0-9a-fA-F]{2})", "%25");
message = message.replaceAll("\\+", "%2B");
syslog.log(0, URLDecoder.decode(message, "utf-8"));
} catch (UnsupportedEncodingException e) {
System.out.println("generate log get exception " + e);
}
}
public static void main(String[] args) {
inputMaksingLog("{\"query\":\"SELECT * from dual\",\"responseinfo\":\"阻断\",\"exequery\":\"SELECT * from dual\",\"datetime\":\"2021-04-26 11:12:34\",\"accesstool\":\"dberror\",\"accessorip\":\"10.10.10.10\",\"accessormac\":\"jkjk:jijj-iokjfodsfd\",\"accessoruser\":\"zhangsan\",\"action\":\"1\",\"sqltype\":\"select\",\"matchrule\":\"rule1\",\"policyname\":\"策略1\",\"matchstatus\":\"1\",\"exestatus\":\"1\",\"datasourceid\":\"1\",\"type\":\"1\",\"alarmtype\":\"0\",\"alarmid\":\"32d31b0224a745d2a961c53f0491fc95\",\"auditswitch\":\"0\"}");
}
}
package com.chenyang.nse.bussiness.webtools.entity.db;
import com.chenyang.nse.bussiness.webtools.enumeration.EdbType;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.apache.commons.lang3.StringUtils;
public class DbInfo {
private String databaseProductName;
private String databaseProductVersion;
private String driverVersion;
private String typeInfo;
public DbInfo() {
}
public DbInfo(String databaseProductName, String databaseProductVersion, String driverVersion, String typeInfo) {
this.databaseProductName = databaseProductName;
this.databaseProductVersion = databaseProductVersion;
this.driverVersion = driverVersion;
this.typeInfo = typeInfo;
}
public String getDatabaseProductName() {
return this.databaseProductName;
}
public void setDatabaseProductName(String databaseProductName) {
this.databaseProductName = databaseProductName;
}
public String getDatabaseProductVersion() {
return this.databaseProductVersion;
}
public void setDatabaseProductVersion(String databaseProductVersion) {
this.databaseProductVersion = databaseProductVersion;
}
public String getDriverVersion() {
return this.driverVersion;
}
public void setDriverVersion(String driverVersion) {
this.driverVersion = driverVersion;
}
public String getTypeInfo() {
return this.typeInfo;
}
public void setTypeInfo(String typeInfo) {
this.typeInfo = typeInfo;
}
public String toString() {
return "DbInfo [databaseProductName=" + this.databaseProductName + ", databaseProductVersion=" + this.databaseProductVersion + ", driverVersion=" + this.driverVersion + ", typeInfo=" + this.typeInfo + "]";
}
public static DbInfo getDbInfoByConnection(Connection conn) {
DbInfo dbinfo = null;
if (conn == null) {
return dbinfo;
} else {
DatabaseMetaData dbmd = null;
ResultSet rs = null;
try {
dbmd = conn.getMetaData();
rs = dbmd.getTypeInfo();
String type = null;
String url = dbmd.getURL();
if (StringUtils.isNotBlank(url) && url.contains("jdbc:oceanbase")) {
dbinfo = new DbInfo("OCEANBASE", dbmd.getDatabaseProductVersion(), dbmd.getDriverVersion(), type);
} else {
dbinfo = new DbInfo(dbmd.getDatabaseProductName(), dbmd.getDatabaseProductVersion(), dbmd.getDriverVersion(), type);
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
try {
if (rs != null) {
rs.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
}
return dbinfo;
}
}
public static EdbType getEdbTypeByConnection(Connection conn) {
DatabaseMetaData metaData = null;
String dbtype = "";
try {
metaData = conn.getMetaData();
dbtype = metaData.getDatabaseProductName();
} catch (SQLException e) {
throw new RuntimeException(e);
}
if (dbtype.replaceAll(" ", "").toUpperCase().contains("SQLSERVER")) {
return EdbType.MSSQLSERVER;
} else if (!dbtype.toUpperCase().equals("ASE") && !dbtype.replaceAll(" ", "").equalsIgnoreCase("AdaptiveServerEnterprise")) {
if (dbtype.toUpperCase().contains("HIVE")) {
return EdbType.HIVE;
} else if (dbtype.equalsIgnoreCase("POSTGRESQL")) {
return EdbType.GREENPLUM;
} else if (dbtype.equalsIgnoreCase("HDB")) {
return EdbType.HANA;
} else {
for(String item : EdbType.getDbTypeList()) {
if (dbtype.toUpperCase().contains(item)) {
return EdbType.getEdbTypeByDbcode(item);
}
}
return null;
}
} else {
return EdbType.SYBASE;
}
}
}
package com.chenyang.nse.bussiness.webtools.entity.vo;
public class DBTableVO implements Comparable<DBTableVO> {
private String datasystemid;
private String schema;
private String tablename;
private String status;
String tableComments = "";
String tableSpace = "";
public DBTableVO() {
}
public DBTableVO(String datasystemid, String schema, String tablename, String status) {
this.datasystemid = datasystemid;
this.schema = schema;
this.tablename = tablename;
this.status = status;
}
public String getDatasystemid() {
return this.datasystemid;
}
public void setDatasystemid(String datasystemid) {
this.datasystemid = datasystemid;
}
public String getSchema() {
return this.schema;
}
public void setSchema(String schema) {
this.schema = schema;
}
public String getTablename() {
return this.tablename;
}
public void setTablename(String tablename) {
this.tablename = tablename;
}
public String getStatus() {
return this.status;
}
public void setStatus(String status) {
this.status = status;
}
public String toString() {
return "DBTableVO [datasystemid=" + this.datasystemid + ", schema=" + this.schema + ", tablename=" + this.tablename + ", status=\" + status + \"]";
}
public int hashCode() {
int prime = 31;
int result = 1;
result = 31 * result + (this.datasystemid == null ? 0 : this.datasystemid.hashCode());
result = 31 * result + (this.schema == null ? 0 : this.schema.hashCode());
result = 31 * result + (this.status == null ? 0 : this.status.hashCode());
result = 31 * result + (this.tablename == null ? 0 : this.tablename.hashCode());
return result;
}
public boolean equals(Object obj) {
if (this == obj) {
return true;
} else if (obj == null) {
return false;
} else if (this.getClass() != obj.getClass()) {
return false;
} else {
DBTableVO other = (DBTableVO)obj;
if (this.datasystemid == null) {
if (other.datasystemid != null) {
return false;
}
} else if (!this.datasystemid.equals(other.datasystemid)) {
return false;
}
if (this.schema == null) {
if (other.schema != null) {
return false;
}
} else if (!this.schema.equals(other.schema)) {
return false;
}
if (this.status == null) {
if (other.status != null) {
return false;
}
} else if (!this.status.equals(other.status)) {
return false;
}
if (this.tablename == null) {
if (other.tablename != null) {
return false;
}
} else if (!this.tablename.equals(other.tablename)) {
return false;
}
return true;
}
}
public int compareTo(DBTableVO v) {
return this.getTablename().compareTo(v.getTablename());
}
}
<?xml version="1.0" encoding="UTF-8"?>
<sql>
<select id="getDatamappingInfo">
select
info.id as id,
ds.id as sourcefieldid,
ds.fieldname as sourcefieldname,
info.flag as flag,
dt.id as targetfieldid,
dt.fieldname as targetfieldname,
info.targetlength as targetlength,
info.targetdecimal as targetdecimal,
info.pwcsrclength as sourcelength,
info.pwcsrcscale as sourcescancale,
info.pwcsqlength as pwcsqlength,
info.pwcsqscale as pwcsqscale,
info.isdefault as isdefault,
info.sourcedefault as sourcedefault,
info.pwcdateformat as pwcdateformat,
info.note as note
from
desensitization_data_sourcefield ds left join desensitization_data_mapping info on
(
ds.id = info.sourcefieldid and info.targetsystemtype = :targetsystemtype
) left join desensitization_data_targetfield dt on
(
dt.id = info.targetfieldid
)
where
ds.datasystemtype = :sourcesystemtype
order by
ds.fieldname
</select>
<select id="getDatamappingInfo1">
select
info.id as id,
ds.id as sourcefieldid,
ds.fieldname as sourcefieldname,
info.flag as flag,
dt.id as targetfieldid,
dt.fieldname as targetfieldname,
info.targetlength as targetlength,
info.targetdecimal as targetdecimal,
info.pwcsrclength as sourcelength,
info.pwcsrcscale as sourcescancale,
info.pwcsqlength as pwcsqlength,
info.pwcsqscale as pwcsqscale,
info.isdefault as isdefault,
info.sourcedefault as sourcedefault,
info.pwcdateformat as pwcdateformat,
info.note as note
from
desensitization_data_sourcefield ds left join desensitization_data_mapping info on
(
ds.td = info.sourcefieldid and info.targetsystemtype = :targetsystemtype
) left join desensitization_data_targetfield dt on
(
dt.id = info.targetfieldid
)
where
ds.datasystemtype = :sourcesystemtype
order by
ds.fieldname
limit
:startno , :pagesize
</select>
<select id="getDatamappingCount">
select
count(1) count
from
desensitization_data_sourcefield ds left join desensitization_data_mapping info on
(
ds.id = info.sourcefieldid and info.targetsystemtype = :targetsystemtype
) left join desensitization_data_targetfield dt on
(
dt.id = info.targetfieldid
)
where
ds.datasystemtype = :sourcesystemtype
</select>
<select id = "getPwctypeBySourceType">
select
dt.fieldname as pwctype
from
desensitization_data_sourcefield ds left join desensitization_data_mapping info on
(
ds.id = info.sourcefieldid and info.targetsystemtype = :targetsystemtype
) left join desensitization_data_targetfield dt on
(
dt.id = info.targetfieldid
)
where
ds.datasystemtype = :sourcesystemtype
and ds.fieldname = :sourcefieldname
and info.sourcedefault = '1'
</select>
<select id = "getPwctypeList">
select
ds.fieldname as columntype;
dt.fieldname as pwctype
from
desensitization_data_sourcefield ds left join desensitization_data_mapping info on
(
ds.id = info.sourcefieldid and info.targetsystemtype = :targetsystemtype
) left join desensitization_data_targetfield dt on
(
dt.id = info.targetfieldid
)
where
ds.datasystemtype = :sourcesystemtype
and ds.fieldname = :sourcefieldname
and info.sourcedefault = '1'
</select>
</sql>
\ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论