2018-11-26 14:34:24 +08:00
|
|
|
|
package com.nis.web.service.configuration;
|
|
|
|
|
|
|
|
|
|
|
|
import java.lang.reflect.Field;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
|
|
|
|
|
|
|
import net.sf.json.JSONObject;
|
|
|
|
|
|
|
|
|
|
|
|
import org.apache.poi.ss.formula.functions.T;
|
|
|
|
|
|
import org.dom4j.Node;
|
|
|
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
|
|
|
|
import antlr.StringUtils;
|
|
|
|
|
|
|
2018-11-28 12:00:25 +08:00
|
|
|
|
import com.google.common.collect.Lists;
|
2018-11-26 14:34:24 +08:00
|
|
|
|
import com.nis.domain.FunctionServiceDict;
|
|
|
|
|
|
import com.nis.domain.Page;
|
2018-11-27 16:57:08 +08:00
|
|
|
|
import com.nis.domain.basics.AsnIpCfg;
|
2018-11-28 19:58:34 +08:00
|
|
|
|
import com.nis.domain.configuration.AppFeatureIndex;
|
2018-11-26 14:34:24 +08:00
|
|
|
|
import com.nis.domain.configuration.AppPolicyCfg;
|
|
|
|
|
|
import com.nis.domain.configuration.AvFileSampleCfg;
|
|
|
|
|
|
import com.nis.domain.configuration.BaseCfg;
|
|
|
|
|
|
import com.nis.domain.configuration.BaseStringCfg;
|
|
|
|
|
|
import com.nis.domain.configuration.CfgIndexInfo;
|
|
|
|
|
|
import com.nis.domain.configuration.ComplexkeywordCfg;
|
|
|
|
|
|
import com.nis.domain.configuration.DdosIpCfg;
|
|
|
|
|
|
import com.nis.domain.configuration.DnsIpCfg;
|
|
|
|
|
|
import com.nis.domain.configuration.DnsResStrategy;
|
|
|
|
|
|
import com.nis.domain.configuration.FileDigestCfg;
|
|
|
|
|
|
import com.nis.domain.configuration.IpPortCfg;
|
|
|
|
|
|
import com.nis.domain.configuration.PxyObjKeyring;
|
|
|
|
|
|
import com.nis.domain.configuration.PxyObjTrustedCaCert;
|
|
|
|
|
|
import com.nis.domain.configuration.PxyObjTrustedCaCrl;
|
|
|
|
|
|
import com.nis.domain.maat.MaatCfg;
|
|
|
|
|
|
import com.nis.domain.maat.ToMaatBean;
|
|
|
|
|
|
import com.nis.domain.maat.ToMaatResult;
|
|
|
|
|
|
import com.nis.domain.maat.MaatCfg.DigestCfg;
|
|
|
|
|
|
import com.nis.domain.maat.MaatCfg.GroupCfg;
|
|
|
|
|
|
import com.nis.domain.maat.MaatCfg.IpCfg;
|
|
|
|
|
|
import com.nis.domain.maat.MaatCfg.NumBoundaryCfg;
|
|
|
|
|
|
import com.nis.domain.maat.MaatCfg.StringCfg;
|
|
|
|
|
|
import com.nis.util.ConfigServiceUtil;
|
|
|
|
|
|
import com.nis.util.Constants;
|
|
|
|
|
|
import com.nis.util.DateUtils;
|
|
|
|
|
|
import com.nis.util.DictUtils;
|
|
|
|
|
|
import com.nis.util.ServiceConfigTemplateUtil;
|
|
|
|
|
|
import com.nis.util.StringUtil;
|
2018-11-29 10:59:54 +08:00
|
|
|
|
import com.nis.web.dao.configuration.CommonPolicyDao;
|
2018-11-26 14:34:24 +08:00
|
|
|
|
import com.nis.web.dao.configuration.ConfigSynchronizationDao;
|
|
|
|
|
|
import com.nis.web.security.UserUtils;
|
|
|
|
|
|
import com.nis.web.service.BaseService;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 配置全量同步事务类
|
|
|
|
|
|
* @author zhangwei
|
|
|
|
|
|
*
|
|
|
|
|
|
*/
|
|
|
|
|
|
@Service
|
|
|
|
|
|
public class ConfigSynchronizationService extends BaseService{
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
protected ConfigSynchronizationDao configSynchronizationDao;
|
2018-11-29 10:59:54 +08:00
|
|
|
|
@Autowired
|
|
|
|
|
|
protected CommonPolicyDao commonPolicyDao;
|
2018-11-26 14:34:24 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 配置全量更新下发
|
|
|
|
|
|
* @param request
|
|
|
|
|
|
* @param response
|
|
|
|
|
|
* @throws IllegalAccessException
|
|
|
|
|
|
* @throws IllegalArgumentException
|
|
|
|
|
|
* @throws SecurityException
|
|
|
|
|
|
* @throws NoSuchFieldException
|
|
|
|
|
|
* @throws ClassNotFoundException
|
|
|
|
|
|
*/
|
|
|
|
|
|
public void send(HttpServletRequest request,HttpServletResponse response,BaseCfg cfg) throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException, ClassNotFoundException {
|
|
|
|
|
|
long start = System.currentTimeMillis();
|
|
|
|
|
|
ServiceConfigTemplateUtil serviceTemplate = new ServiceConfigTemplateUtil();
|
|
|
|
|
|
if(cfg==null){
|
|
|
|
|
|
List<Map<String,Object>> serviceList = serviceTemplate.getServiceList();
|
|
|
|
|
|
for(Map<String,Object> service:serviceList){
|
|
|
|
|
|
String tableName = service.get("tableName").toString();
|
|
|
|
|
|
String serviceType = service.get("serviceType").toString();
|
|
|
|
|
|
String className = service.get("className").toString();
|
|
|
|
|
|
String serviceId = service.get("id").toString();
|
|
|
|
|
|
BaseCfg entity = new BaseCfg();
|
|
|
|
|
|
entity.setServiceId(Integer.valueOf(serviceId));
|
|
|
|
|
|
entity.setIsAudit(1);
|
|
|
|
|
|
entity.setIsValid(1);
|
2018-11-28 19:58:34 +08:00
|
|
|
|
entity.setTableName(tableName);
|
2018-11-26 14:34:24 +08:00
|
|
|
|
if("1".equals(serviceType)){//maat类配置
|
|
|
|
|
|
List<Map<String,Object>> cfgList = (List<Map<String, Object>>) service.get("cfgList");
|
|
|
|
|
|
List<Map<String,Object>> userRegionList = (List<Map<String, Object>>) service.get("userRegionList");
|
2018-11-28 19:58:34 +08:00
|
|
|
|
if(cfgList.size()>0){
|
|
|
|
|
|
Page page=new Page(request,response,Constants.MAAT_JSON_SEND_SIZE,"a");
|
|
|
|
|
|
handleNtcMaatData(cfgList,userRegionList,page,entity,request,response,false,tableName);
|
|
|
|
|
|
}else{
|
|
|
|
|
|
int cfgType = Integer.parseInt(service.get("cfgType").toString());
|
|
|
|
|
|
if("ddos_ip_cfg".equals(tableName)){
|
|
|
|
|
|
Page<DdosIpCfg> page=new Page<DdosIpCfg>(request,response,Constants.MAAT_JSON_SEND_SIZE,"a");
|
|
|
|
|
|
handleDdosMaatData(cfgList,userRegionList,page,entity,request,response,false);
|
|
|
|
|
|
}else{
|
|
|
|
|
|
Page<T> page=new Page<T>(request,response,Constants.MAAT_JSON_SEND_SIZE,"a");
|
|
|
|
|
|
handleSingleMaatData(cfgType,userRegionList,page,entity,request,response,false);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
/*if("cfg_index_info".equals(tableName)){
|
2018-11-26 14:34:24 +08:00
|
|
|
|
Page<CfgIndexInfo> page=new Page<CfgIndexInfo>(request,response,Constants.MAAT_JSON_SEND_SIZE,"a");
|
|
|
|
|
|
handleNtcMaatData(cfgList,userRegionList,page,entity,request,response,false);
|
|
|
|
|
|
}else if("ddos_ip_cfg".equals(tableName)){
|
|
|
|
|
|
Page<DdosIpCfg> page=new Page<DdosIpCfg>(request,response,Constants.MAAT_JSON_SEND_SIZE,"a");
|
|
|
|
|
|
handleDdosMaatData(cfgList,userRegionList,page,entity,request,response,false);
|
2018-11-28 19:58:34 +08:00
|
|
|
|
}*/
|
2018-11-26 14:34:24 +08:00
|
|
|
|
}else if("2".equals(serviceType)){//回调类配置
|
|
|
|
|
|
entity.setTableName(tableName);
|
|
|
|
|
|
entity.setServiceId(Integer.valueOf(serviceId));
|
|
|
|
|
|
Page<BaseCfg> page=new Page<BaseCfg>(request,response,Constants.MAAT_JSON_SEND_SIZE,"a");
|
|
|
|
|
|
handleCallbackData(className,page,entity,request,response,false);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
long end = System.currentTimeMillis();
|
|
|
|
|
|
logger.info("本次配置全量同步,开始时间:"+start
|
|
|
|
|
|
+",结束时间:"+end
|
|
|
|
|
|
+",共计花费"+((end-start)/1000+"秒"));
|
|
|
|
|
|
}else{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 处理ntc业务maat类配置
|
|
|
|
|
|
* @param serviceId
|
|
|
|
|
|
* @param request
|
|
|
|
|
|
* @param response
|
|
|
|
|
|
* @throws SecurityException
|
|
|
|
|
|
* @throws NoSuchFieldException
|
|
|
|
|
|
* @throws IllegalAccessException
|
|
|
|
|
|
* @throws IllegalArgumentException
|
|
|
|
|
|
*/
|
|
|
|
|
|
public void handleNtcMaatData(List<Map<String,Object>>cfgList,List<Map<String,Object>>userRegionList,
|
2018-11-28 19:58:34 +08:00
|
|
|
|
Page<T> page,BaseCfg entity,HttpServletRequest request,HttpServletResponse response,
|
|
|
|
|
|
boolean isUpdateCfg,String tableName) throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException{
|
2018-11-26 14:34:24 +08:00
|
|
|
|
|
|
|
|
|
|
boolean hasData = true;
|
|
|
|
|
|
while(hasData){
|
|
|
|
|
|
entity.setPage(page);
|
2018-11-28 19:58:34 +08:00
|
|
|
|
List list = Lists.newArrayList();
|
|
|
|
|
|
if("cfg_index_info".equals(tableName)){
|
|
|
|
|
|
list = configSynchronizationDao.getCfgIndexList(entity);
|
|
|
|
|
|
if(!StringUtil.isEmpty(list)){
|
|
|
|
|
|
hasData=auditNtcMaatData(cfgList,userRegionList,page,entity,list,hasData,isUpdateCfg);
|
|
|
|
|
|
if(hasData) {
|
|
|
|
|
|
page.setPageNo(page.getNext());
|
|
|
|
|
|
}
|
|
|
|
|
|
}else{
|
|
|
|
|
|
hasData = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}else if("app_policy_cfg".equals(tableName)){
|
|
|
|
|
|
list = configSynchronizationDao.getAppPolicyList(entity);
|
|
|
|
|
|
if(!StringUtil.isEmpty(list)){
|
|
|
|
|
|
hasData=auditAppPolicyData(cfgList,userRegionList,page,entity,list,hasData,isUpdateCfg);
|
|
|
|
|
|
if(hasData) {
|
|
|
|
|
|
page.setPageNo(page.getNext());
|
|
|
|
|
|
}
|
|
|
|
|
|
}else{
|
|
|
|
|
|
hasData = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}else if("app_feature_index".equals(tableName)){
|
|
|
|
|
|
list = configSynchronizationDao.getAppFeatureIndexList(entity);
|
|
|
|
|
|
if(!StringUtil.isEmpty(list)){
|
|
|
|
|
|
hasData=auditAppFeatureData(cfgList,userRegionList,page,entity,list,hasData,isUpdateCfg);
|
|
|
|
|
|
if(hasData) {
|
|
|
|
|
|
page.setPageNo(page.getNext());
|
|
|
|
|
|
}
|
|
|
|
|
|
}else{
|
|
|
|
|
|
hasData = false;
|
2018-11-26 14:34:24 +08:00
|
|
|
|
}
|
2018-11-27 16:17:51 +08:00
|
|
|
|
}else{
|
2018-11-28 19:58:34 +08:00
|
|
|
|
logger.info("全量同步未知业务");
|
2018-11-27 16:17:51 +08:00
|
|
|
|
hasData = false;
|
|
|
|
|
|
}
|
2018-11-28 19:58:34 +08:00
|
|
|
|
|
2018-11-27 16:17:51 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
|
|
|
* MAAT配置批量下发
|
|
|
|
|
|
* @param cfgList
|
|
|
|
|
|
* @param userRegionList
|
|
|
|
|
|
* @param page
|
|
|
|
|
|
* @param entity
|
|
|
|
|
|
* @param list
|
|
|
|
|
|
* @param hasData
|
|
|
|
|
|
* @param isUpdateCfg 业务配置全部生效时需同步更新库表配置状态
|
|
|
|
|
|
* @return
|
|
|
|
|
|
* @throws NoSuchFieldException
|
|
|
|
|
|
* @throws SecurityException
|
|
|
|
|
|
* @throws IllegalArgumentException
|
|
|
|
|
|
* @throws IllegalAccessException
|
|
|
|
|
|
*/
|
|
|
|
|
|
public boolean auditNtcMaatData(List<Map<String,Object>> cfgList,
|
|
|
|
|
|
List<Map<String,Object>> userRegionList,
|
|
|
|
|
|
Page page,
|
|
|
|
|
|
BaseCfg entity,
|
|
|
|
|
|
List<CfgIndexInfo> list,
|
|
|
|
|
|
boolean hasData,
|
|
|
|
|
|
boolean isUpdateCfg)throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException{
|
|
|
|
|
|
ToMaatBean maatBean;
|
|
|
|
|
|
MaatCfg maatCfg;
|
|
|
|
|
|
List<MaatCfg> configCompileList;
|
|
|
|
|
|
List<GroupCfg> groupRelationList;
|
|
|
|
|
|
List<IpCfg> ipRegionList;
|
|
|
|
|
|
List<StringCfg> strRegionList;
|
|
|
|
|
|
List<NumBoundaryCfg> numRegionList;
|
|
|
|
|
|
List<DigestCfg> digestRegionList;
|
|
|
|
|
|
List<IpCfg> areaIpRegionList;
|
|
|
|
|
|
|
|
|
|
|
|
List<IpPortCfg> ipList = new ArrayList();
|
2018-11-27 16:57:08 +08:00
|
|
|
|
List<AsnIpCfg> asnIpList = new ArrayList();
|
2018-11-27 16:17:51 +08:00
|
|
|
|
List<BaseStringCfg> strList = new ArrayList();
|
|
|
|
|
|
List<ComplexkeywordCfg> complexStrList = new ArrayList();
|
|
|
|
|
|
List<com.nis.domain.configuration.NumBoundaryCfg> numList = new ArrayList();
|
|
|
|
|
|
List<FileDigestCfg> fileList = new ArrayList();
|
|
|
|
|
|
maatBean = new ToMaatBean();
|
|
|
|
|
|
configCompileList = new ArrayList();
|
|
|
|
|
|
List<Integer> compileIds = new ArrayList();
|
2018-11-27 16:57:08 +08:00
|
|
|
|
List<String> asnGroupIds = new ArrayList();
|
2018-11-27 16:17:51 +08:00
|
|
|
|
for(CfgIndexInfo cfg:list){
|
|
|
|
|
|
compileIds.add(cfg.getCompileId());
|
2018-11-27 16:57:08 +08:00
|
|
|
|
if(entity.getServiceId().equals(37)||entity.getServiceId().equals(149)){
|
|
|
|
|
|
asnGroupIds.add(cfg.getUserRegion4());
|
|
|
|
|
|
}
|
2018-11-27 16:17:51 +08:00
|
|
|
|
}
|
2018-11-29 10:59:54 +08:00
|
|
|
|
|
|
|
|
|
|
if(isUpdateCfg) {
|
|
|
|
|
|
if(!StringUtil.isEmpty(compileIds) && !StringUtil.isEmpty(entity.getTableName())) {
|
|
|
|
|
|
commonPolicyDao.auditCfgBatch( entity.getTableName(), entity,compileIds,null);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-11-27 16:17:51 +08:00
|
|
|
|
if(cfgList!=null){
|
|
|
|
|
|
for(Map<String,Object> m:cfgList){
|
|
|
|
|
|
String tableName = m.get("tableName").toString();
|
|
|
|
|
|
if("1".equals(m.get("cfgType"))){
|
|
|
|
|
|
if(tableName.equals("asn_ip_cfg")){
|
2018-11-28 15:27:49 +08:00
|
|
|
|
if(!StringUtil.isEmpty(asnGroupIds)) {
|
|
|
|
|
|
asnIpList.addAll(configSynchronizationDao.getAsnIpList(asnGroupIds));
|
|
|
|
|
|
}
|
2018-11-27 16:17:51 +08:00
|
|
|
|
}else{
|
|
|
|
|
|
ipList.addAll(configSynchronizationDao.getIpPortList(tableName, compileIds));
|
2018-11-26 14:34:24 +08:00
|
|
|
|
}
|
2018-11-27 16:17:51 +08:00
|
|
|
|
}else if("2".equals(m.get("cfgType"))){
|
|
|
|
|
|
strList.addAll(configSynchronizationDao.getStrList(tableName,compileIds));
|
|
|
|
|
|
}else if("3".equals(m.get("cfgType"))){
|
|
|
|
|
|
complexStrList.addAll(configSynchronizationDao.getComplexStrList(tableName,compileIds));
|
|
|
|
|
|
}else if("4".equals(m.get("cfgType"))){
|
|
|
|
|
|
|
|
|
|
|
|
}else if("5".equals(m.get("cfgType"))){
|
|
|
|
|
|
fileList.addAll(configSynchronizationDao.getFileDigestList(tableName, compileIds));
|
2018-11-26 14:34:24 +08:00
|
|
|
|
}
|
2018-11-29 10:59:54 +08:00
|
|
|
|
if(isUpdateCfg) {
|
|
|
|
|
|
if(tableName.equals("asn_ip_cfg")){
|
|
|
|
|
|
if(!StringUtil.isEmpty(asnGroupIds)) {
|
|
|
|
|
|
commonPolicyDao.auditCfgBatch(tableName, entity,asnGroupIds,null);
|
|
|
|
|
|
}
|
|
|
|
|
|
}else{
|
|
|
|
|
|
commonPolicyDao.auditCfgBatch( tableName, entity,compileIds,null);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2018-11-27 16:17:51 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2018-11-28 12:00:25 +08:00
|
|
|
|
//批量获取regionId,groupId(相同编译下的IP类配置多条ip只获取一个组号),分组复用的域配置不需要重新获取regionId,groupId
|
|
|
|
|
|
List<Integer> regionIds = ConfigServiceUtil.getId(3, ipList.size()+strList.size()+complexStrList.size()+numList.size()+fileList.size());
|
|
|
|
|
|
List<Integer> groupIds = ConfigServiceUtil.getId(2, strList.size()+complexStrList.size()+numList.size()+fileList.size());
|
2018-11-27 16:17:51 +08:00
|
|
|
|
for(CfgIndexInfo cfg:list){
|
|
|
|
|
|
maatCfg = new MaatCfg();
|
|
|
|
|
|
maatCfg.initDefaultValue();
|
|
|
|
|
|
groupRelationList = new ArrayList();
|
|
|
|
|
|
ipRegionList = new ArrayList();
|
|
|
|
|
|
strRegionList = new ArrayList();
|
|
|
|
|
|
numRegionList = new ArrayList();
|
|
|
|
|
|
digestRegionList = new ArrayList();
|
|
|
|
|
|
areaIpRegionList = new ArrayList();
|
2018-11-27 16:57:08 +08:00
|
|
|
|
List list1 = new ArrayList();
|
2018-11-27 16:17:51 +08:00
|
|
|
|
List<BaseStringCfg> list2 = new ArrayList();
|
|
|
|
|
|
List<ComplexkeywordCfg> list3 = new ArrayList();
|
|
|
|
|
|
List<com.nis.domain.configuration.NumBoundaryCfg> list4 = new ArrayList();
|
|
|
|
|
|
List<FileDigestCfg> list5 = new ArrayList();
|
|
|
|
|
|
String userRegion = "";
|
|
|
|
|
|
//处理自定义域
|
|
|
|
|
|
if(userRegionList!=null){
|
|
|
|
|
|
for(Map<String,Object> n:userRegionList){
|
|
|
|
|
|
Object userRegionPosition = n.get("userRegionPosition");
|
|
|
|
|
|
if(userRegionPosition!=null && (userRegionPosition.toString().equals("1")||userRegionPosition.toString().equals("0"))){
|
|
|
|
|
|
//通过反射机制获取自定义域字段值
|
|
|
|
|
|
String regionColumn = n.get("regionColumn").toString();
|
|
|
|
|
|
Class aClass = null;
|
|
|
|
|
|
if(userRegionPosition.toString().equals(("0"))){
|
|
|
|
|
|
aClass = BaseCfg.class;
|
|
|
|
|
|
}else{
|
|
|
|
|
|
aClass = CfgIndexInfo.class;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Object value = "";
|
|
|
|
|
|
if(entity.getServiceId().equals(517)||entity.getServiceId().equals(560)){//代理替换策略
|
|
|
|
|
|
String[] regionArray = regionColumn.split(",");
|
|
|
|
|
|
for(int r=0;r<regionArray.length;r++){
|
|
|
|
|
|
Field field = aClass.getDeclaredField(regionArray[r]);
|
|
|
|
|
|
field.setAccessible(true);
|
2018-11-28 12:00:25 +08:00
|
|
|
|
if(n.get("regionKey").equals("substitute")){
|
|
|
|
|
|
value += "/"+replaceContentEscape(field.get(cfg)==null?"":field.get(cfg).toString());//自定义域以/分割时的处理
|
|
|
|
|
|
}else{
|
|
|
|
|
|
value += replaceContentEscape(field.get(cfg)==null?"":field.get(cfg).toString());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-11-27 16:17:51 +08:00
|
|
|
|
}
|
|
|
|
|
|
userRegion += n.get("regionKey")+"="+value+Constants.USER_REGION_SPLIT;
|
|
|
|
|
|
}else{
|
|
|
|
|
|
Field field = aClass.getDeclaredField(regionColumn);
|
|
|
|
|
|
field.setAccessible(true);
|
|
|
|
|
|
value = field.get(cfg);
|
|
|
|
|
|
if(!StringUtil.isEmpty(value)){
|
|
|
|
|
|
if(StringUtil.isEmpty(n.get("regionKey"))){
|
|
|
|
|
|
userRegion = value.toString();
|
2018-11-26 14:34:24 +08:00
|
|
|
|
}else{
|
|
|
|
|
|
userRegion += n.get("regionKey")+"="+value+Constants.USER_REGION_SPLIT;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2018-11-27 16:17:51 +08:00
|
|
|
|
// System.out.println("userRegionList:"+n.get("regionKey")+","+n.get("regionColumn")+","+n.get("handleType"));
|
|
|
|
|
|
}
|
|
|
|
|
|
if(userRegion.endsWith(Constants.USER_REGION_SPLIT)){
|
|
|
|
|
|
userRegion = userRegion.substring(0, userRegion.length()-1);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2018-11-28 12:00:25 +08:00
|
|
|
|
if(ipList.size()>0){
|
|
|
|
|
|
List<Integer> ipGroupId = ConfigServiceUtil.getId(2,1);//多条IP只获取一个groupId
|
|
|
|
|
|
for(int index=0;index<ipList.size();index++){
|
|
|
|
|
|
IpPortCfg ip = ipList.get(index);
|
|
|
|
|
|
if(ip.getCompileId().equals(cfg.getCompileId())){
|
2018-11-28 19:58:34 +08:00
|
|
|
|
// BeanUtils.copyProperties(cfg, ip);
|
|
|
|
|
|
ip.setRegionId(regionIds.get(0));
|
|
|
|
|
|
regionIds.remove(0);
|
2018-11-28 12:00:25 +08:00
|
|
|
|
ip.setGroupId(ipGroupId.get(0));
|
2018-11-28 15:27:49 +08:00
|
|
|
|
ip.setIsValid(entity.getIsValid());
|
2018-11-29 09:23:31 +08:00
|
|
|
|
ip.setAuditTime(StringUtil.isEmpty(entity.getAuditTime()) ? cfg.getAuditTime():entity.getAuditTime());
|
2018-11-28 12:00:25 +08:00
|
|
|
|
list1.add(ip);
|
|
|
|
|
|
}
|
2018-11-27 16:17:51 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2018-11-28 12:00:25 +08:00
|
|
|
|
|
|
|
|
|
|
for(AsnIpCfg ip:asnIpList){//asn不需要再次获取regionId,groupId
|
2018-11-27 16:57:08 +08:00
|
|
|
|
if(ip.getAsnIpGroup().toString().equals(cfg.getUserRegion4())){//根据组号对应
|
2018-11-28 15:27:49 +08:00
|
|
|
|
ip.setIsValid(entity.getIsValid());
|
2018-11-29 09:23:31 +08:00
|
|
|
|
ip.setAuditTime(StringUtil.isEmpty(entity.getAuditTime()) ? cfg.getAuditTime():entity.getAuditTime());
|
2018-11-27 16:57:08 +08:00
|
|
|
|
list1.add(ip);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2018-11-28 12:00:25 +08:00
|
|
|
|
for(int index=0;index<strList.size();index++){
|
|
|
|
|
|
BaseStringCfg str = strList.get(index);
|
2018-11-27 16:17:51 +08:00
|
|
|
|
if(str.getCompileId().equals(cfg.getCompileId())){
|
2018-11-28 19:58:34 +08:00
|
|
|
|
// BeanUtils.copyProperties(cfg, str);
|
|
|
|
|
|
str.setRegionId(regionIds.get(0));
|
|
|
|
|
|
regionIds.remove(0);
|
|
|
|
|
|
str.setGroupId(groupIds.get(0));
|
|
|
|
|
|
groupIds.remove(0);
|
2018-11-28 15:27:49 +08:00
|
|
|
|
str.setIsValid(entity.getIsValid());
|
2018-11-29 09:23:31 +08:00
|
|
|
|
str.setAuditTime(StringUtil.isEmpty(entity.getAuditTime()) ? cfg.getAuditTime():entity.getAuditTime());
|
2018-11-27 16:17:51 +08:00
|
|
|
|
list2.add(str);
|
|
|
|
|
|
if(entity.getServiceId().equals(513)||entity.getServiceId().equals(515)){
|
|
|
|
|
|
if(userRegion.equals("")){
|
|
|
|
|
|
userRegion += Constants.USERREGION_DOMAIN_STR+"="+str.getCfgKeywords();
|
|
|
|
|
|
}else{
|
|
|
|
|
|
userRegion += Constants.USER_REGION_SPLIT+Constants.USERREGION_DOMAIN_STR+"="+str.getCfgKeywords();
|
2018-11-26 14:34:24 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2018-11-27 16:17:51 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2018-11-28 12:00:25 +08:00
|
|
|
|
for(int index=0;index<complexStrList.size();index++){
|
|
|
|
|
|
ComplexkeywordCfg str = complexStrList.get(index);
|
2018-11-27 16:17:51 +08:00
|
|
|
|
if(str.getCompileId().equals(cfg.getCompileId())){
|
2018-11-28 19:58:34 +08:00
|
|
|
|
// BeanUtils.copyProperties(cfg, str);
|
|
|
|
|
|
str.setRegionId(regionIds.get(0));
|
|
|
|
|
|
regionIds.remove(0);
|
|
|
|
|
|
str.setGroupId(groupIds.get(0));
|
|
|
|
|
|
groupIds.remove(0);
|
2018-11-28 15:27:49 +08:00
|
|
|
|
str.setIsValid(entity.getIsValid());
|
2018-11-29 09:23:31 +08:00
|
|
|
|
str.setAuditTime(StringUtil.isEmpty(entity.getAuditTime()) ? cfg.getAuditTime():entity.getAuditTime());
|
2018-11-27 16:17:51 +08:00
|
|
|
|
list3.add(str);
|
|
|
|
|
|
if(entity.getServiceId().equals(129) && str.getDistrict()!=null){//http监测
|
|
|
|
|
|
String dictValue = DictUtils.getDictCode(Constants.HTTP_HEADER_DICT_MODULE, str.getDistrict());
|
|
|
|
|
|
if(StringUtil.isEmpty(dictValue) || dictValue.equals("默认")){
|
|
|
|
|
|
if(userRegion.equals("")){
|
|
|
|
|
|
userRegion += Constants.HTTP_HEADER_USER_REGION_KEY+"="+str.getDistrict();
|
|
|
|
|
|
}else{
|
|
|
|
|
|
userRegion += Constants.USER_REGION_SPLIT+Constants.HTTP_HEADER_USER_REGION_KEY+"="+str.getDistrict();
|
2018-11-26 14:34:24 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2018-11-27 16:17:51 +08:00
|
|
|
|
}
|
2018-11-28 12:00:25 +08:00
|
|
|
|
for(int index=0;index<numList.size();index++){
|
|
|
|
|
|
com.nis.domain.configuration.NumBoundaryCfg num = numList.get(index);
|
2018-11-27 16:17:51 +08:00
|
|
|
|
if(num.getCompileId().equals(cfg.getCompileId())){
|
2018-11-28 19:58:34 +08:00
|
|
|
|
// BeanUtils.copyProperties(cfg, num);
|
|
|
|
|
|
num.setRegionId(regionIds.get(0));
|
|
|
|
|
|
regionIds.remove(0);
|
|
|
|
|
|
num.setGroupId(groupIds.get(0));
|
|
|
|
|
|
groupIds.remove(0);
|
2018-11-28 15:27:49 +08:00
|
|
|
|
num.setIsValid(entity.getIsValid());
|
2018-11-29 09:23:31 +08:00
|
|
|
|
num.setAuditTime(StringUtil.isEmpty(entity.getAuditTime()) ? cfg.getAuditTime():entity.getAuditTime());
|
2018-11-27 16:17:51 +08:00
|
|
|
|
list4.add(num);
|
2018-11-26 14:34:24 +08:00
|
|
|
|
}
|
2018-11-27 16:17:51 +08:00
|
|
|
|
}
|
2018-11-28 12:00:25 +08:00
|
|
|
|
for(int index=0;index<fileList.size();index++){
|
|
|
|
|
|
FileDigestCfg file = fileList.get(index);
|
2018-11-27 16:17:51 +08:00
|
|
|
|
if(file.getCompileId().equals(cfg.getCompileId())){
|
2018-11-28 19:58:34 +08:00
|
|
|
|
// BeanUtils.copyProperties(cfg, file);
|
|
|
|
|
|
file.setRegionId(regionIds.get(0));
|
|
|
|
|
|
regionIds.remove(0);
|
|
|
|
|
|
file.setGroupId(groupIds.get(0));
|
|
|
|
|
|
groupIds.remove(0);
|
2018-11-28 15:27:49 +08:00
|
|
|
|
file.setIsValid(entity.getIsValid());
|
2018-11-29 09:23:31 +08:00
|
|
|
|
file.setAuditTime(StringUtil.isEmpty(entity.getAuditTime()) ? cfg.getAuditTime():entity.getAuditTime());
|
2018-11-27 16:17:51 +08:00
|
|
|
|
list5.add(file);
|
2018-11-26 14:34:24 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2018-11-27 16:17:51 +08:00
|
|
|
|
if(list1.size()>0){
|
|
|
|
|
|
ipList.removeAll(list1);
|
2018-11-27 16:57:08 +08:00
|
|
|
|
if(entity.getServiceId().equals(37)||entity.getServiceId().equals(149)){//asn业务
|
2018-11-28 12:00:25 +08:00
|
|
|
|
GroupCfg groupCfg=new GroupCfg();
|
|
|
|
|
|
groupCfg.setCompileId(cfg.getCompileId());
|
|
|
|
|
|
groupCfg.setGroupId(Integer.parseInt(cfg.getUserRegion4()));
|
2018-11-28 15:27:49 +08:00
|
|
|
|
groupCfg.setIsValid(entity.getIsValid());
|
2018-11-29 09:23:31 +08:00
|
|
|
|
groupCfg.setAuditTime(StringUtil.isEmpty(entity.getAuditTime()) ? cfg.getAuditTime():entity.getAuditTime());
|
2018-11-28 12:00:25 +08:00
|
|
|
|
groupRelationList.add(groupCfg);
|
2018-11-27 16:57:08 +08:00
|
|
|
|
ipRegionList.addAll(groupReuseCfgAddRemoveConvert(list1,Constants.VALID_YES,null));
|
|
|
|
|
|
}else{
|
2018-11-28 12:00:25 +08:00
|
|
|
|
Map<String,List> map = cfgToMaatConvert(ipRegionList,list1,1,groupRelationList);
|
2018-11-27 16:57:08 +08:00
|
|
|
|
groupRelationList=map.get("groupList");
|
|
|
|
|
|
ipRegionList=map.get("dstList");
|
|
|
|
|
|
if(map.get("numRegionList")!=null){
|
|
|
|
|
|
numRegionList.addAll(map.get("numRegionList"));
|
|
|
|
|
|
}
|
2018-11-27 16:17:51 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if(list2.size()>0){
|
|
|
|
|
|
strList.removeAll(list2);
|
2018-11-28 12:00:25 +08:00
|
|
|
|
Map<String,List> map = cfgToMaatConvert(strRegionList,list2,2,groupRelationList);
|
2018-11-27 16:17:51 +08:00
|
|
|
|
groupRelationList=map.get("groupList");
|
|
|
|
|
|
strRegionList=map.get("dstList");
|
|
|
|
|
|
}
|
|
|
|
|
|
if(list3.size()>0){
|
|
|
|
|
|
complexStrList.removeAll(list3);
|
2018-11-28 12:00:25 +08:00
|
|
|
|
Map<String,List> map = cfgToMaatConvert(strRegionList,list3,3,groupRelationList);
|
2018-11-27 16:17:51 +08:00
|
|
|
|
groupRelationList=map.get("groupList");
|
|
|
|
|
|
strRegionList=map.get("dstList");
|
|
|
|
|
|
}
|
|
|
|
|
|
if(list4.size()>0){
|
|
|
|
|
|
numList.removeAll(list4);
|
2018-11-28 12:00:25 +08:00
|
|
|
|
Map<String,List> map = cfgToMaatConvert(numRegionList,list4,4,groupRelationList);
|
2018-11-27 16:17:51 +08:00
|
|
|
|
groupRelationList=map.get("groupList");
|
|
|
|
|
|
numRegionList=map.get("dstList");
|
|
|
|
|
|
}
|
|
|
|
|
|
if(list5.size()>0){
|
|
|
|
|
|
fileList.removeAll(list5);
|
2018-11-28 12:00:25 +08:00
|
|
|
|
Map<String,List> map = cfgToMaatConvert(digestRegionList,list5,5,groupRelationList);
|
2018-11-27 16:17:51 +08:00
|
|
|
|
groupRelationList=map.get("groupList");
|
|
|
|
|
|
digestRegionList=map.get("dstList");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BeanUtils.copyProperties(cfg, maatCfg);
|
|
|
|
|
|
maatCfg.setAction(cfg.getAction());
|
2018-11-29 09:23:31 +08:00
|
|
|
|
maatCfg.setAuditTime(StringUtil.isEmpty(entity.getAuditTime()) ? cfg.getAuditTime():entity.getAuditTime());
|
2018-11-27 16:17:51 +08:00
|
|
|
|
maatCfg.setIpRegionList(ipRegionList);
|
|
|
|
|
|
maatCfg.setStrRegionList(strRegionList);
|
|
|
|
|
|
maatCfg.setNumRegionList(numRegionList);
|
|
|
|
|
|
maatCfg.setDigestRegionList(digestRegionList);
|
|
|
|
|
|
maatCfg.setGroupRelationList(groupRelationList);
|
|
|
|
|
|
maatCfg.setGroupNum(groupRelationList.size());
|
|
|
|
|
|
maatCfg.setAreaIpRegionList(areaIpRegionList);
|
2018-11-28 15:27:49 +08:00
|
|
|
|
maatCfg.setIsValid(entity.getIsValid());
|
|
|
|
|
|
maatCfg.setAuditTime(new Date());
|
2018-11-27 16:17:51 +08:00
|
|
|
|
if(!StringUtil.isEmpty(userRegion)){
|
|
|
|
|
|
maatCfg.setUserRegion(userRegion);
|
|
|
|
|
|
}
|
|
|
|
|
|
configCompileList.add(maatCfg);
|
|
|
|
|
|
}
|
|
|
|
|
|
page.setList(list);
|
|
|
|
|
|
if(page.isLastPage()){
|
|
|
|
|
|
hasData = false;
|
2018-11-26 14:34:24 +08:00
|
|
|
|
}
|
2018-11-27 16:17:51 +08:00
|
|
|
|
if(!StringUtil.isEmpty(configCompileList.size())){
|
|
|
|
|
|
maatBean.setConfigCompileList(configCompileList);
|
2018-11-28 15:27:49 +08:00
|
|
|
|
maatBean.setAuditTime(new Date());
|
2018-11-27 16:17:51 +08:00
|
|
|
|
maatBean.setCreatorName(UserUtils.getUser().getName());
|
|
|
|
|
|
maatBean.setVersion(Constants.MAAT_VERSION);
|
|
|
|
|
|
maatBean.setOpAction(Constants.INSERT_ACTION);
|
|
|
|
|
|
String json=gsonToJson(maatBean);
|
2018-11-28 12:00:25 +08:00
|
|
|
|
//调用服务接口下发配置数据
|
|
|
|
|
|
if(isUpdateCfg) {
|
|
|
|
|
|
logger.info("配置批量下发:"+json);
|
|
|
|
|
|
//调用服务接口同步回调类配置
|
|
|
|
|
|
ToMaatResult result = ConfigServiceUtil.postMaatCfg(json);
|
|
|
|
|
|
if(result!=null){
|
|
|
|
|
|
logger.info("配置批量下发响应信息:"+result.getMsg());
|
|
|
|
|
|
}
|
|
|
|
|
|
}else {
|
|
|
|
|
|
//调用服务接口配置全量更新
|
2018-11-28 19:58:34 +08:00
|
|
|
|
// JSONObject result = ConfigServiceUtil.configSync(json,1,entity.getServiceId(),null,(hasData?null:"FINISHED"));
|
2018-11-28 12:00:25 +08:00
|
|
|
|
}
|
2018-11-27 16:17:51 +08:00
|
|
|
|
}
|
|
|
|
|
|
return hasData;
|
2018-11-26 14:34:24 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2018-11-28 19:58:34 +08:00
|
|
|
|
* APP策略配置批量下发
|
2018-11-27 16:17:51 +08:00
|
|
|
|
* @param cfgList
|
|
|
|
|
|
* @param userRegionList
|
|
|
|
|
|
* @param page
|
|
|
|
|
|
* @param entity
|
|
|
|
|
|
* @param list
|
|
|
|
|
|
* @param hasData
|
2018-11-28 19:58:34 +08:00
|
|
|
|
* @param isUpdateCfg 业务配置全部生效时需同步更新库表配置状态
|
2018-11-27 16:17:51 +08:00
|
|
|
|
* @return
|
|
|
|
|
|
* @throws NoSuchFieldException
|
|
|
|
|
|
* @throws SecurityException
|
|
|
|
|
|
* @throws IllegalArgumentException
|
|
|
|
|
|
* @throws IllegalAccessException
|
|
|
|
|
|
*/
|
2018-11-28 19:58:34 +08:00
|
|
|
|
public boolean auditAppPolicyData(List<Map<String,Object>> cfgList,
|
|
|
|
|
|
List<Map<String,Object>> userRegionList,
|
|
|
|
|
|
Page page,
|
2018-11-27 16:17:51 +08:00
|
|
|
|
BaseCfg entity,
|
2018-11-28 19:58:34 +08:00
|
|
|
|
List<AppPolicyCfg> list,
|
2018-11-27 16:17:51 +08:00
|
|
|
|
boolean hasData,
|
2018-11-28 19:58:34 +08:00
|
|
|
|
boolean isUpdateCfg)throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException{
|
2018-11-27 16:17:51 +08:00
|
|
|
|
ToMaatBean maatBean;
|
|
|
|
|
|
MaatCfg maatCfg;
|
|
|
|
|
|
List<MaatCfg> configCompileList;
|
|
|
|
|
|
List<GroupCfg> groupRelationList;
|
|
|
|
|
|
List<IpCfg> ipRegionList;
|
|
|
|
|
|
List<StringCfg> strRegionList;
|
|
|
|
|
|
List<NumBoundaryCfg> numRegionList;
|
|
|
|
|
|
List<DigestCfg> digestRegionList;
|
|
|
|
|
|
List<IpCfg> areaIpRegionList;
|
|
|
|
|
|
|
|
|
|
|
|
List<IpPortCfg> ipList = new ArrayList();
|
2018-11-28 19:58:34 +08:00
|
|
|
|
List<BaseStringCfg> strList = new ArrayList();
|
|
|
|
|
|
List<ComplexkeywordCfg> complexStrList = new ArrayList();
|
|
|
|
|
|
List<com.nis.domain.configuration.NumBoundaryCfg> numList = new ArrayList();
|
|
|
|
|
|
List<FileDigestCfg> fileList = new ArrayList();
|
2018-11-27 16:17:51 +08:00
|
|
|
|
maatBean = new ToMaatBean();
|
|
|
|
|
|
configCompileList = new ArrayList();
|
2018-11-28 19:58:34 +08:00
|
|
|
|
List<Integer> compileIds = new ArrayList();
|
|
|
|
|
|
List<String> asnGroupIds = new ArrayList();
|
|
|
|
|
|
for(AppPolicyCfg cfg:list){
|
|
|
|
|
|
compileIds.add(cfg.getCompileId());
|
|
|
|
|
|
}
|
|
|
|
|
|
if(cfgList!=null){
|
|
|
|
|
|
for(Map<String,Object> m:cfgList){
|
|
|
|
|
|
String tableName = m.get("tableName").toString();
|
|
|
|
|
|
if("1".equals(m.get("cfgType"))){
|
|
|
|
|
|
ipList.addAll(configSynchronizationDao.getIpPortList(tableName, compileIds));
|
|
|
|
|
|
}else if("2".equals(m.get("cfgType"))){
|
|
|
|
|
|
strList.addAll(configSynchronizationDao.getStrList(tableName,compileIds));
|
|
|
|
|
|
}else if("3".equals(m.get("cfgType"))){
|
|
|
|
|
|
complexStrList.addAll(configSynchronizationDao.getComplexStrList(tableName,compileIds));
|
|
|
|
|
|
}else if("4".equals(m.get("cfgType"))){
|
|
|
|
|
|
|
|
|
|
|
|
}else if("5".equals(m.get("cfgType"))){
|
|
|
|
|
|
fileList.addAll(configSynchronizationDao.getFileDigestList(tableName, compileIds));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
//批量获取regionId,groupId(相同编译下的IP类配置多条ip只获取一个组号),compileIds.size()表示app策略本身有一个字符串域
|
|
|
|
|
|
List<Integer> regionIds = ConfigServiceUtil.getId(3, ipList.size()+strList.size()+compileIds.size()+complexStrList.size()+numList.size()+fileList.size());
|
|
|
|
|
|
List<Integer> groupIds = ConfigServiceUtil.getId(2, strList.size()+compileIds.size()+complexStrList.size()+numList.size()+fileList.size());
|
|
|
|
|
|
for(AppPolicyCfg cfg:list){
|
2018-11-27 16:17:51 +08:00
|
|
|
|
maatCfg = new MaatCfg();
|
|
|
|
|
|
maatCfg.initDefaultValue();
|
|
|
|
|
|
groupRelationList = new ArrayList();
|
|
|
|
|
|
ipRegionList = new ArrayList();
|
|
|
|
|
|
strRegionList = new ArrayList();
|
|
|
|
|
|
numRegionList = new ArrayList();
|
|
|
|
|
|
digestRegionList = new ArrayList();
|
|
|
|
|
|
areaIpRegionList = new ArrayList();
|
2018-11-28 19:58:34 +08:00
|
|
|
|
List list1 = new ArrayList();
|
|
|
|
|
|
List<BaseStringCfg> list2 = new ArrayList();
|
|
|
|
|
|
List<ComplexkeywordCfg> list3 = new ArrayList();
|
|
|
|
|
|
List<com.nis.domain.configuration.NumBoundaryCfg> list4 = new ArrayList();
|
|
|
|
|
|
List<FileDigestCfg> list5 = new ArrayList();
|
2018-11-27 16:17:51 +08:00
|
|
|
|
String userRegion = "";
|
|
|
|
|
|
//处理自定义域
|
|
|
|
|
|
if(userRegionList!=null){
|
|
|
|
|
|
for(Map<String,Object> n:userRegionList){
|
|
|
|
|
|
Object userRegionPosition = n.get("userRegionPosition");
|
|
|
|
|
|
if(userRegionPosition!=null && (userRegionPosition.toString().equals("1")||userRegionPosition.toString().equals("0"))){
|
|
|
|
|
|
//通过反射机制获取自定义域字段值
|
|
|
|
|
|
String regionColumn = n.get("regionColumn").toString();
|
|
|
|
|
|
Class aClass = null;
|
|
|
|
|
|
if(userRegionPosition.toString().equals(("0"))){
|
|
|
|
|
|
aClass = BaseCfg.class;
|
|
|
|
|
|
}else{
|
2018-11-28 19:58:34 +08:00
|
|
|
|
aClass = AppPolicyCfg.class;
|
2018-11-26 14:34:24 +08:00
|
|
|
|
}
|
2018-11-27 16:17:51 +08:00
|
|
|
|
Object value = "";
|
|
|
|
|
|
Field field = aClass.getDeclaredField(regionColumn);
|
|
|
|
|
|
field.setAccessible(true);
|
|
|
|
|
|
value = field.get(cfg);
|
|
|
|
|
|
if(!StringUtil.isEmpty(value)){
|
|
|
|
|
|
if(StringUtil.isEmpty(n.get("regionKey"))){
|
|
|
|
|
|
userRegion = value.toString();
|
|
|
|
|
|
}else{
|
|
|
|
|
|
userRegion += n.get("regionKey")+"="+value+Constants.USER_REGION_SPLIT;
|
|
|
|
|
|
}
|
2018-11-26 14:34:24 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2018-11-27 16:17:51 +08:00
|
|
|
|
if(userRegion.endsWith(Constants.USER_REGION_SPLIT)){
|
|
|
|
|
|
userRegion = userRegion.substring(0, userRegion.length()-1);
|
2018-11-26 14:34:24 +08:00
|
|
|
|
}
|
2018-11-27 16:17:51 +08:00
|
|
|
|
}
|
2018-11-28 19:58:34 +08:00
|
|
|
|
//将app码与行为码设置为字符串域
|
|
|
|
|
|
StringBuffer cfgKeywords = new StringBuffer();
|
|
|
|
|
|
BaseStringCfg strCfg = new BaseStringCfg();
|
|
|
|
|
|
if(cfg.getServiceId().equals(35)||cfg.getServiceId().equals(147)||cfg.getServiceId().equals(1059)){//基础协议
|
|
|
|
|
|
cfgKeywords.append(Constants.PROTO_ID_REGION + "=" + cfg.getAppCode());
|
|
|
|
|
|
}else if(cfg.getServiceId().equals(33)||cfg.getServiceId().equals(145)||cfg.getServiceId().equals(1056)){
|
|
|
|
|
|
cfgKeywords.append(Constants.APP_ID_REGION + "=" + cfg.getAppCode());
|
|
|
|
|
|
if(cfg.getBehavCode()!=null){
|
|
|
|
|
|
cfgKeywords.append(Constants.KEYWORD_EXPR);
|
|
|
|
|
|
cfgKeywords.append(Constants.BEHAV_ID_REGION + "=" + cfg.getBehavCode());
|
|
|
|
|
|
}
|
|
|
|
|
|
}else if(cfg.getServiceId().equals(36)||cfg.getServiceId().equals(148)||cfg.getServiceId().equals(1060)){//隧道加密协议
|
|
|
|
|
|
cfgKeywords.append(Constants.PROTO_ID_REGION + "=" + cfg.getAppCode());
|
|
|
|
|
|
if(cfg.getBehavCode()!=null){
|
|
|
|
|
|
cfgKeywords.append(Constants.KEYWORD_EXPR);
|
|
|
|
|
|
cfgKeywords.append(Constants.BEHAV_ID_REGION + "=" + cfg.getBehavCode());
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
cfg.setCfgKeywords(cfgKeywords.toString());
|
|
|
|
|
|
BeanUtils.copyProperties(cfg, strCfg);
|
|
|
|
|
|
strList.add(strCfg);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(ipList.size()>0){
|
|
|
|
|
|
List<Integer> ipGroupId = ConfigServiceUtil.getId(2,1);//多条IP只获取一个groupId
|
|
|
|
|
|
for(int index=0;index<ipList.size();index++){
|
|
|
|
|
|
IpPortCfg ip = ipList.get(index);
|
|
|
|
|
|
if(ip.getCompileId().equals(cfg.getCompileId())){
|
|
|
|
|
|
// BeanUtils.copyProperties(cfg, ip);
|
|
|
|
|
|
ip.setRegionId(regionIds.get(0));
|
|
|
|
|
|
regionIds.remove(0);
|
|
|
|
|
|
ip.setGroupId(ipGroupId.get(0));
|
|
|
|
|
|
ip.setIsValid(entity.getIsValid());
|
2018-11-29 09:23:31 +08:00
|
|
|
|
ip.setAuditTime(StringUtil.isEmpty(entity.getAuditTime()) ? cfg.getAuditTime():entity.getAuditTime());
|
2018-11-28 19:58:34 +08:00
|
|
|
|
list1.add(ip);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
for(int index=0;index<strList.size();index++){
|
|
|
|
|
|
BaseStringCfg str = strList.get(index);
|
|
|
|
|
|
if(str.getCompileId().equals(cfg.getCompileId())){
|
|
|
|
|
|
// BeanUtils.copyProperties(cfg, str);
|
|
|
|
|
|
str.setRegionId(regionIds.get(0));
|
|
|
|
|
|
regionIds.remove(0);
|
|
|
|
|
|
str.setGroupId(groupIds.get(0));
|
|
|
|
|
|
groupIds.remove(0);
|
|
|
|
|
|
str.setIsValid(entity.getIsValid());
|
2018-11-29 09:23:31 +08:00
|
|
|
|
str.setAuditTime(StringUtil.isEmpty(entity.getAuditTime()) ? cfg.getAuditTime():entity.getAuditTime());
|
2018-11-28 19:58:34 +08:00
|
|
|
|
list2.add(str);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
for(int index=0;index<complexStrList.size();index++){
|
|
|
|
|
|
ComplexkeywordCfg str = complexStrList.get(index);
|
|
|
|
|
|
if(str.getCompileId().equals(cfg.getCompileId())){
|
|
|
|
|
|
// BeanUtils.copyProperties(cfg, str);
|
|
|
|
|
|
str.setRegionId(regionIds.get(0));
|
|
|
|
|
|
regionIds.remove(0);
|
|
|
|
|
|
str.setGroupId(groupIds.get(0));
|
|
|
|
|
|
groupIds.remove(0);
|
|
|
|
|
|
str.setIsValid(entity.getIsValid());
|
2018-11-29 09:23:31 +08:00
|
|
|
|
str.setAuditTime(StringUtil.isEmpty(entity.getAuditTime()) ? cfg.getAuditTime():entity.getAuditTime());
|
2018-11-28 19:58:34 +08:00
|
|
|
|
list3.add(str);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
for(int index=0;index<numList.size();index++){
|
|
|
|
|
|
com.nis.domain.configuration.NumBoundaryCfg num = numList.get(index);
|
|
|
|
|
|
if(num.getCompileId().equals(cfg.getCompileId())){
|
|
|
|
|
|
// BeanUtils.copyProperties(cfg, num);
|
|
|
|
|
|
num.setRegionId(regionIds.get(0));
|
|
|
|
|
|
regionIds.remove(0);
|
|
|
|
|
|
num.setGroupId(groupIds.get(0));
|
|
|
|
|
|
groupIds.remove(0);
|
|
|
|
|
|
num.setIsValid(entity.getIsValid());
|
2018-11-29 09:23:31 +08:00
|
|
|
|
num.setAuditTime(StringUtil.isEmpty(entity.getAuditTime()) ? cfg.getAuditTime():entity.getAuditTime());
|
2018-11-28 19:58:34 +08:00
|
|
|
|
list4.add(num);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
for(int index=0;index<fileList.size();index++){
|
|
|
|
|
|
FileDigestCfg file = fileList.get(index);
|
|
|
|
|
|
if(file.getCompileId().equals(cfg.getCompileId())){
|
|
|
|
|
|
// BeanUtils.copyProperties(cfg, file);
|
|
|
|
|
|
file.setRegionId(regionIds.get(0));
|
|
|
|
|
|
regionIds.remove(0);
|
|
|
|
|
|
file.setGroupId(groupIds.get(0));
|
|
|
|
|
|
groupIds.remove(0);
|
|
|
|
|
|
file.setIsValid(entity.getIsValid());
|
2018-11-29 09:23:31 +08:00
|
|
|
|
file.setAuditTime(StringUtil.isEmpty(entity.getAuditTime()) ? cfg.getAuditTime():entity.getAuditTime());
|
2018-11-28 19:58:34 +08:00
|
|
|
|
list5.add(file);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2018-11-27 16:17:51 +08:00
|
|
|
|
if(list1.size()>0){
|
|
|
|
|
|
ipList.removeAll(list1);
|
2018-11-28 12:00:25 +08:00
|
|
|
|
Map<String,List> map = cfgToMaatConvert(ipRegionList,list1,1,groupRelationList);
|
2018-11-27 16:17:51 +08:00
|
|
|
|
groupRelationList=map.get("groupList");
|
|
|
|
|
|
ipRegionList=map.get("dstList");
|
|
|
|
|
|
if(map.get("numRegionList")!=null){
|
|
|
|
|
|
numRegionList.addAll(map.get("numRegionList"));
|
2018-11-26 14:34:24 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2018-11-28 19:58:34 +08:00
|
|
|
|
if(list2.size()>0){
|
|
|
|
|
|
strList.removeAll(list2);
|
|
|
|
|
|
Map<String,List> map = cfgToMaatConvert(strRegionList,list2,2,groupRelationList);
|
|
|
|
|
|
groupRelationList=map.get("groupList");
|
|
|
|
|
|
strRegionList=map.get("dstList");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(list3.size()>0){
|
|
|
|
|
|
complexStrList.removeAll(list3);
|
|
|
|
|
|
Map<String,List> map = cfgToMaatConvert(strRegionList,list3,3,groupRelationList);
|
|
|
|
|
|
groupRelationList=map.get("groupList");
|
|
|
|
|
|
strRegionList=map.get("dstList");
|
|
|
|
|
|
}
|
|
|
|
|
|
if(list4.size()>0){
|
|
|
|
|
|
numList.removeAll(list4);
|
|
|
|
|
|
Map<String,List> map = cfgToMaatConvert(numRegionList,list4,4,groupRelationList);
|
|
|
|
|
|
groupRelationList=map.get("groupList");
|
|
|
|
|
|
numRegionList=map.get("dstList");
|
|
|
|
|
|
}
|
|
|
|
|
|
if(list5.size()>0){
|
|
|
|
|
|
fileList.removeAll(list5);
|
|
|
|
|
|
Map<String,List> map = cfgToMaatConvert(digestRegionList,list5,5,groupRelationList);
|
|
|
|
|
|
groupRelationList=map.get("groupList");
|
|
|
|
|
|
digestRegionList=map.get("dstList");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BeanUtils.copyProperties(cfg, maatCfg);
|
|
|
|
|
|
maatCfg.setAction(cfg.getAction());
|
2018-11-29 09:23:31 +08:00
|
|
|
|
maatCfg.setAuditTime(StringUtil.isEmpty(entity.getAuditTime()) ? cfg.getAuditTime():entity.getAuditTime());
|
2018-11-28 19:58:34 +08:00
|
|
|
|
maatCfg.setIpRegionList(ipRegionList);
|
|
|
|
|
|
maatCfg.setStrRegionList(strRegionList);
|
|
|
|
|
|
maatCfg.setNumRegionList(numRegionList);
|
|
|
|
|
|
maatCfg.setDigestRegionList(digestRegionList);
|
|
|
|
|
|
maatCfg.setGroupRelationList(groupRelationList);
|
|
|
|
|
|
maatCfg.setGroupNum(groupRelationList.size());
|
|
|
|
|
|
maatCfg.setAreaIpRegionList(areaIpRegionList);
|
|
|
|
|
|
maatCfg.setIsValid(entity.getIsValid());
|
|
|
|
|
|
maatCfg.setAuditTime(new Date());
|
|
|
|
|
|
if(!StringUtil.isEmpty(userRegion)){
|
|
|
|
|
|
maatCfg.setUserRegion(userRegion);
|
|
|
|
|
|
}
|
|
|
|
|
|
configCompileList.add(maatCfg);
|
|
|
|
|
|
}
|
|
|
|
|
|
page.setList(list);
|
|
|
|
|
|
if(page.isLastPage()){
|
|
|
|
|
|
hasData = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
if(!StringUtil.isEmpty(configCompileList.size())){
|
|
|
|
|
|
maatBean.setConfigCompileList(configCompileList);
|
|
|
|
|
|
maatBean.setAuditTime(new Date());
|
|
|
|
|
|
maatBean.setCreatorName(UserUtils.getUser().getName());
|
|
|
|
|
|
maatBean.setVersion(Constants.MAAT_VERSION);
|
|
|
|
|
|
maatBean.setOpAction(Constants.INSERT_ACTION);
|
|
|
|
|
|
String json=gsonToJson(maatBean);
|
|
|
|
|
|
//调用服务接口下发配置数据
|
|
|
|
|
|
if(isUpdateCfg) {
|
|
|
|
|
|
logger.info("配置批量下发:"+json);
|
|
|
|
|
|
//调用服务接口同步回调类配置
|
|
|
|
|
|
ToMaatResult result = ConfigServiceUtil.postMaatCfg(json);
|
|
|
|
|
|
if(result!=null){
|
|
|
|
|
|
logger.info("配置批量下发响应信息:"+result.getMsg());
|
|
|
|
|
|
}
|
|
|
|
|
|
}else {
|
|
|
|
|
|
//调用服务接口配置全量更新
|
|
|
|
|
|
// JSONObject result = ConfigServiceUtil.configSync(json,1,entity.getServiceId(),null,(hasData?null:"FINISHED"));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return hasData;
|
|
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
|
|
|
* APP特征批量下发
|
|
|
|
|
|
* @param cfgList
|
|
|
|
|
|
* @param userRegionList
|
|
|
|
|
|
* @param page
|
|
|
|
|
|
* @param entity
|
|
|
|
|
|
* @param list
|
|
|
|
|
|
* @param hasData
|
|
|
|
|
|
* @param isUpdateCfg 业务配置全部生效时需同步更新库表配置状态
|
|
|
|
|
|
* @return
|
|
|
|
|
|
* @throws NoSuchFieldException
|
|
|
|
|
|
* @throws SecurityException
|
|
|
|
|
|
* @throws IllegalArgumentException
|
|
|
|
|
|
* @throws IllegalAccessException
|
|
|
|
|
|
*/
|
|
|
|
|
|
public boolean auditAppFeatureData(List<Map<String,Object>> cfgList,
|
|
|
|
|
|
List<Map<String,Object>> userRegionList,
|
|
|
|
|
|
Page page,
|
|
|
|
|
|
BaseCfg entity,
|
|
|
|
|
|
List<AppFeatureIndex> list,
|
|
|
|
|
|
boolean hasData,
|
|
|
|
|
|
boolean isUpdateCfg)throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException{
|
|
|
|
|
|
ToMaatBean maatBean;
|
|
|
|
|
|
MaatCfg maatCfg;
|
|
|
|
|
|
List<MaatCfg> configCompileList;
|
|
|
|
|
|
List<GroupCfg> groupRelationList;
|
|
|
|
|
|
List<IpCfg> ipRegionList;
|
|
|
|
|
|
List<StringCfg> strRegionList;
|
|
|
|
|
|
List<NumBoundaryCfg> numRegionList;
|
|
|
|
|
|
List<DigestCfg> digestRegionList;
|
|
|
|
|
|
List<IpCfg> areaIpRegionList;
|
|
|
|
|
|
|
|
|
|
|
|
List<IpPortCfg> ipList = new ArrayList();
|
|
|
|
|
|
List<BaseStringCfg> strList = new ArrayList();
|
|
|
|
|
|
List<ComplexkeywordCfg> complexStrList = new ArrayList();
|
|
|
|
|
|
List<com.nis.domain.configuration.NumBoundaryCfg> numList = new ArrayList();
|
|
|
|
|
|
List<FileDigestCfg> fileList = new ArrayList();
|
|
|
|
|
|
maatBean = new ToMaatBean();
|
|
|
|
|
|
configCompileList = new ArrayList();
|
|
|
|
|
|
List<Integer> compileIds = new ArrayList();
|
|
|
|
|
|
List<String> asnGroupIds = new ArrayList();
|
|
|
|
|
|
for(AppFeatureIndex cfg:list){
|
|
|
|
|
|
compileIds.add(cfg.getCompileId());
|
|
|
|
|
|
if(entity.getServiceId().equals(37)||entity.getServiceId().equals(149)){
|
|
|
|
|
|
asnGroupIds.add(cfg.getUserRegion4());
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if(cfgList!=null){
|
|
|
|
|
|
for(Map<String,Object> m:cfgList){
|
|
|
|
|
|
String tableName = m.get("tableName").toString();
|
|
|
|
|
|
if("1".equals(m.get("cfgType"))){
|
|
|
|
|
|
ipList.addAll(configSynchronizationDao.getAppIpPortList(tableName, compileIds));
|
|
|
|
|
|
}else if("2".equals(m.get("cfgType"))){
|
|
|
|
|
|
strList.addAll(configSynchronizationDao.getStrList(tableName,compileIds));
|
|
|
|
|
|
}else if("3".equals(m.get("cfgType"))){
|
|
|
|
|
|
complexStrList.addAll(configSynchronizationDao.getComplexStrList(tableName,compileIds));
|
|
|
|
|
|
}else if("4".equals(m.get("cfgType"))){
|
|
|
|
|
|
|
|
|
|
|
|
}else if("5".equals(m.get("cfgType"))){
|
|
|
|
|
|
fileList.addAll(configSynchronizationDao.getFileDigestList(tableName, compileIds));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
//批量获取regionId,groupId(相同编译下的IP类配置多条ip只获取一个组号),分组复用的域配置不需要重新获取regionId,groupId
|
|
|
|
|
|
List<Integer> regionIds = ConfigServiceUtil.getId(3, ipList.size()+strList.size()+complexStrList.size()+numList.size()+fileList.size());
|
|
|
|
|
|
List<Integer> groupIds = ConfigServiceUtil.getId(2, strList.size()+complexStrList.size()+numList.size()+fileList.size());
|
|
|
|
|
|
for(AppFeatureIndex cfg:list){
|
|
|
|
|
|
maatCfg = new MaatCfg();
|
|
|
|
|
|
maatCfg.initDefaultValue();
|
|
|
|
|
|
groupRelationList = new ArrayList();
|
|
|
|
|
|
ipRegionList = new ArrayList();
|
|
|
|
|
|
strRegionList = new ArrayList();
|
|
|
|
|
|
numRegionList = new ArrayList();
|
|
|
|
|
|
digestRegionList = new ArrayList();
|
|
|
|
|
|
areaIpRegionList = new ArrayList();
|
|
|
|
|
|
List list1 = new ArrayList();
|
|
|
|
|
|
List<BaseStringCfg> list2 = new ArrayList();
|
|
|
|
|
|
List<ComplexkeywordCfg> list3 = new ArrayList();
|
|
|
|
|
|
List<com.nis.domain.configuration.NumBoundaryCfg> list4 = new ArrayList();
|
|
|
|
|
|
List<FileDigestCfg> list5 = new ArrayList();
|
|
|
|
|
|
String userRegion = "";
|
|
|
|
|
|
//处理自定义域
|
|
|
|
|
|
if(userRegionList!=null){
|
|
|
|
|
|
for(Map<String,Object> n:userRegionList){
|
|
|
|
|
|
Object userRegionPosition = n.get("userRegionPosition");
|
|
|
|
|
|
if(userRegionPosition!=null && (userRegionPosition.toString().equals("1")||userRegionPosition.toString().equals("0"))){
|
|
|
|
|
|
//通过反射机制获取自定义域字段值
|
|
|
|
|
|
String regionColumn = n.get("regionColumn").toString();
|
|
|
|
|
|
Class aClass = null;
|
|
|
|
|
|
if(userRegionPosition.toString().equals(("0"))){
|
|
|
|
|
|
aClass = BaseCfg.class;
|
|
|
|
|
|
}else{
|
|
|
|
|
|
aClass = AppFeatureIndex.class;
|
|
|
|
|
|
}
|
|
|
|
|
|
Object value = "";
|
|
|
|
|
|
Field field = aClass.getDeclaredField(regionColumn);
|
|
|
|
|
|
field.setAccessible(true);
|
|
|
|
|
|
value = field.get(cfg);
|
|
|
|
|
|
if(!StringUtil.isEmpty(value)){
|
|
|
|
|
|
if(StringUtil.isEmpty(n.get("regionKey"))){
|
|
|
|
|
|
userRegion = value.toString();
|
|
|
|
|
|
}else{
|
|
|
|
|
|
userRegion += n.get("regionKey")+"="+value+Constants.USER_REGION_SPLIT;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if(userRegion.endsWith(Constants.USER_REGION_SPLIT)){
|
|
|
|
|
|
userRegion = userRegion.substring(0, userRegion.length()-1);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if(ipList.size()>0){
|
|
|
|
|
|
List<Integer> ipGroupId = ConfigServiceUtil.getId(2,1);//多条IP只获取一个groupId
|
|
|
|
|
|
for(int index=0;index<ipList.size();index++){
|
|
|
|
|
|
IpPortCfg ip = ipList.get(index);
|
|
|
|
|
|
if(ip.getCompileId().equals(cfg.getCompileId())){
|
|
|
|
|
|
// BeanUtils.copyProperties(cfg, ip);
|
|
|
|
|
|
ip.setRegionId(regionIds.get(0));
|
|
|
|
|
|
regionIds.remove(0);
|
|
|
|
|
|
ip.setGroupId(ipGroupId.get(0));
|
|
|
|
|
|
ip.setIsValid(entity.getIsValid());
|
2018-11-29 09:23:31 +08:00
|
|
|
|
ip.setAuditTime(StringUtil.isEmpty(entity.getAuditTime()) ? cfg.getAuditTime():entity.getAuditTime());
|
2018-11-28 19:58:34 +08:00
|
|
|
|
list1.add(ip);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
for(int index=0;index<strList.size();index++){
|
|
|
|
|
|
BaseStringCfg str = strList.get(index);
|
|
|
|
|
|
if(str.getCompileId().equals(cfg.getCompileId())){
|
|
|
|
|
|
// BeanUtils.copyProperties(cfg, str);
|
|
|
|
|
|
str.setRegionId(regionIds.get(0));
|
|
|
|
|
|
regionIds.remove(0);
|
|
|
|
|
|
str.setGroupId(groupIds.get(0));
|
|
|
|
|
|
groupIds.remove(0);
|
|
|
|
|
|
str.setIsValid(entity.getIsValid());
|
2018-11-29 09:23:31 +08:00
|
|
|
|
str.setAuditTime(StringUtil.isEmpty(entity.getAuditTime()) ? cfg.getAuditTime():entity.getAuditTime());
|
2018-11-28 19:58:34 +08:00
|
|
|
|
list2.add(str);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
for(int index=0;index<complexStrList.size();index++){
|
|
|
|
|
|
ComplexkeywordCfg str = complexStrList.get(index);
|
|
|
|
|
|
if(str.getCompileId().equals(cfg.getCompileId())){
|
|
|
|
|
|
// BeanUtils.copyProperties(cfg, str);
|
|
|
|
|
|
str.setRegionId(regionIds.get(0));
|
|
|
|
|
|
regionIds.remove(0);
|
|
|
|
|
|
str.setGroupId(groupIds.get(0));
|
|
|
|
|
|
groupIds.remove(0);
|
|
|
|
|
|
str.setIsValid(entity.getIsValid());
|
2018-11-29 09:23:31 +08:00
|
|
|
|
str.setAuditTime(StringUtil.isEmpty(entity.getAuditTime()) ? cfg.getAuditTime():entity.getAuditTime());
|
2018-11-28 19:58:34 +08:00
|
|
|
|
list3.add(str);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
for(int index=0;index<numList.size();index++){
|
|
|
|
|
|
com.nis.domain.configuration.NumBoundaryCfg num = numList.get(index);
|
|
|
|
|
|
if(num.getCompileId().equals(cfg.getCompileId())){
|
|
|
|
|
|
// BeanUtils.copyProperties(cfg, num);
|
|
|
|
|
|
num.setRegionId(regionIds.get(0));
|
|
|
|
|
|
regionIds.remove(0);
|
|
|
|
|
|
num.setGroupId(groupIds.get(0));
|
|
|
|
|
|
groupIds.remove(0);
|
|
|
|
|
|
num.setIsValid(entity.getIsValid());
|
2018-11-29 09:23:31 +08:00
|
|
|
|
num.setAuditTime(StringUtil.isEmpty(entity.getAuditTime()) ? cfg.getAuditTime():entity.getAuditTime());
|
2018-11-28 19:58:34 +08:00
|
|
|
|
list4.add(num);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
for(int index=0;index<fileList.size();index++){
|
|
|
|
|
|
FileDigestCfg file = fileList.get(index);
|
|
|
|
|
|
if(file.getCompileId().equals(cfg.getCompileId())){
|
|
|
|
|
|
// BeanUtils.copyProperties(cfg, file);
|
|
|
|
|
|
file.setRegionId(regionIds.get(0));
|
|
|
|
|
|
regionIds.remove(0);
|
|
|
|
|
|
file.setGroupId(groupIds.get(0));
|
|
|
|
|
|
groupIds.remove(0);
|
|
|
|
|
|
file.setIsValid(entity.getIsValid());
|
2018-11-29 09:23:31 +08:00
|
|
|
|
file.setAuditTime(StringUtil.isEmpty(entity.getAuditTime()) ? cfg.getAuditTime():entity.getAuditTime());
|
2018-11-28 19:58:34 +08:00
|
|
|
|
list5.add(file);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if(list1.size()>0){
|
|
|
|
|
|
ipList.removeAll(list1);
|
|
|
|
|
|
Map<String,List> map = cfgToMaatConvert(ipRegionList,list1,1,groupRelationList);
|
|
|
|
|
|
groupRelationList=map.get("groupList");
|
|
|
|
|
|
ipRegionList=map.get("dstList");
|
|
|
|
|
|
if(map.get("numRegionList")!=null){
|
|
|
|
|
|
numRegionList.addAll(map.get("numRegionList"));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if(list2.size()>0){
|
|
|
|
|
|
strList.removeAll(list2);
|
|
|
|
|
|
Map<String,List> map = cfgToMaatConvert(strRegionList,list2,2,groupRelationList);
|
|
|
|
|
|
groupRelationList=map.get("groupList");
|
|
|
|
|
|
strRegionList=map.get("dstList");
|
|
|
|
|
|
}
|
|
|
|
|
|
if(list3.size()>0){
|
|
|
|
|
|
complexStrList.removeAll(list3);
|
|
|
|
|
|
Map<String,List> map = cfgToMaatConvert(strRegionList,list3,3,groupRelationList);
|
|
|
|
|
|
groupRelationList=map.get("groupList");
|
|
|
|
|
|
strRegionList=map.get("dstList");
|
|
|
|
|
|
}
|
|
|
|
|
|
if(list4.size()>0){
|
|
|
|
|
|
numList.removeAll(list4);
|
|
|
|
|
|
Map<String,List> map = cfgToMaatConvert(numRegionList,list4,4,groupRelationList);
|
|
|
|
|
|
groupRelationList=map.get("groupList");
|
|
|
|
|
|
numRegionList=map.get("dstList");
|
|
|
|
|
|
}
|
|
|
|
|
|
if(list5.size()>0){
|
|
|
|
|
|
fileList.removeAll(list5);
|
|
|
|
|
|
Map<String,List> map = cfgToMaatConvert(digestRegionList,list5,5,groupRelationList);
|
|
|
|
|
|
groupRelationList=map.get("groupList");
|
|
|
|
|
|
digestRegionList=map.get("dstList");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BeanUtils.copyProperties(cfg, maatCfg);
|
|
|
|
|
|
maatCfg.setAction(cfg.getAction());
|
2018-11-29 09:23:31 +08:00
|
|
|
|
maatCfg.setAuditTime(StringUtil.isEmpty(entity.getAuditTime()) ? cfg.getAuditTime():entity.getAuditTime());
|
2018-11-28 19:58:34 +08:00
|
|
|
|
maatCfg.setIpRegionList(ipRegionList);
|
|
|
|
|
|
maatCfg.setStrRegionList(strRegionList);
|
|
|
|
|
|
maatCfg.setNumRegionList(numRegionList);
|
|
|
|
|
|
maatCfg.setDigestRegionList(digestRegionList);
|
|
|
|
|
|
maatCfg.setGroupRelationList(groupRelationList);
|
|
|
|
|
|
maatCfg.setGroupNum(groupRelationList.size());
|
|
|
|
|
|
maatCfg.setAreaIpRegionList(areaIpRegionList);
|
|
|
|
|
|
maatCfg.setIsValid(entity.getIsValid());
|
|
|
|
|
|
maatCfg.setAuditTime(new Date());
|
|
|
|
|
|
if(!StringUtil.isEmpty(userRegion)){
|
|
|
|
|
|
maatCfg.setUserRegion(userRegion);
|
|
|
|
|
|
}
|
|
|
|
|
|
configCompileList.add(maatCfg);
|
|
|
|
|
|
}
|
|
|
|
|
|
page.setList(list);
|
|
|
|
|
|
if(page.isLastPage()){
|
|
|
|
|
|
hasData = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
if(!StringUtil.isEmpty(configCompileList.size())){
|
|
|
|
|
|
maatBean.setConfigCompileList(configCompileList);
|
|
|
|
|
|
maatBean.setAuditTime(new Date());
|
|
|
|
|
|
maatBean.setCreatorName(UserUtils.getUser().getName());
|
|
|
|
|
|
maatBean.setVersion(Constants.MAAT_VERSION);
|
|
|
|
|
|
maatBean.setOpAction(Constants.INSERT_ACTION);
|
|
|
|
|
|
String json=gsonToJson(maatBean);
|
|
|
|
|
|
//调用服务接口下发配置数据
|
|
|
|
|
|
if(isUpdateCfg) {
|
|
|
|
|
|
logger.info("配置批量下发:"+json);
|
|
|
|
|
|
//调用服务接口同步回调类配置
|
|
|
|
|
|
ToMaatResult result = ConfigServiceUtil.postMaatCfg(json);
|
|
|
|
|
|
if(result!=null){
|
|
|
|
|
|
logger.info("配置批量下发响应信息:"+result.getMsg());
|
|
|
|
|
|
}
|
|
|
|
|
|
}else {
|
|
|
|
|
|
//调用服务接口配置全量更新
|
|
|
|
|
|
// JSONObject result = ConfigServiceUtil.configSync(json,1,entity.getServiceId(),null,(hasData?null:"FINISHED"));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return hasData;
|
|
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 处理ddos配置
|
|
|
|
|
|
* @param serviceId
|
|
|
|
|
|
* @param request
|
|
|
|
|
|
* @param response
|
|
|
|
|
|
* @throws SecurityException
|
|
|
|
|
|
* @throws NoSuchFieldException
|
|
|
|
|
|
* @throws IllegalAccessException
|
|
|
|
|
|
* @throws IllegalArgumentException
|
|
|
|
|
|
*/
|
|
|
|
|
|
public void handleDdosMaatData(List<Map<String,Object>>cfgList,List<Map<String,Object>>userRegionList,
|
|
|
|
|
|
Page<DdosIpCfg> page,BaseCfg entity,HttpServletRequest request,HttpServletResponse response,
|
|
|
|
|
|
boolean isUpdateCfg) throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException{
|
|
|
|
|
|
|
|
|
|
|
|
boolean hasData = true;
|
|
|
|
|
|
while(hasData){
|
|
|
|
|
|
entity.setPage(page);
|
|
|
|
|
|
List<DdosIpCfg> list = configSynchronizationDao.getDdosIpCfgList(entity);
|
|
|
|
|
|
if(!StringUtil.isEmpty(list)){
|
|
|
|
|
|
hasData=auditDdosMaatData(cfgList,userRegionList,
|
|
|
|
|
|
page,entity,list,hasData,isUpdateCfg);
|
|
|
|
|
|
if(hasData) {
|
|
|
|
|
|
page.setPageNo(page.getNext());
|
|
|
|
|
|
}
|
|
|
|
|
|
}else{
|
|
|
|
|
|
hasData = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 处理单域maat配置
|
|
|
|
|
|
* @param serviceId
|
|
|
|
|
|
* @param request
|
|
|
|
|
|
* @param response
|
|
|
|
|
|
* @throws SecurityException
|
|
|
|
|
|
* @throws NoSuchFieldException
|
|
|
|
|
|
* @throws IllegalAccessException
|
|
|
|
|
|
* @throws IllegalArgumentException
|
|
|
|
|
|
*/
|
|
|
|
|
|
public void handleSingleMaatData(int cfgType,List<Map<String,Object>>userRegionList,
|
|
|
|
|
|
Page<T> page,BaseCfg entity,HttpServletRequest request,HttpServletResponse response,
|
|
|
|
|
|
boolean isUpdateCfg) throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException{
|
|
|
|
|
|
|
|
|
|
|
|
boolean hasData = true;
|
|
|
|
|
|
while(hasData){
|
|
|
|
|
|
entity.setPage(page);
|
|
|
|
|
|
List list = Lists.newArrayList();
|
|
|
|
|
|
if(cfgType==1){
|
|
|
|
|
|
list = configSynchronizationDao.getIpPortListByService(entity);
|
|
|
|
|
|
}else if(cfgType==2){
|
|
|
|
|
|
list = configSynchronizationDao.getStrListByService(entity);
|
|
|
|
|
|
}else if(cfgType==3){
|
|
|
|
|
|
list = configSynchronizationDao.getComplexStrListByService(entity);
|
|
|
|
|
|
}
|
|
|
|
|
|
if(!StringUtil.isEmpty(list)){
|
|
|
|
|
|
hasData=auditSingleMaatData(cfgType,userRegionList,
|
|
|
|
|
|
page,entity,list,hasData,isUpdateCfg);
|
|
|
|
|
|
if(hasData) {
|
|
|
|
|
|
page.setPageNo(page.getNext());
|
|
|
|
|
|
}
|
|
|
|
|
|
}else{
|
|
|
|
|
|
hasData = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
|
|
|
* ddos配置批量下发
|
|
|
|
|
|
* @param cfgList
|
|
|
|
|
|
* @param userRegionList
|
|
|
|
|
|
* @param page
|
|
|
|
|
|
* @param entity
|
|
|
|
|
|
* @param list
|
|
|
|
|
|
* @param hasData
|
|
|
|
|
|
* @param isUpdateCfg 业务配置全部生效时需同步更新库表配置状态
|
|
|
|
|
|
* @return
|
|
|
|
|
|
* @throws NoSuchFieldException
|
|
|
|
|
|
* @throws SecurityException
|
|
|
|
|
|
* @throws IllegalArgumentException
|
|
|
|
|
|
* @throws IllegalAccessException
|
|
|
|
|
|
*/
|
|
|
|
|
|
public boolean auditDdosMaatData(List<Map<String,Object>> cfgList,
|
|
|
|
|
|
List<Map<String,Object>>userRegionList,
|
|
|
|
|
|
Page<DdosIpCfg> page,
|
|
|
|
|
|
BaseCfg entity,
|
|
|
|
|
|
List<DdosIpCfg> list,
|
|
|
|
|
|
boolean hasData,
|
|
|
|
|
|
boolean isUpdateCfg) throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException{
|
|
|
|
|
|
ToMaatBean maatBean;
|
|
|
|
|
|
MaatCfg maatCfg;
|
|
|
|
|
|
List<MaatCfg> configCompileList;
|
|
|
|
|
|
List<GroupCfg> groupRelationList;
|
|
|
|
|
|
List<IpCfg> ipRegionList;
|
|
|
|
|
|
List<StringCfg> strRegionList;
|
|
|
|
|
|
List<NumBoundaryCfg> numRegionList;
|
|
|
|
|
|
List<DigestCfg> digestRegionList;
|
|
|
|
|
|
List<IpCfg> areaIpRegionList;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<IpPortCfg> ipList = new ArrayList();
|
|
|
|
|
|
maatBean = new ToMaatBean();
|
|
|
|
|
|
configCompileList = new ArrayList();
|
|
|
|
|
|
//批量获取regionId,groupId
|
|
|
|
|
|
List<Integer> regionIds = ConfigServiceUtil.getId(3, list.size());
|
|
|
|
|
|
List<Integer> groupIds = ConfigServiceUtil.getId(2, list.size());
|
|
|
|
|
|
for(int i=0;i<list.size();i++){
|
|
|
|
|
|
DdosIpCfg cfg=list.get(i);
|
|
|
|
|
|
cfg.setRegionId(regionIds.get(i));
|
|
|
|
|
|
cfg.setGroupId(groupIds.get(i));
|
|
|
|
|
|
cfg.setIsValid(entity.getIsValid());
|
2018-11-29 09:23:31 +08:00
|
|
|
|
cfg.setAuditTime(StringUtil.isEmpty(entity.getAuditTime()) ? cfg.getAuditTime():entity.getAuditTime());
|
2018-11-28 19:58:34 +08:00
|
|
|
|
maatCfg = new MaatCfg();
|
|
|
|
|
|
maatCfg.initDefaultValue();
|
|
|
|
|
|
groupRelationList = new ArrayList();
|
|
|
|
|
|
ipRegionList = new ArrayList();
|
|
|
|
|
|
strRegionList = new ArrayList();
|
|
|
|
|
|
numRegionList = new ArrayList();
|
|
|
|
|
|
digestRegionList = new ArrayList();
|
|
|
|
|
|
areaIpRegionList = new ArrayList();
|
|
|
|
|
|
List<DdosIpCfg> list1 = new ArrayList();
|
|
|
|
|
|
String userRegion = "";
|
|
|
|
|
|
//处理自定义域
|
|
|
|
|
|
if(userRegionList!=null){
|
|
|
|
|
|
for(Map<String,Object> n:userRegionList){
|
|
|
|
|
|
Object userRegionPosition = n.get("userRegionPosition");
|
|
|
|
|
|
if(userRegionPosition!=null && (userRegionPosition.toString().equals("1")||userRegionPosition.toString().equals("0"))){
|
|
|
|
|
|
//通过反射机制获取自定义域字段值
|
|
|
|
|
|
String regionColumn = n.get("regionColumn").toString();
|
|
|
|
|
|
Class aClass = null;
|
|
|
|
|
|
if(userRegionPosition.toString().equals(("0"))){
|
|
|
|
|
|
aClass = BaseCfg.class;
|
|
|
|
|
|
}else{
|
|
|
|
|
|
aClass = DdosIpCfg.class;
|
|
|
|
|
|
}
|
|
|
|
|
|
Object value = "";
|
|
|
|
|
|
Field field = aClass.getDeclaredField(regionColumn);
|
|
|
|
|
|
field.setAccessible(true);
|
|
|
|
|
|
value = field.get(cfg);
|
|
|
|
|
|
if(!StringUtil.isEmpty(value)){
|
|
|
|
|
|
if(StringUtil.isEmpty(n.get("regionKey"))){
|
|
|
|
|
|
userRegion = value.toString();
|
|
|
|
|
|
}else{
|
|
|
|
|
|
userRegion += n.get("regionKey")+"="+value+Constants.USER_REGION_SPLIT;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if(userRegion.endsWith(Constants.USER_REGION_SPLIT)){
|
|
|
|
|
|
userRegion = userRegion.substring(0, userRegion.length()-1);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
list1.add(cfg);
|
|
|
|
|
|
if(list1.size()>0){
|
|
|
|
|
|
ipList.removeAll(list1);
|
|
|
|
|
|
Map<String,List> map = cfgToMaatConvert(ipRegionList,list1,1,groupRelationList);
|
|
|
|
|
|
groupRelationList=map.get("groupList");
|
|
|
|
|
|
ipRegionList=map.get("dstList");
|
|
|
|
|
|
if(map.get("numRegionList")!=null){
|
|
|
|
|
|
numRegionList.addAll(map.get("numRegionList"));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
BeanUtils.copyProperties(cfg, maatCfg);
|
|
|
|
|
|
maatCfg.setAction(cfg.getAction());
|
2018-11-29 09:23:31 +08:00
|
|
|
|
maatCfg.setAuditTime(StringUtil.isEmpty(entity.getAuditTime()) ? cfg.getAuditTime():entity.getAuditTime());
|
2018-11-28 19:58:34 +08:00
|
|
|
|
maatCfg.setIpRegionList(ipRegionList);
|
|
|
|
|
|
maatCfg.setStrRegionList(strRegionList);
|
|
|
|
|
|
maatCfg.setNumRegionList(numRegionList);
|
|
|
|
|
|
maatCfg.setDigestRegionList(digestRegionList);
|
|
|
|
|
|
maatCfg.setGroupRelationList(groupRelationList);
|
|
|
|
|
|
maatCfg.setGroupNum(groupRelationList.size());
|
|
|
|
|
|
maatCfg.setAreaIpRegionList(areaIpRegionList);
|
|
|
|
|
|
maatCfg.setIsValid(entity.getIsValid());
|
|
|
|
|
|
if(!StringUtil.isEmpty(userRegion)){
|
|
|
|
|
|
maatCfg.setUserRegion(userRegion);
|
|
|
|
|
|
}
|
|
|
|
|
|
configCompileList.add(maatCfg);
|
|
|
|
|
|
}
|
|
|
|
|
|
page.setList(list);
|
|
|
|
|
|
if(page.isLastPage()){
|
|
|
|
|
|
hasData = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
if(!StringUtil.isEmpty(configCompileList.size())){
|
|
|
|
|
|
maatBean.setConfigCompileList(configCompileList);
|
|
|
|
|
|
maatBean.setAuditTime(new Date());
|
|
|
|
|
|
maatBean.setCreatorName(UserUtils.getUser().getName());
|
|
|
|
|
|
maatBean.setVersion(Constants.MAAT_VERSION);
|
|
|
|
|
|
maatBean.setOpAction(Constants.INSERT_ACTION);
|
|
|
|
|
|
String json=gsonToJson(maatBean);
|
|
|
|
|
|
//调用服务接口下发配置数据
|
|
|
|
|
|
if(isUpdateCfg) {
|
|
|
|
|
|
logger.info("配置批量下发:"+json);
|
|
|
|
|
|
//调用服务接口同步回调类配置
|
|
|
|
|
|
ToMaatResult result = ConfigServiceUtil.postMaatCfg(json);
|
|
|
|
|
|
if(result!=null){
|
|
|
|
|
|
logger.info("配置批量下发响应信息:"+result.getMsg());
|
|
|
|
|
|
}
|
|
|
|
|
|
}else {
|
|
|
|
|
|
//调用服务接口配置全量更新
|
|
|
|
|
|
JSONObject result = ConfigServiceUtil.configSync(json,1,entity.getServiceId(),null,(hasData?null:"FINISHED"));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
return hasData;
|
|
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 单域配置批量下发
|
|
|
|
|
|
* @param cfgList
|
|
|
|
|
|
* @param userRegionList
|
|
|
|
|
|
* @param page
|
|
|
|
|
|
* @param entity
|
|
|
|
|
|
* @param list
|
|
|
|
|
|
* @param hasData
|
|
|
|
|
|
* @param isUpdateCfg 业务配置全部生效时需同步更新库表配置状态
|
|
|
|
|
|
* @return
|
|
|
|
|
|
* @throws NoSuchFieldException
|
|
|
|
|
|
* @throws SecurityException
|
|
|
|
|
|
* @throws IllegalArgumentException
|
|
|
|
|
|
* @throws IllegalAccessException
|
|
|
|
|
|
*/
|
|
|
|
|
|
public boolean auditSingleMaatData(int cfgType,
|
|
|
|
|
|
List<Map<String,Object>>userRegionList,
|
|
|
|
|
|
Page<T> page,
|
|
|
|
|
|
BaseCfg entity,
|
|
|
|
|
|
List<T> list,
|
|
|
|
|
|
boolean hasData,
|
|
|
|
|
|
boolean isUpdateCfg) throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException{
|
|
|
|
|
|
ToMaatBean maatBean;
|
|
|
|
|
|
MaatCfg maatCfg;
|
|
|
|
|
|
List<MaatCfg> configCompileList;
|
|
|
|
|
|
List<GroupCfg> groupRelationList;
|
|
|
|
|
|
List<IpCfg> ipRegionList;
|
|
|
|
|
|
List<StringCfg> strRegionList;
|
|
|
|
|
|
List<NumBoundaryCfg> numRegionList;
|
|
|
|
|
|
List<DigestCfg> digestRegionList;
|
|
|
|
|
|
List<IpCfg> areaIpRegionList;
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-11-29 10:59:54 +08:00
|
|
|
|
List cfgList = new ArrayList();
|
2018-11-28 19:58:34 +08:00
|
|
|
|
maatBean = new ToMaatBean();
|
|
|
|
|
|
configCompileList = new ArrayList();
|
|
|
|
|
|
//批量获取regionId,groupId
|
|
|
|
|
|
List<Integer> regionIds = ConfigServiceUtil.getId(3, list.size());
|
|
|
|
|
|
List<Integer> groupIds = ConfigServiceUtil.getId(2, list.size());
|
2018-11-29 10:59:54 +08:00
|
|
|
|
IpPortCfg ipCfg = new IpPortCfg();
|
|
|
|
|
|
BaseStringCfg strCfg = new BaseStringCfg();
|
|
|
|
|
|
ComplexkeywordCfg complexStrCfg = new ComplexkeywordCfg();
|
2018-11-28 19:58:34 +08:00
|
|
|
|
for(int i=0;i<list.size();i++){
|
|
|
|
|
|
BaseCfg cfg = new BaseCfg();
|
2018-11-29 10:59:54 +08:00
|
|
|
|
if(cfgType==1){
|
|
|
|
|
|
BeanUtils.copyProperties(list.get(i), ipCfg);
|
|
|
|
|
|
}else if(cfgType==2){
|
|
|
|
|
|
BeanUtils.copyProperties(list.get(i), strCfg);
|
|
|
|
|
|
}else if(cfgType==3){
|
|
|
|
|
|
BeanUtils.copyProperties(list.get(i), complexStrCfg);
|
|
|
|
|
|
}
|
2018-11-28 19:58:34 +08:00
|
|
|
|
BeanUtils.copyProperties(list.get(i), cfg);
|
|
|
|
|
|
cfg.setRegionId(regionIds.get(i));
|
|
|
|
|
|
cfg.setGroupId(groupIds.get(i));
|
|
|
|
|
|
cfg.setIsValid(entity.getIsValid());
|
2018-11-29 09:23:31 +08:00
|
|
|
|
cfg.setAuditTime(StringUtil.isEmpty(entity.getAuditTime()) ? cfg.getAuditTime():entity.getAuditTime());
|
2018-11-28 19:58:34 +08:00
|
|
|
|
maatCfg = new MaatCfg();
|
|
|
|
|
|
maatCfg.initDefaultValue();
|
|
|
|
|
|
groupRelationList = new ArrayList();
|
|
|
|
|
|
ipRegionList = new ArrayList();
|
|
|
|
|
|
strRegionList = new ArrayList();
|
|
|
|
|
|
numRegionList = new ArrayList();
|
|
|
|
|
|
digestRegionList = new ArrayList();
|
|
|
|
|
|
areaIpRegionList = new ArrayList();
|
|
|
|
|
|
List list1 = new ArrayList();
|
|
|
|
|
|
String userRegion = "";
|
|
|
|
|
|
//处理自定义域
|
|
|
|
|
|
if(userRegionList!=null){
|
|
|
|
|
|
for(Map<String,Object> n:userRegionList){
|
|
|
|
|
|
Object userRegionPosition = n.get("userRegionPosition");
|
2018-11-29 10:59:54 +08:00
|
|
|
|
if(userRegionPosition!=null){
|
2018-11-28 19:58:34 +08:00
|
|
|
|
//通过反射机制获取自定义域字段值
|
|
|
|
|
|
String regionColumn = n.get("regionColumn").toString();
|
|
|
|
|
|
Class aClass = null;
|
|
|
|
|
|
if(userRegionPosition.toString().equals(("0"))){
|
|
|
|
|
|
aClass = BaseCfg.class;
|
|
|
|
|
|
}else{
|
|
|
|
|
|
if(cfgType==1){
|
|
|
|
|
|
aClass = IpPortCfg.class;
|
|
|
|
|
|
}else if(cfgType==2){
|
|
|
|
|
|
aClass = BaseStringCfg.class;
|
|
|
|
|
|
}else if(cfgType==3){
|
|
|
|
|
|
aClass = ComplexkeywordCfg.class;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
Object value = "";
|
|
|
|
|
|
Field field = aClass.getDeclaredField(regionColumn);
|
|
|
|
|
|
field.setAccessible(true);
|
2018-11-29 10:59:54 +08:00
|
|
|
|
if(cfgType==1){
|
|
|
|
|
|
value = field.get(ipCfg);
|
|
|
|
|
|
}else if(cfgType==2){
|
|
|
|
|
|
value = field.get(strCfg);
|
|
|
|
|
|
}else if(cfgType==3){
|
|
|
|
|
|
value = field.get(complexStrCfg);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-11-28 19:58:34 +08:00
|
|
|
|
if(!StringUtil.isEmpty(value)){
|
|
|
|
|
|
if(StringUtil.isEmpty(n.get("regionKey"))){
|
|
|
|
|
|
userRegion = value.toString();
|
|
|
|
|
|
}else{
|
|
|
|
|
|
userRegion += n.get("regionKey")+"="+value+Constants.USER_REGION_SPLIT;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if(userRegion.endsWith(Constants.USER_REGION_SPLIT)){
|
|
|
|
|
|
userRegion = userRegion.substring(0, userRegion.length()-1);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2018-11-29 10:59:54 +08:00
|
|
|
|
if(cfgType==1){
|
|
|
|
|
|
ipCfg.setRegionId(regionIds.get(0));
|
|
|
|
|
|
regionIds.remove(0);
|
|
|
|
|
|
ipCfg.setGroupId(groupIds.get(0));
|
|
|
|
|
|
groupIds.remove(0);
|
|
|
|
|
|
list1.add(ipCfg);
|
|
|
|
|
|
}else if(cfgType==2){
|
|
|
|
|
|
strCfg.setRegionId(regionIds.get(0));
|
|
|
|
|
|
regionIds.remove(0);
|
|
|
|
|
|
strCfg.setGroupId(groupIds.get(0));
|
|
|
|
|
|
groupIds.remove(0);
|
|
|
|
|
|
list1.add(strCfg);
|
|
|
|
|
|
}else if(cfgType==3){
|
|
|
|
|
|
complexStrCfg.setRegionId(regionIds.get(0));
|
|
|
|
|
|
regionIds.remove(0);
|
|
|
|
|
|
complexStrCfg.setGroupId(groupIds.get(0));
|
|
|
|
|
|
groupIds.remove(0);
|
|
|
|
|
|
list1.add(complexStrCfg);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-11-28 19:58:34 +08:00
|
|
|
|
if(list1.size()>0){
|
2018-11-29 10:59:54 +08:00
|
|
|
|
cfgList.removeAll(list1);
|
2018-11-28 19:58:34 +08:00
|
|
|
|
if(cfgType==1){
|
|
|
|
|
|
Map<String,List> map = cfgToMaatConvert(ipRegionList,list1,1,groupRelationList);
|
|
|
|
|
|
groupRelationList=map.get("groupList");
|
|
|
|
|
|
ipRegionList=map.get("dstList");
|
|
|
|
|
|
if(map.get("numRegionList")!=null){
|
|
|
|
|
|
numRegionList.addAll(map.get("numRegionList"));
|
|
|
|
|
|
}
|
|
|
|
|
|
}else if(cfgType==2||cfgType==3){
|
|
|
|
|
|
Map<String,List> map = cfgToMaatConvert(strRegionList,list1,2,groupRelationList);
|
|
|
|
|
|
groupRelationList=map.get("groupList");
|
|
|
|
|
|
strRegionList=map.get("dstList");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2018-11-27 16:17:51 +08:00
|
|
|
|
BeanUtils.copyProperties(cfg, maatCfg);
|
|
|
|
|
|
maatCfg.setAction(cfg.getAction());
|
2018-11-29 09:23:31 +08:00
|
|
|
|
maatCfg.setAuditTime(StringUtil.isEmpty(entity.getAuditTime()) ? cfg.getAuditTime():entity.getAuditTime());
|
2018-11-27 16:17:51 +08:00
|
|
|
|
maatCfg.setIpRegionList(ipRegionList);
|
|
|
|
|
|
maatCfg.setStrRegionList(strRegionList);
|
|
|
|
|
|
maatCfg.setNumRegionList(numRegionList);
|
|
|
|
|
|
maatCfg.setDigestRegionList(digestRegionList);
|
|
|
|
|
|
maatCfg.setGroupRelationList(groupRelationList);
|
|
|
|
|
|
maatCfg.setGroupNum(groupRelationList.size());
|
|
|
|
|
|
maatCfg.setAreaIpRegionList(areaIpRegionList);
|
2018-11-28 15:27:49 +08:00
|
|
|
|
maatCfg.setIsValid(entity.getIsValid());
|
2018-11-27 16:17:51 +08:00
|
|
|
|
if(!StringUtil.isEmpty(userRegion)){
|
|
|
|
|
|
maatCfg.setUserRegion(userRegion);
|
|
|
|
|
|
}
|
|
|
|
|
|
configCompileList.add(maatCfg);
|
|
|
|
|
|
}
|
|
|
|
|
|
page.setList(list);
|
|
|
|
|
|
if(page.isLastPage()){
|
|
|
|
|
|
hasData = false;
|
2018-11-26 14:34:24 +08:00
|
|
|
|
}
|
2018-11-27 16:17:51 +08:00
|
|
|
|
if(!StringUtil.isEmpty(configCompileList.size())){
|
|
|
|
|
|
maatBean.setConfigCompileList(configCompileList);
|
|
|
|
|
|
maatBean.setAuditTime(new Date());
|
|
|
|
|
|
maatBean.setCreatorName(UserUtils.getUser().getName());
|
|
|
|
|
|
maatBean.setVersion(Constants.MAAT_VERSION);
|
|
|
|
|
|
maatBean.setOpAction(Constants.INSERT_ACTION);
|
|
|
|
|
|
String json=gsonToJson(maatBean);
|
2018-11-28 12:00:25 +08:00
|
|
|
|
//调用服务接口下发配置数据
|
|
|
|
|
|
if(isUpdateCfg) {
|
|
|
|
|
|
logger.info("配置批量下发:"+json);
|
|
|
|
|
|
//调用服务接口同步回调类配置
|
|
|
|
|
|
ToMaatResult result = ConfigServiceUtil.postMaatCfg(json);
|
|
|
|
|
|
if(result!=null){
|
|
|
|
|
|
logger.info("配置批量下发响应信息:"+result.getMsg());
|
|
|
|
|
|
}
|
|
|
|
|
|
}else {
|
|
|
|
|
|
//调用服务接口配置全量更新
|
2018-11-29 10:59:54 +08:00
|
|
|
|
// JSONObject result = ConfigServiceUtil.configSync(json,1,entity.getServiceId(),null,(hasData?null:"FINISHED"));
|
2018-11-28 12:00:25 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-11-27 16:17:51 +08:00
|
|
|
|
}
|
|
|
|
|
|
return hasData;
|
2018-11-26 14:34:24 +08:00
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 处理app业务maat类配置
|
|
|
|
|
|
* @param serviceId
|
|
|
|
|
|
* @param request
|
|
|
|
|
|
* @param response
|
|
|
|
|
|
*/
|
|
|
|
|
|
public void handleAppMaatData(List<Map<String,Object>>cfgList,List<Map<String,Object>>userRegionList,
|
|
|
|
|
|
Page<BaseCfg> page,Object entity,HttpServletRequest request,HttpServletResponse response){
|
|
|
|
|
|
/*if(entity instanceof AppPolicyCfg){
|
|
|
|
|
|
AppPolicyCfg newEntity = entity;
|
|
|
|
|
|
entity.setPage(page);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
boolean hasData = true;
|
|
|
|
|
|
while(hasData){
|
|
|
|
|
|
List<CfgIndexInfo> list = configSynchronizationDao.getCfgIndexList(entity);
|
|
|
|
|
|
page.setList(list);
|
|
|
|
|
|
if(page.isLastPage()){
|
|
|
|
|
|
hasData = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}*/
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 处理回调类业务配置
|
|
|
|
|
|
* @param serviceId
|
|
|
|
|
|
* @param request
|
|
|
|
|
|
* @param response
|
|
|
|
|
|
* @throws ClassNotFoundException
|
|
|
|
|
|
*/
|
|
|
|
|
|
public void handleCallbackData(String className,
|
|
|
|
|
|
Page<BaseCfg> page,BaseCfg entity,HttpServletRequest request,HttpServletResponse response,
|
|
|
|
|
|
boolean isUpdateCfg) throws ClassNotFoundException{
|
|
|
|
|
|
|
|
|
|
|
|
boolean hasData = true;
|
|
|
|
|
|
while(hasData){
|
|
|
|
|
|
entity.setPage(page);
|
2018-11-27 16:17:51 +08:00
|
|
|
|
hasData=auditCallbackData(className,page,entity,hasData,isUpdateCfg);
|
|
|
|
|
|
if(hasData){
|
2018-11-26 14:34:24 +08:00
|
|
|
|
page.setPageNo(page.getNext());
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2018-11-27 16:17:51 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 回调类配置下发
|
|
|
|
|
|
* @param className
|
|
|
|
|
|
* @param page
|
|
|
|
|
|
* @param entity
|
|
|
|
|
|
* @param hasData
|
|
|
|
|
|
* @param isUpdateCfg
|
|
|
|
|
|
* @throws ClassNotFoundException
|
|
|
|
|
|
*/
|
|
|
|
|
|
public boolean auditCallbackData(String className,
|
|
|
|
|
|
Page<BaseCfg> page,BaseCfg entity,
|
|
|
|
|
|
boolean hasData,
|
|
|
|
|
|
boolean isUpdateCfg) throws ClassNotFoundException{
|
|
|
|
|
|
ToMaatBean maatBean;
|
|
|
|
|
|
MaatCfg maatCfg;
|
|
|
|
|
|
List<MaatCfg> configCompileList;
|
|
|
|
|
|
List<GroupCfg> groupRelationList;
|
|
|
|
|
|
List<IpCfg> ipRegionList;
|
|
|
|
|
|
List<StringCfg> strRegionList;
|
|
|
|
|
|
List<NumBoundaryCfg> numRegionList;
|
|
|
|
|
|
List<DigestCfg> digestRegionList;
|
|
|
|
|
|
List<IpCfg> areaIpRegionList;
|
|
|
|
|
|
|
|
|
|
|
|
maatBean = new ToMaatBean();
|
|
|
|
|
|
configCompileList = new ArrayList();
|
|
|
|
|
|
List list = new ArrayList();
|
|
|
|
|
|
List newList = new ArrayList();
|
|
|
|
|
|
if(className.equals("AvFileSampleCfg")){
|
|
|
|
|
|
list = configSynchronizationDao.getAvFileCfgList(entity);
|
|
|
|
|
|
}else if(className.equals("PxyObjKeyring")){
|
|
|
|
|
|
list = configSynchronizationDao.getPxyObjKeyringCfgList(entity);
|
|
|
|
|
|
for(int i=0;i<list.size();i++){
|
|
|
|
|
|
PxyObjKeyring cfg = (PxyObjKeyring) list.get(i);
|
|
|
|
|
|
newList.add(convertCallBackProxyObjKeyring(cfg));
|
|
|
|
|
|
}
|
|
|
|
|
|
}else if(className.equals("PxyObjTrustedCaCert")){
|
|
|
|
|
|
list = configSynchronizationDao.getPxyObjTrustedCertCfgList(entity);
|
|
|
|
|
|
for(int i=0;i<list.size();i++){
|
|
|
|
|
|
PxyObjTrustedCaCert cfg = (PxyObjTrustedCaCert) list.get(i);
|
|
|
|
|
|
newList.add(convertCallBackProxyObjTrustedCa(cfg,null));
|
|
|
|
|
|
}
|
|
|
|
|
|
}else if(className.equals("PxyObjTrustedCaCrl")){
|
|
|
|
|
|
list = configSynchronizationDao.getPxyObjTrustedCrlCfgList(entity);
|
|
|
|
|
|
for(int i=0;i<list.size();i++){
|
|
|
|
|
|
PxyObjTrustedCaCrl cfg = (PxyObjTrustedCaCrl) list.get(i);
|
|
|
|
|
|
newList.add(convertCallBackProxyObjTrustedCa(null,cfg));
|
|
|
|
|
|
}
|
|
|
|
|
|
}else if(className.equals("DnsResStrategy")){
|
|
|
|
|
|
list = configSynchronizationDao.getDnsStrategyList(entity);
|
|
|
|
|
|
for(int i=0;i<list.size();i++){
|
|
|
|
|
|
DnsResStrategy cfg = (DnsResStrategy) list.get(i);
|
|
|
|
|
|
newList.add(convertCallBackDnsResStrategy(cfg));
|
|
|
|
|
|
}
|
|
|
|
|
|
}else if(className.equals("DnsIpCfg")){
|
|
|
|
|
|
list = configSynchronizationDao.getDnsIpCfgList(entity);
|
|
|
|
|
|
for(int i=0;i<list.size();i++){
|
|
|
|
|
|
DnsIpCfg cfg = (DnsIpCfg) list.get(i);
|
|
|
|
|
|
newList.add(convertCallBackIp(cfg,cfg.getGroupId()));
|
|
|
|
|
|
}
|
|
|
|
|
|
}else if(className.equals("IpPortCfg")){
|
|
|
|
|
|
list = configSynchronizationDao.getIpPortListByService(entity);
|
|
|
|
|
|
for(int i=0;i<list.size();i++){
|
|
|
|
|
|
IpPortCfg cfg = (IpPortCfg) list.get(i);
|
|
|
|
|
|
newList.add(convertCallBackIp(cfg,cfg.getGroupId()));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
page.setList(list);
|
|
|
|
|
|
if(page.isLastPage()){
|
|
|
|
|
|
hasData = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
//调用服务接口下发配置数据
|
|
|
|
|
|
String json=gsonToJson(newList);
|
2018-11-28 12:00:25 +08:00
|
|
|
|
if(isUpdateCfg) {
|
|
|
|
|
|
logger.info("配置批量下发:"+json);
|
|
|
|
|
|
//调用服务接口同步回调类配置
|
|
|
|
|
|
ToMaatResult result = ConfigServiceUtil.postMaatCfg(json);
|
|
|
|
|
|
if(result!=null){
|
|
|
|
|
|
logger.info("配置批量下发响应信息:"+result.getMsg());
|
|
|
|
|
|
}
|
|
|
|
|
|
}else {
|
|
|
|
|
|
logger.info("回调类配置同步:"+json);
|
|
|
|
|
|
//调用服务接口同步回调类配置
|
|
|
|
|
|
JSONObject result = ConfigServiceUtil.configSync(json,2,entity.getServiceId(),entity.getTableName(),(hasData?null:"FINISHED"));
|
|
|
|
|
|
// logger.info("回调类配置同步:"+result.getMsg());
|
|
|
|
|
|
}
|
2018-11-27 16:17:51 +08:00
|
|
|
|
|
|
|
|
|
|
return hasData;
|
|
|
|
|
|
}
|
2018-11-26 14:34:24 +08:00
|
|
|
|
}
|