3655 lines
162 KiB
Java
3655 lines
162 KiB
Java
package com.nis.web.service;
|
||
|
||
import java.io.IOException;
|
||
import java.lang.reflect.Array;
|
||
import java.lang.reflect.Field;
|
||
import java.lang.reflect.Type;
|
||
import java.math.BigDecimal;
|
||
import java.nio.charset.Charset;
|
||
import java.sql.SQLException;
|
||
import java.text.SimpleDateFormat;
|
||
import java.util.ArrayList;
|
||
import java.util.Arrays;
|
||
import java.util.Collection;
|
||
import java.util.Date;
|
||
import java.util.HashMap;
|
||
import java.util.List;
|
||
import java.util.Map;
|
||
import java.util.Map.Entry;
|
||
import java.util.Set;
|
||
import java.util.HashSet;
|
||
import com.nis.domain.basics.*;
|
||
import com.nis.domain.configuration.*;
|
||
import com.nis.util.*;
|
||
import com.nis.web.dao.CrudDao;
|
||
import com.nis.web.dao.basics.*;
|
||
import com.nis.web.dao.configuration.*;
|
||
import org.apache.commons.collections.CollectionUtils;
|
||
import org.apache.commons.collections.MapUtils;
|
||
import org.apache.commons.lang3.StringEscapeUtils;
|
||
import org.apache.ibatis.session.ExecutorType;
|
||
import org.apache.ibatis.session.SqlSession;
|
||
import org.apache.ibatis.session.SqlSessionFactory;
|
||
import org.slf4j.Logger;
|
||
import org.slf4j.LoggerFactory;
|
||
import org.springframework.beans.BeanUtils;
|
||
import org.springframework.transaction.annotation.Transactional;
|
||
|
||
import com.beust.jcommander.internal.Maps;
|
||
import com.google.common.collect.Lists;
|
||
import com.google.gson.Gson;
|
||
import com.google.gson.GsonBuilder;
|
||
import com.google.gson.JsonElement;
|
||
import com.google.gson.JsonPrimitive;
|
||
import com.google.gson.JsonSerializationContext;
|
||
import com.google.gson.JsonSerializer;
|
||
import com.google.gson.TypeAdapter;
|
||
import com.google.gson.internal.LinkedTreeMap;
|
||
import com.google.gson.reflect.TypeToken;
|
||
import com.google.gson.stream.JsonReader;
|
||
import com.google.gson.stream.JsonToken;
|
||
import com.google.gson.stream.JsonWriter;
|
||
import com.googlecode.ipv6.IPv6Address;
|
||
import com.googlecode.ipv6.IPv6Network;
|
||
import com.nis.domain.FunctionRegionDict;
|
||
import com.nis.domain.FunctionServiceDict;
|
||
import com.nis.domain.ScheduleCfg;
|
||
import com.nis.domain.SysRole;
|
||
import com.nis.domain.SysUser;
|
||
import com.nis.domain.basics.AsnGroupInfo;
|
||
import com.nis.domain.basics.AsnIpCfg;
|
||
import com.nis.domain.callback.InlineIp;
|
||
import com.nis.domain.callback.NtcDnsResStrategy;
|
||
import com.nis.domain.callback.ProxyFileHijackCfg;
|
||
import com.nis.domain.callback.ProxyFileHijackCfgAudit;
|
||
import com.nis.domain.callback.ProxyFileInsertScriptCfg;
|
||
import com.nis.domain.callback.ProxyFileInsertScriptCfgAudit;
|
||
import com.nis.domain.callback.ProxyFileResponsePageCfg;
|
||
import com.nis.domain.callback.ProxyFileResponsePageCfgAudit;
|
||
import com.nis.domain.callback.ProxyFileStrategyCfg;
|
||
import com.nis.domain.callback.ProxyFileStrategyCfgAudit;
|
||
import com.nis.domain.callback.ProxyFileTrafficMirrorCfg;
|
||
import com.nis.domain.callback.ProxyFileTrafficMirrorCfgAudit;
|
||
import com.nis.domain.callback.ProxyObjKeyring;
|
||
import com.nis.domain.callback.ProxyObjTrustedCa;
|
||
import com.nis.domain.configuration.AppComplexFeatureCfg;
|
||
import com.nis.domain.configuration.AppDomainCfg;
|
||
import com.nis.domain.configuration.AppFeatureIndex;
|
||
import com.nis.domain.configuration.AppHttpCfg;
|
||
import com.nis.domain.configuration.AppIpCfg;
|
||
import com.nis.domain.configuration.AppPolicyCfg;
|
||
import com.nis.domain.configuration.AppTopicDomainCfg;
|
||
import com.nis.domain.configuration.AreaBean;
|
||
import com.nis.domain.configuration.AreaIpCfg;
|
||
import com.nis.domain.configuration.BaseCfg;
|
||
import com.nis.domain.configuration.BaseIpCfg;
|
||
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.IpReusePolicyCfg;
|
||
import com.nis.domain.configuration.NtcSubscribeIdCfg;
|
||
import com.nis.domain.configuration.PxyObjKeyring;
|
||
import com.nis.domain.configuration.PxyObjSpoofingIpPool;
|
||
import com.nis.domain.configuration.PxyObjTrustedCaCert;
|
||
import com.nis.domain.configuration.PxyObjTrustedCaCrl;
|
||
import com.nis.domain.configuration.WebsiteDomainTopic;
|
||
import com.nis.domain.maat.GroupReuseAddBean;
|
||
import com.nis.domain.maat.GroupReuseCfg;
|
||
import com.nis.domain.maat.MaatCfg;
|
||
import com.nis.domain.maat.ManipulatActionParam;
|
||
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.domain.maat.ManipulatActionParam.ReplaceCfg;
|
||
import com.nis.domain.maat.ToMaatBean;
|
||
import com.nis.domain.maat.ToMaatResult;
|
||
import com.nis.domain.specific.ConfigGroupInfo;
|
||
import com.nis.domain.specific.SpecificServiceCfg;
|
||
import com.nis.exceptions.MaatConvertException;
|
||
//import com.nis.util.AsnCacheUtils;
|
||
import com.nis.util.ConfigServiceUtil;
|
||
import com.nis.util.Configurations;
|
||
import com.nis.util.Constants;
|
||
import com.nis.util.DictUtils;
|
||
import com.nis.util.IpUtil;
|
||
import com.nis.util.Reflections;
|
||
import com.nis.util.StringUtil;
|
||
import com.nis.util.StringUtils;
|
||
import com.nis.web.dao.SchedulerDao;
|
||
import com.nis.web.dao.basics.AsnGroupInfoDao;
|
||
import com.nis.web.dao.basics.AsnIpCfgDao;
|
||
import com.nis.web.dao.configuration.AppCfgDao;
|
||
import com.nis.web.dao.configuration.AppMultiFeatureCfgDao;
|
||
import com.nis.web.dao.configuration.DdosCfgDao;
|
||
import com.nis.web.dao.configuration.DnsIpCfgDao;
|
||
import com.nis.web.dao.configuration.DnsResStrategyDao;
|
||
import com.nis.web.dao.configuration.IpCfgDao;
|
||
import com.nis.web.dao.configuration.PxyObjSpoofingIpPoolDao;
|
||
import com.nis.web.dao.configuration.StringCfgDao;
|
||
import com.nis.web.dao.specific.ConfigGroupInfoDao;
|
||
import com.nis.web.dao.specific.SpecificServiceCfgDao;
|
||
import com.nis.web.security.UserUtils;
|
||
import com.nis.web.service.basics.SysDictInfoService;
|
||
|
||
/**
|
||
* Service基类
|
||
*
|
||
* @author ThinkGem
|
||
* @version 2014-05-16
|
||
*/
|
||
public abstract class BaseService {
|
||
|
||
/**
|
||
* 日志对象
|
||
*/
|
||
protected Logger logger = LoggerFactory.getLogger(getClass());
|
||
|
||
/**
|
||
* 数据范围过滤
|
||
*
|
||
* @param user
|
||
* 当前用户对象,通过“entity.getCurrentUser()”获取
|
||
* @param officeAlias
|
||
* 机构表别名,多个用“,”逗号隔开。
|
||
* @param userAlias
|
||
* 用户表别名,多个用“,”逗号隔开,传递空,忽略此参数
|
||
* @return 标准连接条件对象
|
||
*/
|
||
public static String dataScopeFilter(SysUser user, String officeAlias, String userAlias) {
|
||
|
||
StringBuilder sqlString = new StringBuilder();
|
||
|
||
// 进行权限过滤,多个角色权限范围之间为或者关系。
|
||
List<Integer> dataScope = Lists.newArrayList();
|
||
|
||
if (StringUtils.isBlank(user.getLoginId())) {
|
||
return "";
|
||
}
|
||
|
||
// 超级管理员,跳过权限过滤
|
||
if (user.isAdmin()) {
|
||
boolean isDataScopeAll = isContainsDataScopeAll(user.getUserRoleList());
|
||
|
||
for (SysRole r : user.getUserRoleList()) {
|
||
for (String oa : StringUtils.split(officeAlias, ",")) {
|
||
if (!dataScope.contains(r.getDataScope()) && StringUtils.isNotBlank(oa)) {
|
||
|
||
sqlString.append(createScopeSql(r.getDataScope(), oa, user, null));
|
||
dataScope.add(r.getDataScope());
|
||
}
|
||
}
|
||
}
|
||
// 如果没有全部数据权限,并设置了用户别名,则当前权限为本人;如果未设置别名,当前无权限为已植入权限
|
||
if (!isDataScopeAll) {
|
||
if (StringUtils.isNotBlank(userAlias)) {
|
||
for (String ua : StringUtils.split(userAlias, ",")) {
|
||
sqlString.append(" OR " + ua + ".id = '" + user.getId() + "'");
|
||
}
|
||
} else {
|
||
for (String oa : StringUtils.split(officeAlias, ",")) {
|
||
// sqlString.append(" OR " + oa + ".id = " + user.getOffice().getId());
|
||
sqlString.append(" OR " + oa + ".id IS NULL");
|
||
}
|
||
}
|
||
} else {
|
||
// 如果包含全部权限,则去掉之前添加的所有条件,并跳出循环。
|
||
sqlString = new StringBuilder();
|
||
}
|
||
}
|
||
if (StringUtils.isNotBlank(sqlString.toString())) {
|
||
return " AND (" + sqlString.substring(4) + ")";
|
||
}
|
||
return "";
|
||
}
|
||
|
||
/**
|
||
* 数据范围过滤
|
||
*
|
||
* @param user
|
||
* 当前用户对象,通过“entity.getCurrentUser()”获取
|
||
* @param configAlias
|
||
* 配置表别名,多个用","逗号隔开,传递空,忽略此参数
|
||
* @return 标准连接条件对象
|
||
*/
|
||
public static String configScopeFilter(SysUser user, String configAlias) {
|
||
|
||
StringBuilder sqlString = new StringBuilder();
|
||
|
||
// 进行权限过滤,多个角色权限范围之间为或者关系。
|
||
List<Integer> dataScope = Lists.newArrayList();
|
||
|
||
if (StringUtils.isBlank(user.getLoginId())) {
|
||
return "";
|
||
}
|
||
|
||
// 超级管理员,跳过权限过滤
|
||
if (!user.isAdmin()) {
|
||
boolean isDataScopeAll = isContainsDataScopeAll(user.getUserRoleList());
|
||
// 如果没有全部数据权限
|
||
if (!isDataScopeAll) {
|
||
for (SysRole r : user.getUserRoleList()) {
|
||
for (String c : StringUtils.split(configAlias, ",")) {
|
||
if (!dataScope.contains(r.getDataScope()) && StringUtils.isNotBlank(c)) {
|
||
sqlString.append(createScopeSql(r.getDataScope(), "", user, c));
|
||
dataScope.add(r.getDataScope());
|
||
}
|
||
}
|
||
}
|
||
|
||
} else {
|
||
// 如果包含全部权限,则去掉之前添加的所有条件但增加配置审核取消以及删除的配置,并跳出循环。
|
||
sqlString = new StringBuilder();
|
||
// sqlString.append(" OR " + configAlias + ".is_audit !=3");
|
||
sqlString.append(" OR " + configAlias + ".creator_id <> 1");
|
||
}
|
||
}
|
||
if (StringUtils.isNotBlank(sqlString.toString())) {
|
||
return " AND (" + sqlString.substring(4) + ")";
|
||
}
|
||
return "";
|
||
}
|
||
|
||
/**
|
||
* 测试数据是否包含全集
|
||
*
|
||
* @return
|
||
*/
|
||
private static boolean isContainsDataScopeAll(List<SysRole> roleList) {
|
||
boolean isDataScopeAll = false;
|
||
|
||
for (SysRole role : roleList) {
|
||
if (SysRole.DATA_SCOPE_ALL.equals(role.getDataScope())) {
|
||
isDataScopeAll = true;
|
||
break;
|
||
}
|
||
}
|
||
|
||
return isDataScopeAll;
|
||
|
||
}
|
||
|
||
/**
|
||
* 过滤机构信息
|
||
*
|
||
* @param dataScope
|
||
* 数据范围(1:所有数据;2:所在公司及以下数据;3:所在公司数据;
|
||
* 4:所在部门及以下数据;5:所在部门数据;6:所在单位及以下数据;7:所在单位数据;
|
||
* 8:操作员数据;9:审核员数据,10:审计员数据)
|
||
* @return
|
||
*/
|
||
private static String createScopeSql(int dataScope, String officeAlias, SysUser user, String configAlias) {
|
||
StringBuilder scopeSql = new StringBuilder(1024);
|
||
|
||
if (SysRole.DATA_SCOPE_COMPANY_AND_CHILD.equals(dataScope)) {
|
||
scopeSql.append(" OR " + officeAlias + ".id = " + user.getCompany().getId());
|
||
scopeSql.append(" OR " + officeAlias + ".parent_ids LIKE '" + user.getCompany().getParentIds()
|
||
+ user.getCompany().getId() + ",%'");
|
||
} else if (SysRole.DATA_SCOPE_COMPANY.equals(dataScope)) {
|
||
scopeSql.append(" OR " + officeAlias + ".id = " + user.getCompany().getId());
|
||
// 包括本公司下的部门 (type=1:公司;type=2:单位 3.部门)
|
||
scopeSql.append(" OR (" + officeAlias + ".parent_id = '" + user.getCompany().getId() + "' AND "
|
||
+ officeAlias + ".type>1)");
|
||
} else if (SysRole.DATA_SCOPE_OFFICE_AND_CHILD.equals(dataScope)) {
|
||
scopeSql.append(" OR " + officeAlias + ".id = " + user.getOffice().getId());
|
||
scopeSql.append(" OR " + officeAlias + ".parent_ids LIKE '" + user.getOffice().getParentIds()
|
||
+ user.getOffice().getId() + ",%'");
|
||
} else if (SysRole.DATA_SCOPE_OFFICE.equals(dataScope)) {
|
||
scopeSql.append(" OR " + officeAlias + ".id = " + user.getOffice().getId());
|
||
} else if (SysRole.DATA_SCOPE_ENTITY_AND_CHILD.equals(dataScope)) {
|
||
scopeSql.append(" OR " + officeAlias + ".id = " + user.getEntity().getId());
|
||
scopeSql.append(" OR " + officeAlias + ".parent_ids LIKE '" + user.getEntity().getParentIds()
|
||
+ user.getEntity().getId() + ",%'");
|
||
|
||
} else if (SysRole.DATA_SCOPE_ENTITY.equals(dataScope)) {
|
||
scopeSql.append(" OR " + officeAlias + ".id = " + user.getEntity().getId());
|
||
// 包括本公司下的部门 (type=1:公司;type=2:单位 3.部门)
|
||
scopeSql.append(" OR (" + officeAlias + ".parent_id = '" + user.getEntity().getId() + "' AND " + officeAlias
|
||
+ ".type>1)");
|
||
|
||
} else if (SysRole.DATA_SCOPE_CREATOR.equals(dataScope)) {//操作员【非管理员用户数据】
|
||
// scopeSql.append(" OR " + configAlias + ".is_audit !=3");
|
||
scopeSql.append(" OR " + configAlias + ".creator_id <>1 ");
|
||
} else if (SysRole.DATA_SCOPE_AUDITOR.equals(dataScope)) {//审核员【未审核和审核通过状态的非管理员用户数据】
|
||
scopeSql.append(" OR (" + configAlias + ".is_audit = 0 OR " + configAlias + ".is_audit = 1)");
|
||
scopeSql.append(" AND " + configAlias + ".creator_id <>1 ");
|
||
} else if (SysRole.DATA_SCOPE_SHOWER.equals(dataScope)) {//审计员【审核通过状态的非管理员用户数据】
|
||
scopeSql.append(" OR " + configAlias + ".is_audit = 1");
|
||
scopeSql.append(" AND " + configAlias + ".creator_id <>1 ");
|
||
}
|
||
|
||
return scopeSql.toString();
|
||
}
|
||
|
||
/**
|
||
*
|
||
* getTableName(获取表名对应的Class) (这里描述这个方法适用条件 – 可选)
|
||
*
|
||
* @param tableName
|
||
* @return String
|
||
* @exception @since
|
||
* 1.0.0
|
||
*/
|
||
public String getClassName(String tableName) {
|
||
return Configurations.getStringProperty(tableName, null);
|
||
}
|
||
|
||
public static class MapTypeAdapter extends TypeAdapter<Object> {
|
||
@Override
|
||
public Object read(JsonReader in) throws IOException {
|
||
JsonToken token = in.peek();
|
||
switch (token) {
|
||
case BEGIN_ARRAY:
|
||
List<Object> list = new ArrayList<Object>();
|
||
in.beginArray();
|
||
while (in.hasNext()) {
|
||
list.add(read(in));
|
||
}
|
||
in.endArray();
|
||
return list;
|
||
|
||
case BEGIN_OBJECT:
|
||
Map<String, Object> map = new LinkedTreeMap<String, Object>();
|
||
in.beginObject();
|
||
while (in.hasNext()) {
|
||
map.put(in.nextName(), read(in));
|
||
}
|
||
in.endObject();
|
||
return map;
|
||
|
||
case STRING:
|
||
return in.nextString();
|
||
|
||
case NUMBER:
|
||
String temp = in.nextString();
|
||
BigDecimal dbNum = new BigDecimal(temp);
|
||
BigDecimal maxLong = new BigDecimal(Long.MAX_VALUE);
|
||
BigDecimal maxInteger = new BigDecimal(Integer.MAX_VALUE);
|
||
// 数字超过long的最大值,返回BigDecimal类型
|
||
if (dbNum.compareTo(maxLong) == 1) {
|
||
return dbNum;
|
||
} else if (dbNum.compareTo(maxInteger) == 1) {
|
||
long lngNum = Long.parseLong(temp);
|
||
return lngNum;
|
||
} else {
|
||
int lngNum = Integer.parseInt(temp);
|
||
return lngNum;
|
||
}
|
||
|
||
case BOOLEAN:
|
||
return in.nextBoolean();
|
||
|
||
case NULL:
|
||
in.nextNull();
|
||
return null;
|
||
|
||
default:
|
||
throw new IllegalStateException();
|
||
}
|
||
}
|
||
|
||
@Override
|
||
public void write(JsonWriter out, Object value) throws IOException {
|
||
// 序列化无需实现
|
||
}
|
||
|
||
}
|
||
|
||
/**
|
||
* 转换成字符串
|
||
*
|
||
* @param obj
|
||
* @return
|
||
*/
|
||
public static <T> String gsonToJson(T obj) {
|
||
Gson gson = new GsonBuilder().disableHtmlEscaping().excludeFieldsWithoutExposeAnnotation()
|
||
.registerTypeAdapter(Date.class, new JsonSerializer<Date>() {
|
||
@Override
|
||
public JsonElement serialize(Date src, Type type, JsonSerializationContext context) {
|
||
String format = "yyyy-MM-dd HH:mm:ss";
|
||
long time = ((Date) src).getTime();
|
||
SimpleDateFormat sdf = new SimpleDateFormat(format);
|
||
return new JsonPrimitive(sdf.format(time));
|
||
}
|
||
}).create();
|
||
return gson.toJson(obj);
|
||
}
|
||
|
||
/**
|
||
* 字符串转成对象
|
||
*
|
||
* @param jsonString
|
||
* @param cls
|
||
* @return
|
||
*/
|
||
public static <T> T gsonFromJson(String jsonString, Class<T> cls) {
|
||
Gson gson = new GsonBuilder().registerTypeAdapter(new TypeToken<Map>() {
|
||
}.getType(), new MapTypeAdapter()).registerTypeAdapter(new TypeToken<List>() {
|
||
}.getType(), new MapTypeAdapter()).create();
|
||
return gson.fromJson(jsonString, cls);
|
||
}
|
||
|
||
/**
|
||
* 界面配置list转换为服务接口端的list
|
||
*
|
||
* @param <T>
|
||
* @param <T>
|
||
* @param dstList
|
||
* @param srcList
|
||
* @param cfgType,1为IP类型,2为字符串类型,3为增强字符串,4数值类型,5摘要类,6回调类[但字符串类域配置和增强字符串域配置在接口参数中同属于strRegionList]
|
||
* @param baseCfg,配置基本信息
|
||
* @param groupRelationList
|
||
* 配置分组列表
|
||
* @return
|
||
*/
|
||
public static <T> Map<String, List> cfgConvert(List dstList, List<T> srcList, Integer cfgType, BaseCfg baseCfg,
|
||
List groupRelationList) {
|
||
Map<String, List> map = new HashMap();
|
||
if (cfgType == 1) {
|
||
List numRegionList = new ArrayList();
|
||
Integer groupId = 0;
|
||
Integer numGroupId = 0;
|
||
List<Integer> regionIdList = ConfigServiceUtil.getId(3, srcList.size());
|
||
for (int i = 0; i < srcList.size(); i++) {
|
||
T srcCfg = srcList.get(i);
|
||
BaseIpCfg baseIpCfg = new BaseIpCfg();
|
||
BeanUtils.copyProperties(srcCfg, baseIpCfg);
|
||
IpCfg cfg = new IpCfg();
|
||
BeanUtils.copyProperties(baseIpCfg, cfg);
|
||
// 区域IP配置,多条IP配置属于同一个分组,其他业务配置IP,一条配置一个分组
|
||
// if(groupId==0 || !cfg.getCfgType().equals(Constants.AREA_REGION)){
|
||
if (groupId == 0) {
|
||
GroupCfg group = new GroupCfg();
|
||
groupId = ConfigServiceUtil.getId(2, 1).get(0);
|
||
group.setGroupId(groupId);
|
||
group.setCompileId(baseCfg.getCompileId());
|
||
group.setAuditTime(baseCfg.getAuditTime());
|
||
group.setIsValid(baseCfg.getIsValid());
|
||
groupRelationList.add(group);
|
||
}
|
||
cfg.setGroupId(groupId);
|
||
cfg.setAuditTime(baseCfg.getAuditTime());
|
||
cfg.setIsValid(baseCfg.getIsValid());
|
||
List<IpCfg> cfgs = ipConvert(cfg, baseIpCfg);
|
||
if (cfgs.size() > 1) {
|
||
List<Integer> ids = ConfigServiceUtil.getId(3, cfgs.size() - 1);
|
||
regionIdList.addAll(ids);
|
||
}
|
||
for (int j = i; j < cfgs.size() + i; j++) {
|
||
cfgs.get(j - i).setRegionId(regionIdList.get(j));
|
||
}
|
||
dstList.addAll(cfgs);
|
||
|
||
// 如果protocolId非空非零,需要构造数值型域配置,多条相同协议的IP只需要一条数值域配置(目前没有不同协议IP&情况)
|
||
if (baseIpCfg.getProtocolId() != null && baseIpCfg.getProtocolId() != 0) {
|
||
if (numGroupId == 0) {
|
||
GroupCfg group1 = new GroupCfg();
|
||
group1.setGroupId(ConfigServiceUtil.getId(2, 1).get(0));
|
||
group1.setCompileId(baseIpCfg.getCompileId());
|
||
group1.setAuditTime(baseCfg.getAuditTime());
|
||
group1.setIsValid(baseCfg.getIsValid());
|
||
groupRelationList.add(group1);
|
||
NumBoundaryCfg numCfg = new NumBoundaryCfg();
|
||
numCfg.initDefaultValue();
|
||
numCfg.setLowBoundary(baseIpCfg.getProtocolId());
|
||
numCfg.setUpBoundary(baseIpCfg.getProtocolId());
|
||
numCfg.setRegionId(ConfigServiceUtil.getId(3, 1).get(0));
|
||
numCfg.setAuditTime(baseCfg.getAuditTime());
|
||
numCfg.setGroupId(group1.getGroupId());
|
||
numCfg.setIsValid(baseCfg.getIsValid());
|
||
numRegionList.add(numCfg);
|
||
map.put("numRegionList", numRegionList);
|
||
numGroupId++;
|
||
}
|
||
}
|
||
}
|
||
|
||
} else if (cfgType == 2 || cfgType == 3) {
|
||
List<Integer> groupIdList = ConfigServiceUtil.getId(2, srcList.size());
|
||
List<Integer> regionIdList = ConfigServiceUtil.getId(3, srcList.size());
|
||
for (int i = 0; i < srcList.size(); i++) {
|
||
// 一条业务配置创建一个分组
|
||
GroupCfg group = new GroupCfg();
|
||
StringCfg cfg = new StringCfg();
|
||
BeanUtils.copyProperties(srcList.get(i), cfg);
|
||
group.setGroupId(groupIdList.get(i));
|
||
group.setCompileId(baseCfg.getCompileId());
|
||
group.setAuditTime(baseCfg.getAuditTime());
|
||
group.setIsValid(baseCfg.getIsValid());
|
||
groupRelationList.add(group);
|
||
cfg.setGroupId(group.getGroupId());
|
||
cfg.setRegionId(regionIdList.get(i));
|
||
cfg.setAuditTime(baseCfg.getAuditTime());
|
||
cfg.setIsValid(baseCfg.getIsValid());
|
||
// 处理配置关键字转译
|
||
cfg.setCfgKeywords(keywordsEscape(cfg.getCfgKeywords()));
|
||
// 增强字符串转换
|
||
cfg.setDistrict(keywordsEscape(cfg.getDistrict()));
|
||
dstList.add(cfg);
|
||
}
|
||
} else if (cfgType == 4) {
|
||
List<Integer> groupIdList = ConfigServiceUtil.getId(2, srcList.size());
|
||
List<Integer> regionIdList = ConfigServiceUtil.getId(3, srcList.size());
|
||
for (int i = 0; i < srcList.size(); i++) {
|
||
// 一条业务配置创建一个分组
|
||
com.nis.domain.maat.MaatCfg.NumBoundaryCfg cfg = new com.nis.domain.maat.MaatCfg.NumBoundaryCfg();
|
||
BeanUtils.copyProperties(srcList.get(i), cfg);
|
||
GroupCfg group = new GroupCfg();
|
||
group.setGroupId(groupIdList.get(i));
|
||
group.setCompileId(baseCfg.getCompileId());
|
||
group.setAuditTime(baseCfg.getAuditTime());
|
||
group.setIsValid(baseCfg.getIsValid());
|
||
groupRelationList.add(group);
|
||
cfg.setGroupId(group.getGroupId());
|
||
cfg.setRegionId(regionIdList.get(i));
|
||
cfg.setAuditTime(baseCfg.getAuditTime());
|
||
cfg.setIsValid(baseCfg.getIsValid());
|
||
dstList.add(cfg);
|
||
}
|
||
} else if (cfgType == 5) {
|
||
List<Integer> groupIdList = ConfigServiceUtil.getId(2, srcList.size());
|
||
List<Integer> regionIdList = ConfigServiceUtil.getId(3, srcList.size());
|
||
for (int i = 0; i < srcList.size(); i++) {
|
||
// 一条业务配置创建一个分组
|
||
com.nis.domain.maat.MaatCfg.DigestCfg cfg = new com.nis.domain.maat.MaatCfg.DigestCfg();
|
||
BeanUtils.copyProperties(srcList.get(i), cfg);
|
||
GroupCfg group = new GroupCfg();
|
||
group.setGroupId(groupIdList.get(i));
|
||
group.setCompileId(baseCfg.getCompileId());
|
||
group.setAuditTime(baseCfg.getAuditTime());
|
||
group.setIsValid(baseCfg.getIsValid());
|
||
groupRelationList.add(group);
|
||
cfg.setGroupId(group.getGroupId());
|
||
cfg.setRegionId(regionIdList.get(i));
|
||
cfg.setAuditTime(baseCfg.getAuditTime());
|
||
cfg.setIsValid(baseCfg.getIsValid());
|
||
dstList.add(cfg);
|
||
}
|
||
} else {
|
||
dstList.addAll(srcList);
|
||
}
|
||
map.put("groupList", groupRelationList);
|
||
map.put("dstList", dstList);
|
||
return map;
|
||
}
|
||
/**
|
||
* maatCfg转换,不支持callback,注意除了ip类型的range转换完成之后需要额外获取region id之外,其他需要在src中设置 compileId,regionId,regoup id
|
||
* 如果ip类型协议id不为空,需要设置numberRegionGroupId,numberRegionRegionId。
|
||
* @param src
|
||
* @param cfgType,1为IP类型,2为字符串类型,3为增强字符串,4数值类型,5摘要类[但字符串类域配置和增强字符串域配置在接口参数中同属于strRegionList]
|
||
* @return Map<String,List>
|
||
* @throws IllegalAccessException
|
||
* @throws IllegalArgumentException
|
||
*/
|
||
public static <T> Map<String,List> cfgConvert(BaseCfg<T> src, Integer cfgType) {
|
||
Map<String,List> map=Maps.newHashMap();
|
||
List groupRelationList=Lists.newArrayList();
|
||
Field compileIdF= Reflections.getAccessibleField(src, "compileId");
|
||
Field groupIdF= Reflections.getAccessibleField(src, "groupId");
|
||
Field regionIdF= Reflections.getAccessibleField(src, "regionId");
|
||
try {
|
||
if(compileIdF==null||compileIdF.get(src)==null) {
|
||
throw new RuntimeException("Please set compileId first");
|
||
}
|
||
if(groupIdF==null||groupIdF.get(src)==null) {
|
||
throw new RuntimeException("Please set groupId first");
|
||
}
|
||
if(regionIdF==null||regionIdF.get(src)==null) {
|
||
throw new RuntimeException("Please set regionId first");
|
||
}
|
||
} catch (IllegalArgumentException | IllegalAccessException e) {
|
||
// TODO Auto-generated catch block
|
||
e.printStackTrace();
|
||
}
|
||
|
||
if (cfgType == 1) {
|
||
List<IpCfg> ipcfgs=Lists.newArrayList();
|
||
List numRegionList = new ArrayList();
|
||
BaseIpCfg baseIpCfg = new BaseIpCfg();
|
||
BeanUtils.copyProperties(src, baseIpCfg);
|
||
Integer groupId = baseIpCfg.getGroupId();
|
||
Integer numGroupId = 0;
|
||
IpCfg cfg = new IpCfg();
|
||
BeanUtils.copyProperties(baseIpCfg, cfg);
|
||
// 区域IP配置,多条IP配置属于同一个分组,其他业务配置IP,一条配置一个分组
|
||
// if(groupId==0 || !cfg.getCfgType().equals(Constants.AREA_REGION)){
|
||
GroupCfg group = new GroupCfg();
|
||
if (groupId == 0) {
|
||
groupId = ConfigServiceUtil.getId(2, 1).get(0);
|
||
}
|
||
group.setGroupId(groupId);
|
||
group.setCompileId(baseIpCfg.getCompileId());
|
||
group.setAuditTime(baseIpCfg.getAuditTime());
|
||
group.setIsValid(baseIpCfg.getIsValid());
|
||
groupRelationList.add(group);
|
||
cfg.setGroupId(groupId);
|
||
cfg.setAuditTime(baseIpCfg.getAuditTime());
|
||
cfg.setIsValid(baseIpCfg.getIsValid());
|
||
List<IpCfg> cfgs = ipConvert(cfg, baseIpCfg);
|
||
List<Integer> regionIdList=Lists.newArrayListWithCapacity(cfgs.size() - 1);
|
||
if (cfgs.size() > 1) {
|
||
List<Integer> ids = ConfigServiceUtil.getId(3, cfgs.size() - 1);
|
||
regionIdList.addAll(ids);
|
||
}
|
||
for (int i = 1; i < cfgs.size(); i++) {
|
||
cfgs.get(i).setRegionId(regionIdList.get(i-1));
|
||
}
|
||
ipcfgs.addAll(cfgs);
|
||
map.put("ipRegionList", ipcfgs);
|
||
// 如果protocolId非空非零,需要构造数值型域配置,多条相同协议的IP只需要一条数值域配置(目前没有不同协议IP&情况)
|
||
if (baseIpCfg.getProtocolId() != null && baseIpCfg.getProtocolId() != 0) {
|
||
if (numGroupId == 0) {
|
||
GroupCfg group1 = new GroupCfg();
|
||
//group1.setGroupId(groupId);
|
||
if(baseIpCfg.getNumberRegionGroupId()!=null) {
|
||
group1.setGroupId(baseIpCfg.getNumberRegionGroupId());
|
||
}else {
|
||
group1.setGroupId(ConfigServiceUtil.getId(2, 1).get(0));
|
||
}
|
||
group1.setCompileId(baseIpCfg.getCompileId());
|
||
group1.setAuditTime(baseIpCfg.getAuditTime());
|
||
group1.setIsValid(baseIpCfg.getIsValid());
|
||
groupRelationList.add(group1);
|
||
NumBoundaryCfg numCfg = new NumBoundaryCfg();
|
||
numCfg.initDefaultValue();
|
||
numCfg.setLowBoundary(baseIpCfg.getProtocolId());
|
||
numCfg.setUpBoundary(baseIpCfg.getProtocolId());
|
||
if(baseIpCfg.getNumberRegionRegionId()!=null) {
|
||
numCfg.setRegionId(baseIpCfg.getNumberRegionRegionId());
|
||
}else {
|
||
numCfg.setRegionId(ConfigServiceUtil.getId(3, 1).get(0));
|
||
}
|
||
numCfg.setAuditTime(baseIpCfg.getAuditTime());
|
||
numCfg.setGroupId(group1.getGroupId());
|
||
numCfg.setIsValid(baseIpCfg.getIsValid());
|
||
numRegionList.add(numCfg);
|
||
map.put("numRegionList", numRegionList);
|
||
numGroupId++;
|
||
}
|
||
}
|
||
} else if (cfgType == 2 || cfgType == 3) {
|
||
List<StringCfg> stringcfgs=Lists.newArrayList();
|
||
// 一条业务配置创建一个分组
|
||
BaseCfg baseCfg=(BaseCfg)src;
|
||
GroupCfg group = new GroupCfg();
|
||
StringCfg cfg = new StringCfg();
|
||
BeanUtils.copyProperties(src, cfg);
|
||
group.setGroupId(baseCfg.getGroupId());
|
||
group.setCompileId(baseCfg.getCompileId());
|
||
group.setAuditTime(baseCfg.getAuditTime());
|
||
group.setIsValid(baseCfg.getIsValid());
|
||
groupRelationList.add(group);
|
||
cfg.setGroupId(group.getGroupId());
|
||
cfg.setRegionId(baseCfg.getRegionId());
|
||
cfg.setAuditTime(baseCfg.getAuditTime());
|
||
cfg.setIsValid(baseCfg.getIsValid());
|
||
// 处理配置关键字转译
|
||
cfg.setCfgKeywords(keywordsEscape(cfg.getCfgKeywords()));
|
||
// 增强字符串转换
|
||
cfg.setDistrict(keywordsEscape(cfg.getDistrict()));
|
||
stringcfgs.add(cfg);
|
||
map.put("strRegionList", stringcfgs);
|
||
} else if (cfgType == 4) {
|
||
List<com.nis.domain.maat.MaatCfg.NumBoundaryCfg> numCfgs=Lists.newArrayList();
|
||
// 一条业务配置创建一个分组
|
||
BaseCfg baseCfg=(BaseCfg)src;
|
||
com.nis.domain.maat.MaatCfg.NumBoundaryCfg cfg = new com.nis.domain.maat.MaatCfg.NumBoundaryCfg();
|
||
BeanUtils.copyProperties(src, cfg);
|
||
GroupCfg group = new GroupCfg();
|
||
group.setGroupId(baseCfg.getGroupId());
|
||
group.setCompileId(baseCfg.getCompileId());
|
||
group.setAuditTime(baseCfg.getAuditTime());
|
||
group.setIsValid(baseCfg.getIsValid());
|
||
groupRelationList.add(group);
|
||
cfg.setGroupId(group.getGroupId());
|
||
cfg.setRegionId(baseCfg.getRegionId());
|
||
cfg.setAuditTime(baseCfg.getAuditTime());
|
||
cfg.setIsValid(baseCfg.getIsValid());
|
||
numCfgs.add(cfg);
|
||
map.put("numRegionList", numCfgs);
|
||
} else if (cfgType == 5) {
|
||
List<com.nis.domain.maat.MaatCfg.DigestCfg> digestCfgs=Lists.newArrayList();
|
||
BaseCfg baseCfg=(BaseCfg)src;
|
||
// 一条业务配置创建一个分组
|
||
com.nis.domain.maat.MaatCfg.DigestCfg cfg = new com.nis.domain.maat.MaatCfg.DigestCfg();
|
||
BeanUtils.copyProperties(src, cfg);
|
||
GroupCfg group = new GroupCfg();
|
||
group.setGroupId(baseCfg.getGroupId());
|
||
group.setCompileId(baseCfg.getCompileId());
|
||
group.setAuditTime(baseCfg.getAuditTime());
|
||
group.setIsValid(baseCfg.getIsValid());
|
||
groupRelationList.add(group);
|
||
cfg.setGroupId(group.getGroupId());
|
||
cfg.setRegionId(baseCfg.getRegionId());
|
||
cfg.setAuditTime(baseCfg.getAuditTime());
|
||
cfg.setIsValid(baseCfg.getIsValid());
|
||
digestCfgs.add(cfg);
|
||
map.put("digestRegionList", digestCfgs);
|
||
} else {
|
||
throw new RuntimeException("unknown cfgType "+cfgType);
|
||
}
|
||
map.put("groupRelationList", groupRelationList);
|
||
return map;
|
||
}
|
||
|
||
/**
|
||
* 界面配置list转换为服务接口端的list,用于批量下发时,regionId,groupId已在该方法前被批量获取
|
||
*
|
||
* @param <T>
|
||
* @param <T>
|
||
* @param dstList
|
||
* @param srcList
|
||
* @param cfgType,1为IP类型,2为字符串类型,3为增强字符串,4数值类型,5摘要类,6回调类[但字符串类域配置和增强字符串域配置在接口参数中同属于strRegionList]
|
||
* @param groupRelationList
|
||
* 配置分组列表
|
||
* @return
|
||
*/
|
||
public static <T> Map<String, List> cfgToMaatConvert(List dstList, List<T> srcList, Integer cfgType,List groupRelationList) {
|
||
Map<String, List> map = new HashMap();
|
||
if (cfgType == 1) {
|
||
List numRegionList = new ArrayList();
|
||
Integer groupId = 0;
|
||
Integer numGroupId = 0;
|
||
for (int i = 0; i < srcList.size(); i++) {
|
||
List<Integer> regionIdList = Lists.newArrayList();
|
||
T srcCfg = srcList.get(i);
|
||
BaseIpCfg baseIpCfg = new BaseIpCfg();
|
||
BeanUtils.copyProperties(srcCfg, baseIpCfg);
|
||
regionIdList.add(baseIpCfg.getRegionId());
|
||
IpCfg cfg = new IpCfg();
|
||
BeanUtils.copyProperties(baseIpCfg, cfg);
|
||
//多条IP配置属于同一个分组
|
||
if (groupId == 0) {
|
||
GroupCfg group = new GroupCfg();
|
||
groupId = baseIpCfg.getGroupId();
|
||
group.setGroupId(groupId);
|
||
group.setCompileId(baseIpCfg.getCompileId());
|
||
group.setAuditTime(baseIpCfg.getAuditTime());
|
||
group.setIsValid(baseIpCfg.getIsValid());
|
||
groupRelationList.add(group);
|
||
}
|
||
cfg.setGroupId(groupId);
|
||
cfg.setAuditTime(baseIpCfg.getAuditTime());
|
||
cfg.setIsValid(baseIpCfg.getIsValid());
|
||
List<IpCfg> cfgs = ipConvert(cfg, baseIpCfg);
|
||
if (cfgs.size() > 1) {
|
||
List<Integer> ids = ConfigServiceUtil.getId(3, cfgs.size() - 1);
|
||
regionIdList.addAll(ids);
|
||
}
|
||
for (int j = i; j < cfgs.size() + i; j++) {
|
||
cfgs.get(j - i).setRegionId(regionIdList.get(j));
|
||
}
|
||
dstList.addAll(cfgs);
|
||
|
||
// 如果protocolId非空非零,需要构造数值型域配置,多条相同协议的IP只需要一条数值域配置(目前没有不同协议IP&情况)
|
||
if (baseIpCfg.getProtocolId() != null && baseIpCfg.getProtocolId() != 0) {
|
||
if (numGroupId == 0) {
|
||
GroupCfg group1 = new GroupCfg();
|
||
group1.setGroupId(ConfigServiceUtil.getId(2, 1).get(0));
|
||
group1.setCompileId(baseIpCfg.getCompileId());
|
||
group1.setAuditTime(baseIpCfg.getAuditTime());
|
||
group1.setIsValid(baseIpCfg.getIsValid());
|
||
groupRelationList.add(group1);
|
||
NumBoundaryCfg numCfg = new NumBoundaryCfg();
|
||
numCfg.initDefaultValue();
|
||
numCfg.setLowBoundary(baseIpCfg.getProtocolId());
|
||
numCfg.setUpBoundary(baseIpCfg.getProtocolId());
|
||
numCfg.setRegionId(ConfigServiceUtil.getId(3, 1).get(0));
|
||
numCfg.setAuditTime(baseIpCfg.getAuditTime());
|
||
numCfg.setGroupId(group1.getGroupId());
|
||
numCfg.setIsValid(baseIpCfg.getIsValid());
|
||
numRegionList.add(numCfg);
|
||
map.put("numRegionList", numRegionList);
|
||
numGroupId++;
|
||
}
|
||
}
|
||
}
|
||
|
||
} else if (cfgType == 2 || cfgType == 3) {
|
||
for (int i = 0; i < srcList.size(); i++) {
|
||
// 一条业务配置创建一个分组
|
||
BaseCfg baseCfg = new BaseCfg();
|
||
BeanUtils.copyProperties(srcList.get(i), baseCfg);//拷贝公共属性
|
||
GroupCfg group = new GroupCfg();
|
||
StringCfg cfg = new StringCfg();
|
||
BeanUtils.copyProperties(srcList.get(i), cfg);//拷贝公共属性以及私有属性
|
||
group.setGroupId(baseCfg.getGroupId());
|
||
group.setCompileId(baseCfg.getCompileId());
|
||
group.setAuditTime(baseCfg.getAuditTime());
|
||
group.setIsValid(baseCfg.getIsValid());
|
||
groupRelationList.add(group);
|
||
cfg.setGroupId(group.getGroupId());
|
||
cfg.setRegionId(baseCfg.getRegionId());
|
||
cfg.setAuditTime(baseCfg.getAuditTime());
|
||
cfg.setIsValid(baseCfg.getIsValid());
|
||
// 处理配置关键字转译
|
||
cfg.setCfgKeywords(keywordsEscape(cfg.getCfgKeywords()));
|
||
// 增强字符串转换
|
||
cfg.setDistrict(keywordsEscape(cfg.getDistrict()));
|
||
dstList.add(cfg);
|
||
}
|
||
} else if (cfgType == 4) {
|
||
for (int i = 0; i < srcList.size(); i++) {
|
||
BaseCfg baseCfg = new BaseCfg();
|
||
BeanUtils.copyProperties(srcList.get(i), baseCfg);//拷贝公共属性
|
||
// 一条业务配置创建一个分组
|
||
com.nis.domain.maat.MaatCfg.NumBoundaryCfg cfg = new com.nis.domain.maat.MaatCfg.NumBoundaryCfg();
|
||
BeanUtils.copyProperties(srcList.get(i), cfg);
|
||
GroupCfg group = new GroupCfg();
|
||
group.setGroupId(baseCfg.getGroupId());
|
||
group.setCompileId(baseCfg.getCompileId());
|
||
group.setAuditTime(baseCfg.getAuditTime());
|
||
group.setIsValid(baseCfg.getIsValid());
|
||
groupRelationList.add(group);
|
||
cfg.setGroupId(group.getGroupId());
|
||
cfg.setRegionId(baseCfg.getRegionId());
|
||
cfg.setAuditTime(baseCfg.getAuditTime());
|
||
cfg.setIsValid(baseCfg.getIsValid());
|
||
dstList.add(cfg);
|
||
}
|
||
} else if (cfgType == 5) {
|
||
for (int i = 0; i < srcList.size(); i++) {
|
||
BaseCfg baseCfg = new BaseCfg();
|
||
BeanUtils.copyProperties(srcList.get(i), baseCfg);//拷贝公共属性
|
||
// 一条业务配置创建一个分组
|
||
com.nis.domain.maat.MaatCfg.DigestCfg cfg = new com.nis.domain.maat.MaatCfg.DigestCfg();
|
||
BeanUtils.copyProperties(srcList.get(i), cfg);
|
||
GroupCfg group = new GroupCfg();
|
||
group.setGroupId(baseCfg.getGroupId());
|
||
group.setCompileId(baseCfg.getCompileId());
|
||
group.setAuditTime(baseCfg.getAuditTime());
|
||
group.setIsValid(baseCfg.getIsValid());
|
||
groupRelationList.add(group);
|
||
cfg.setGroupId(group.getGroupId());
|
||
cfg.setRegionId(baseCfg.getRegionId());
|
||
cfg.setAuditTime(baseCfg.getAuditTime());
|
||
cfg.setIsValid(baseCfg.getIsValid());
|
||
dstList.add(cfg);
|
||
}
|
||
} else {
|
||
dstList.addAll(srcList);
|
||
}
|
||
map.put("groupList", groupRelationList);
|
||
map.put("dstList", dstList);
|
||
return map;
|
||
}
|
||
/**
|
||
* 界面IP配置转换为MAAT类或者回调类IP配置
|
||
*
|
||
* @param dstIp
|
||
* @param srcIp
|
||
* @return
|
||
*/
|
||
/*
|
||
* public static IpCfg ipConvert(IpCfg dstIp,BaseIpCfg srcIp){
|
||
* if(srcIp.getSrcIpAddress()!=null){
|
||
* if(srcIp.getSrcIpAddress().indexOf("/")!=-1){ if(srcIp.getIpType()==4 ||
|
||
* srcIp.getIpType()==46){//46表示源ip为ipv4,目的ip为ipv6 Integer srcMaskNum =
|
||
* Integer.parseInt(srcIp.getSrcIpAddress().split("/")[1]); if(srcMaskNum==0){
|
||
* dstIp.setSrcIpMask("0.0.0.0"); }else{
|
||
* dstIp.setSrcIpMask(IpUtil.convertMask(srcMaskNum)); }
|
||
*
|
||
* dstIp.setSrcIp(srcIp.getSrcIpAddress().split("/")[0]); }else
|
||
* if(srcIp.getIpType()==6|| srcIp.getIpType()==64){//64表示源ip为ipv6,目的ip为ipv4
|
||
* IPv6Network strangeNetwork = IPv6Network.fromString(srcIp.getSrcIpAddress());
|
||
* dstIp.setSrcIp(srcIp.getSrcIpAddress().split("/")[0]);
|
||
* dstIp.setSrcIpMask(strangeNetwork.getNetmask().asAddress().toString()); }else
|
||
* { Pattern patternV4Subnet=Pattern.compile(Constants.IPV4_IP_SUBNET_REGEXP);
|
||
* Pattern patternV6Subnet=Pattern.compile(Constants.IPV6_IP_SUBNET_REGEXP);
|
||
* Matcher matchernV4Subnet=patternV4Subnet.matcher(srcIp.getSrcIpAddress());
|
||
* Matcher matcherV6Subnet=patternV6Subnet.matcher(srcIp.getSrcIpAddress());
|
||
* if(matchernV4Subnet.matches()) { Integer srcMaskNum =
|
||
* Integer.parseInt(srcIp.getSrcIpAddress().split("/")[1]); if(srcMaskNum==0){
|
||
* dstIp.setSrcIpMask("0.0.0.0"); }else{
|
||
* dstIp.setSrcIpMask(IpUtil.convertMask(srcMaskNum)); }
|
||
* dstIp.setSrcIp(srcIp.getSrcIpAddress().split("/")[0]); }else
|
||
* if(matcherV6Subnet.matches()){ IPv6Network strangeNetwork =
|
||
* IPv6Network.fromString(srcIp.getSrcIpAddress());
|
||
* dstIp.setSrcIp(srcIp.getSrcIpAddress().split("/")[0]);
|
||
* dstIp.setSrcIpMask(strangeNetwork.getNetmask().asAddress().toString()); }else
|
||
* { throw new RuntimeException("Invalid IP/subnet mask format"); } }
|
||
*
|
||
* }else if(srcIp.getSrcIpAddress().indexOf("-")!=-1){ if(srcIp.getIpType()==4||
|
||
* srcIp.getIpType()==46){//46表示源ip为ipv4,目的ip为ipv6
|
||
* dstIp.setSrcIp(srcIp.getSrcIpAddress().split("-")[0]);
|
||
* dstIp.setSrcIpMask(IpUtil.getMask(srcIp.getSrcIpAddress().split("-")[0],
|
||
* srcIp.getSrcIpAddress().split("-")[1])); }else if(srcIp.getIpType()==6||
|
||
* srcIp.getIpType()==64){//64表示源ip为ipv6,目的ip为ipv4 IPv6Address address1 =
|
||
* IPv6Address.fromString(srcIp.getSrcIpAddress().split("-")[0]); IPv6Address
|
||
* address2 = IPv6Address.fromString(srcIp.getSrcIpAddress().split("-")[1]);
|
||
* IPv6Network network = IPv6Network.fromTwoAddresses(address1,address2);
|
||
* dstIp.setSrcIp(address1.toString());
|
||
* dstIp.setSrcIpMask(network.getNetmask().asAddress().toString()); }else {
|
||
* Pattern patternV4Range=Pattern.compile(Constants.IPV4_IP_RANGE_REGEXP);
|
||
* Pattern patternV6Range=Pattern.compile(Constants.IPV6_IP_RANGE_REGEXP);
|
||
* Matcher matcherV4Range=patternV4Range.matcher(srcIp.getSrcIpAddress());
|
||
* Matcher matcherV6Range=patternV6Range.matcher(srcIp.getSrcIpAddress());
|
||
* if(matcherV4Range.matches()) {
|
||
* dstIp.setSrcIp(srcIp.getSrcIpAddress().split("-")[0]);
|
||
* dstIp.setSrcIpMask(IpUtil.getMask(srcIp.getSrcIpAddress().split("-")[0],
|
||
* srcIp.getSrcIpAddress().split("-")[1])); }else if(matcherV6Range.matches()) {
|
||
* IPv6Address address1 =
|
||
* IPv6Address.fromString(srcIp.getSrcIpAddress().split("-")[0]); IPv6Address
|
||
* address2 = IPv6Address.fromString(srcIp.getSrcIpAddress().split("-")[1]);
|
||
* IPv6Network network = IPv6Network.fromTwoAddresses(address1,address2);
|
||
* dstIp.setSrcIp(address1.toString());
|
||
* dstIp.setSrcIpMask(network.getNetmask().asAddress().toString()); }else {
|
||
* throw new RuntimeException("Invalid IP range format"); } }
|
||
*
|
||
* }else{ if(srcIp.getIpType()==4||
|
||
* srcIp.getIpType()==46){//46表示源ip为ipv4,目的ip为ipv6
|
||
* dstIp.setSrcIp(srcIp.getSrcIpAddress());
|
||
* dstIp.setSrcIpMask("255.255.255.255"); }else if(srcIp.getIpType()==6||
|
||
* srcIp.getIpType()==64){//64表示源ip为ipv6,目的ip为ipv4
|
||
* dstIp.setSrcIp(srcIp.getSrcIpAddress());
|
||
* dstIp.setSrcIpMask("FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF"); }else {//all
|
||
* Pattern patternV4=Pattern.compile(Constants.IPV4_IP_REGEXP); Pattern
|
||
* patternV6=Pattern.compile(Constants.IPV6_IP_REGEXP); Matcher
|
||
* matcherV4=patternV4.matcher(srcIp.getSrcIpAddress()); Matcher
|
||
* matcherV6=patternV6.matcher(srcIp.getSrcIpAddress()); if(matcherV4.matches())
|
||
* { dstIp.setSrcIp(srcIp.getSrcIpAddress());
|
||
* dstIp.setSrcIpMask("255.255.255.255"); }else if(matcherV6.matches()) {
|
||
* dstIp.setSrcIp(srcIp.getSrcIpAddress());
|
||
* dstIp.setSrcIpMask("FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF"); }else { throw
|
||
* new RuntimeException("Invalid IP format"); } }
|
||
*
|
||
* } }else{ if(srcIp.getIpType()==4||
|
||
* srcIp.getIpType()==46){//46表示源ip为ipv4,目的ip为ipv6
|
||
* dstIp.setSrcIp(srcIp.getSrcIpAddress());
|
||
* dstIp.setSrcIpMask("255.255.255.255"); }else if(srcIp.getIpType()==6||
|
||
* srcIp.getIpType()==64){//64表示源ip为ipv6,目的ip为ipv4
|
||
* dstIp.setSrcIp(srcIp.getSrcIpAddress());
|
||
* dstIp.setSrcIpMask("FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF"); }else {//all
|
||
* dstIp.setSrcIp(srcIp.getSrcIpAddress());
|
||
* dstIp.setSrcIpMask("255.255.255.255"); } }
|
||
* if(srcIp.getDestIpAddress()!=null){
|
||
* if(srcIp.getDestIpAddress().indexOf("/")!=-1){ if(srcIp.getIpType()==4||
|
||
* srcIp.getIpType()==64){//64表示源ip为ipv6,目的ip为ipv4 Integer dstMaskNum =
|
||
* Integer.parseInt(srcIp.getDestIpAddress().split("/")[1]); if(dstMaskNum==0){
|
||
* dstIp.setDstIpMask("0.0.0.0"); }else{
|
||
* dstIp.setDstIpMask(IpUtil.convertMask(dstMaskNum));; }
|
||
* dstIp.setDstIp(srcIp.getDestIpAddress().split("/")[0]); }else
|
||
* if(srcIp.getIpType()==6|| srcIp.getIpType()==46){//46表示源ip为ipv4,目的ip为ipv6
|
||
* IPv6Network strangeNetwork =
|
||
* IPv6Network.fromString(srcIp.getDestIpAddress());
|
||
* dstIp.setDstIp(srcIp.getDestIpAddress().split("/")[0]);
|
||
* dstIp.setDstIpMask(strangeNetwork.getNetmask().asAddress().toString()); }else
|
||
* { Pattern patternV4Subnet=Pattern.compile(Constants.IPV4_IP_SUBNET_REGEXP);
|
||
* Pattern patternV6Subnet=Pattern.compile(Constants.IPV6_IP_SUBNET_REGEXP);
|
||
* Matcher matchernV4Subnet=patternV4Subnet.matcher(srcIp.getDestIpAddress());
|
||
* Matcher matcherV6Subnet=patternV6Subnet.matcher(srcIp.getDestIpAddress());
|
||
* if(matchernV4Subnet.matches()) { Integer dstMaskNum =
|
||
* Integer.parseInt(srcIp.getDestIpAddress().split("/")[1]); if(dstMaskNum==0){
|
||
* dstIp.setDstIpMask("0.0.0.0"); }else{
|
||
* dstIp.setDstIpMask(IpUtil.convertMask(dstMaskNum));; }
|
||
* dstIp.setDstIp(srcIp.getDestIpAddress().split("/")[0]); }else
|
||
* if(matcherV6Subnet.matches()){ IPv6Network strangeNetwork =
|
||
* IPv6Network.fromString(srcIp.getDestIpAddress());
|
||
* dstIp.setDstIp(srcIp.getDestIpAddress().split("/")[0]);
|
||
* dstIp.setDstIpMask(strangeNetwork.getNetmask().asAddress().toString()); }else
|
||
* { throw new RuntimeException("Invalid IP/subnet mask format"); } }
|
||
*
|
||
* }else if(srcIp.getDestIpAddress().indexOf("-")!=-1){
|
||
* if(srcIp.getIpType()==4|| srcIp.getIpType()==64){//64表示源ip为ipv6,目的ip为ipv4
|
||
* dstIp.setDstIp(srcIp.getDestIpAddress().split("-")[0]);
|
||
* dstIp.setDstIpMask(IpUtil.getMask(srcIp.getDestIpAddress().split("-")[0],
|
||
* srcIp.getDestIpAddress().split("-")[1])); }else if(srcIp.getIpType()==6||
|
||
* srcIp.getIpType()==46){//46表示源ip为ipv4,目的ip为ipv6 IPv6Address address1 =
|
||
* IPv6Address.fromString(srcIp.getDestIpAddress().split("-")[0]); IPv6Address
|
||
* address2 = IPv6Address.fromString(srcIp.getDestIpAddress().split("-")[1]);
|
||
* IPv6Network network = IPv6Network.fromTwoAddresses(address1,address2);
|
||
* dstIp.setDstIp(address1.toString());
|
||
* dstIp.setDstIpMask(network.getNetmask().asAddress().toString()); }else {
|
||
* Pattern patternV4Range=Pattern.compile(Constants.IPV4_IP_RANGE_REGEXP);
|
||
* Pattern patternV6Range=Pattern.compile(Constants.IPV6_IP_RANGE_REGEXP);
|
||
* Matcher matcherV4Range=patternV4Range.matcher(srcIp.getDestIpAddress());
|
||
* Matcher matcherV6Range=patternV6Range.matcher(srcIp.getDestIpAddress());
|
||
* if(matcherV4Range.matches()) {
|
||
* dstIp.setDstIp(srcIp.getDestIpAddress().split("-")[0]);
|
||
* dstIp.setDstIpMask(IpUtil.getMask(srcIp.getDestIpAddress().split("-")[0],
|
||
* srcIp.getDestIpAddress().split("-")[1])); }else if(matcherV6Range.matches())
|
||
* { IPv6Address address1 =
|
||
* IPv6Address.fromString(srcIp.getDestIpAddress().split("-")[0]); IPv6Address
|
||
* address2 = IPv6Address.fromString(srcIp.getDestIpAddress().split("-")[1]);
|
||
* IPv6Network network = IPv6Network.fromTwoAddresses(address1,address2);
|
||
* dstIp.setDstIp(address1.toString());
|
||
* dstIp.setDstIpMask(network.getNetmask().asAddress().toString()); }else {
|
||
* throw new RuntimeException("Invalid IP range format"); } }
|
||
*
|
||
* }else{ if(srcIp.getIpType()==4||
|
||
* srcIp.getIpType()==64){//64表示源ip为ipv6,目的ip为ipv4
|
||
* dstIp.setDstIp(srcIp.getDestIpAddress());
|
||
* dstIp.setDstIpMask("255.255.255.255"); }else if(srcIp.getIpType()==6||
|
||
* srcIp.getIpType()==46){//46表示源ip为ipv4,目的ip为ipv6
|
||
* dstIp.setDstIp(srcIp.getDestIpAddress());
|
||
* dstIp.setDstIpMask("FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF"); }else {//all
|
||
* Pattern patternV4=Pattern.compile(Constants.IPV4_IP_REGEXP); Pattern
|
||
* patternV6=Pattern.compile(Constants.IPV6_IP_REGEXP); Matcher
|
||
* matcherV4=patternV4.matcher(srcIp.getDestIpAddress()); Matcher
|
||
* matcherV6=patternV6.matcher(srcIp.getDestIpAddress());
|
||
* if(matcherV4.matches()) { dstIp.setDstIp(srcIp.getDestIpAddress());
|
||
* dstIp.setDstIpMask("255.255.255.255"); }else if(matcherV6.matches()) {
|
||
* dstIp.setDstIp(srcIp.getDestIpAddress());
|
||
* dstIp.setDstIpMask("FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF"); }else { throw
|
||
* new RuntimeException("invalid ip format"); } }
|
||
*
|
||
* } }else{ if(srcIp.getIpType()==4||
|
||
* srcIp.getIpType()==64){//64表示源ip为ipv6,目的ip为ipv4
|
||
* dstIp.setDstIp(srcIp.getDestIpAddress());
|
||
* dstIp.setDstIpMask("255.255.255.255"); }else if(srcIp.getIpType()==6||
|
||
* srcIp.getIpType()==46){//46表示源ip为ipv4,目的ip为ipv6
|
||
* dstIp.setDstIp(srcIp.getDestIpAddress());
|
||
* dstIp.setDstIpMask("FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF"); }else {//all
|
||
* dstIp.setDstIp(srcIp.getDestIpAddress());
|
||
* dstIp.setDstIpMask("255.255.255.255"); } } if(srcIp.getSrcPort()!=null){
|
||
* if(srcIp.getSrcPort().indexOf("/")!=-1){ String srcMaskNum =
|
||
* srcIp.getSrcPort().split("/")[1]; dstIp.setSrcPortMask(srcMaskNum);
|
||
* dstIp.setSrcPort(srcIp.getSrcPort().split("/")[0]); }else{
|
||
* dstIp.setSrcPort(srcIp.getSrcPort()); dstIp.setSrcPortMask("65535"); } }else{
|
||
* dstIp.setSrcPort("0"); dstIp.setSrcPortMask("65535"); }
|
||
* if(srcIp.getDestPort()!=null){ if(srcIp.getDestPort().indexOf("/")!=-1){
|
||
* String dstMaskNum = srcIp.getDestPort().split("/")[1];
|
||
* dstIp.setDstPortMask(dstMaskNum);
|
||
* dstIp.setDstPort(srcIp.getDestPort().split("/")[0]); }else{
|
||
* dstIp.setDstPort(srcIp.getDestPort()); dstIp.setDstPortMask("65535"); }
|
||
* }else{ dstIp.setDstPort("0"); dstIp.setDstPortMask("65535"); } return dstIp;
|
||
* }
|
||
*/
|
||
/**
|
||
* 界面IP配置转换为MAAT类或者回调类IP配置
|
||
*
|
||
* @param dstIp
|
||
* @param srcIp
|
||
* @return
|
||
*/
|
||
public static List<IpCfg> ipConvert(IpCfg dstIp, BaseIpCfg srcIp) {
|
||
List<IpCfg> ipConvertList = Lists.newArrayList();
|
||
List<IpCfg> tempList = Lists.newArrayList();
|
||
List<IpCfg> tempList1 = Lists.newArrayList();
|
||
if (srcIp.getIpType().equals(4)) {// IP V4
|
||
if(srcIp.getSrcIpPattern().equals(2)) {//源IP范围
|
||
if (srcIp.getSrcIpAddress() != null) {
|
||
String startIpPart = srcIp.getSrcIpAddress().split("-")[0];
|
||
String endIpPart = srcIp.getSrcIpAddress().split("-")[1];
|
||
Integer startNum = Integer.parseInt(startIpPart.split("\\.")[3]);
|
||
Integer endNum = Integer.parseInt(endIpPart.split("\\.")[3]);
|
||
for (int i = startNum; i <= endNum; i++) {
|
||
IpCfg tempIp = new IpCfg();
|
||
BeanUtils.copyProperties(dstIp, tempIp);
|
||
tempIp.setSrcIp(startIpPart.substring(0, startIpPart.lastIndexOf(".") + 1) + i);
|
||
tempIp.setSrcIpMask("255.255.255.255");
|
||
tempList.add(tempIp);
|
||
}
|
||
}else {
|
||
dstIp.setSrcIp("0.0.0.0");
|
||
dstIp.setSrcIpMask("255.255.255.255");
|
||
tempList.add(dstIp);
|
||
}
|
||
}else if(srcIp.getSrcIpPattern().equals(1)){
|
||
Integer srcMaskNum = Integer.parseInt(srcIp.getSrcIpAddress().split("/")[1]);
|
||
if (srcMaskNum == 0) {
|
||
dstIp.setSrcIpMask("0.0.0.0");
|
||
} else {
|
||
dstIp.setSrcIpMask(IpUtil.convertMask(srcMaskNum));
|
||
}
|
||
dstIp.setSrcIp(srcIp.getSrcIpAddress().split("/")[0]);
|
||
tempList.add(dstIp);
|
||
}else if(srcIp.getSrcIpPattern().equals(3)){
|
||
dstIp.setSrcIp(srcIp.getSrcIpAddress());
|
||
dstIp.setSrcIpMask("255.255.255.255");
|
||
tempList.add(dstIp);
|
||
}else {
|
||
throw new RuntimeException("Unsupported IP Pattern " + srcIp.getSrcIpPattern());
|
||
}
|
||
if (srcIp.getDestIpAddress() != null) {
|
||
if(srcIp.getDestIpPattern().equals(2)) {
|
||
String startIpPart = srcIp.getDestIpAddress().split("-")[0];
|
||
String endIpPart = srcIp.getDestIpAddress().split("-")[1];
|
||
Integer startNum = Integer.parseInt(startIpPart.split("\\.")[3]);
|
||
Integer endNum = Integer.parseInt(endIpPart.split("\\.")[3]);
|
||
for (IpCfg _cfg : tempList) {
|
||
for (int i = startNum; i <= endNum; i++) {
|
||
IpCfg tempIp = new IpCfg();
|
||
BeanUtils.copyProperties(_cfg, tempIp);
|
||
tempIp.setDstIp(startIpPart.substring(0, startIpPart.lastIndexOf(".") + 1) + i);
|
||
tempIp.setDstIpMask("255.255.255.255");
|
||
// 处理
|
||
convertPortValues(tempIp, srcIp);
|
||
if (!tempIp.getSrcIp().equals(tempIp.getDstIp())) {
|
||
tempList1.add(tempIp);
|
||
}
|
||
|
||
}
|
||
}
|
||
tempList.clear();
|
||
}else if(srcIp.getDestIpPattern().equals(1)) {
|
||
Integer dstMaskNum = Integer.parseInt(srcIp.getDestIpAddress().split("/")[1]);
|
||
for (IpCfg _cfg : tempList) {
|
||
IpCfg tempIp = new IpCfg();
|
||
BeanUtils.copyProperties(_cfg, tempIp);
|
||
if (dstMaskNum == 0) {
|
||
tempIp.setDstIpMask("0.0.0.0");
|
||
} else {
|
||
tempIp.setDstIpMask(IpUtil.convertMask(dstMaskNum));
|
||
}
|
||
tempIp.setDstIp(srcIp.getDestIpAddress().split("/")[0]);
|
||
if (!tempIp.getSrcIp().equals(tempIp.getDstIp())) {
|
||
// 处理
|
||
convertPortValues(tempIp, srcIp);
|
||
tempList1.add(tempIp);
|
||
}
|
||
}
|
||
tempList.clear();
|
||
}else {
|
||
for (IpCfg _cfg : tempList) {
|
||
IpCfg tempIp = new IpCfg();
|
||
BeanUtils.copyProperties(_cfg, tempIp);
|
||
tempIp.setDstIp(srcIp.getDestIpAddress());
|
||
if (!tempIp.getSrcIp().equals(tempIp.getDstIp())) {
|
||
tempIp.setDstIpMask("255.255.255.255");
|
||
// 处理
|
||
convertPortValues(tempIp, srcIp);
|
||
tempList1.add(tempIp);
|
||
}
|
||
}
|
||
tempList.clear();
|
||
}
|
||
}else {
|
||
for (IpCfg _cfg : tempList) {
|
||
_cfg.setDstIp("0.0.0.0");
|
||
_cfg.setSrcIpMask("255.255.255.255");
|
||
convertPortValues(_cfg, srcIp);
|
||
}
|
||
}
|
||
if (tempList1.size() > 0) {
|
||
ipConvertList.addAll(tempList1);
|
||
} else {
|
||
ipConvertList.addAll(tempList);
|
||
}
|
||
}else if(srcIp.getIpType().equals(6)){// IP V6
|
||
if (srcIp.getSrcIpAddress() != null) {
|
||
if(srcIp.getSrcIpPattern().equals(2)) {
|
||
IPv6Address address1 = IPv6Address.fromString(srcIp.getSrcIpAddress().split("-")[0]);
|
||
IPv6Address address2 = IPv6Address.fromString(srcIp.getSrcIpAddress().split("-")[1]);
|
||
IPv6Network network = IPv6Network.fromTwoAddresses(address1, address2);
|
||
dstIp.setSrcIp(address1.toString());
|
||
dstIp.setSrcIpMask(network.getNetmask().asAddress().toString());
|
||
}else if(srcIp.getSrcIpPattern().equals(1)){// IP/掩码
|
||
IPv6Network strangeNetwork = IPv6Network.fromString(srcIp.getSrcIpAddress());
|
||
dstIp.setSrcIp(srcIp.getSrcIpAddress().split("/")[0]);
|
||
dstIp.setSrcIpMask(strangeNetwork.getNetmask().asAddress().toString());
|
||
}else {// IP
|
||
dstIp.setSrcIp(srcIp.getSrcIpAddress());
|
||
dstIp.setSrcIpMask("FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF");
|
||
}
|
||
} else {
|
||
dstIp.setSrcIp("::");
|
||
dstIp.setSrcIpMask("FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF");
|
||
}
|
||
if (srcIp.getDestIpAddress() != null) {
|
||
if(srcIp.getDestIpPattern().equals(2)) {
|
||
IPv6Address address1 = IPv6Address.fromString(srcIp.getDestIpAddress().split("-")[0]);
|
||
IPv6Address address2 = IPv6Address.fromString(srcIp.getDestIpAddress().split("-")[1]);
|
||
IPv6Network network = IPv6Network.fromTwoAddresses(address1, address2);
|
||
dstIp.setDstIp(address1.toString());
|
||
dstIp.setDstIpMask(network.getNetmask().asAddress().toString());
|
||
}else if(srcIp.getDestIpPattern().equals(1)) {// IP/掩码
|
||
IPv6Network strangeNetwork = IPv6Network.fromString(srcIp.getDestIpAddress());
|
||
dstIp.setDstIp(srcIp.getDestIpAddress().split("/")[0]);
|
||
dstIp.setDstIpMask(strangeNetwork.getNetmask().asAddress().toString());
|
||
}else {// IP
|
||
dstIp.setDstIp(srcIp.getDestIpAddress());
|
||
dstIp.setDstIpMask("FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF");
|
||
}
|
||
} else {
|
||
dstIp.setDstIp("::");
|
||
dstIp.setDstIpMask("FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF");
|
||
}
|
||
convertPortValues(dstIp, srcIp);
|
||
ipConvertList.add(dstIp);
|
||
}else {
|
||
throw new RuntimeException("Unsupported IP type " + srcIp.getIpType());
|
||
}
|
||
return ipConvertList;
|
||
}
|
||
|
||
/**
|
||
* 设置端口值
|
||
*
|
||
* @param dstIp
|
||
* @param srcIp
|
||
*/
|
||
public static void convertPortValues(IpCfg dstIp, BaseIpCfg srcIp) {
|
||
if (srcIp.getSrcPort() != null) {
|
||
if (srcIp.getSrcPort().indexOf("/") != -1) {
|
||
String srcMaskNum = srcIp.getSrcPort().split("/")[1];
|
||
dstIp.setSrcPortMask(srcMaskNum);
|
||
dstIp.setSrcPort(srcIp.getSrcPort().split("/")[0]);
|
||
} else {
|
||
dstIp.setSrcPort(srcIp.getSrcPort());
|
||
dstIp.setSrcPortMask("65535");
|
||
}
|
||
} else {
|
||
dstIp.setSrcPort("0");
|
||
dstIp.setSrcPortMask("65535");
|
||
}
|
||
if (srcIp.getDestPort() != null) {
|
||
if (srcIp.getDestPort().indexOf("/") != -1) {
|
||
String dstMaskNum = srcIp.getDestPort().split("/")[1];
|
||
dstIp.setDstPortMask(dstMaskNum);
|
||
dstIp.setDstPort(srcIp.getDestPort().split("/")[0]);
|
||
} else {
|
||
dstIp.setDstPort(srcIp.getDestPort());
|
||
dstIp.setDstPortMask("65535");
|
||
}
|
||
} else {
|
||
dstIp.setDstPort("0");
|
||
dstIp.setDstPortMask("65535");
|
||
}
|
||
}
|
||
|
||
// 拦截策略
|
||
public static ProxyObjKeyring convertCallBackProxyObjKeyring(PxyObjKeyring cfg) {
|
||
ProxyObjKeyring proxyObjKeyring = new ProxyObjKeyring();
|
||
proxyObjKeyring.setId(Long.valueOf(cfg.getCompileId()));
|
||
proxyObjKeyring.setCfgId(cfg.getCompileId());
|
||
proxyObjKeyring.setCrl(cfg.getCrl());
|
||
proxyObjKeyring.setExpireAfter(cfg.getExpireAfter());
|
||
proxyObjKeyring.setKeyringId(cfg.getCompileId());
|
||
proxyObjKeyring.setKeyringName(keywordsEscape(cfg.getCfgDesc()));
|
||
proxyObjKeyring.setKeyringType(cfg.getKeyringType());
|
||
proxyObjKeyring.setPrivateKeyFile(cfg.getPrivateKeyFile());
|
||
proxyObjKeyring.setPublicKeyAlgo(cfg.getPublicKeyAlgo());
|
||
proxyObjKeyring.setPublicKeyFile(cfg.getPublicKeyFile());
|
||
proxyObjKeyring.setService(cfg.getServiceId());
|
||
proxyObjKeyring.setIsValid(cfg.getIsValid());
|
||
proxyObjKeyring.setOpTime(cfg.getAuditTime());
|
||
return proxyObjKeyring;
|
||
}
|
||
// 拦截策略
|
||
public static IpReusePolicyCfg convertCallBackSnatPolicy(IpReusePolicyCfg cfg) {
|
||
if(cfg != null) {
|
||
String areaEffectiveIds=cfg.getAreaEffectiveIds();
|
||
if(StringUtils.isEmpty(areaEffectiveIds)){
|
||
areaEffectiveIds="0";
|
||
}else {
|
||
// 组织区域、运营商配置下发格式
|
||
SysDictInfoService service = SpringContextHolder.getBean(SysDictInfoService.class);
|
||
areaEffectiveIds = service.setEffectiveRange(areaEffectiveIds);
|
||
}
|
||
cfg.setAreaEffectiveIds(areaEffectiveIds);
|
||
cfg.setUserName(keywordsEscape(cfg.getUserName()));
|
||
}
|
||
return cfg;
|
||
}
|
||
|
||
// 可信证书
|
||
public static List<ProxyObjTrustedCa> convertCallBackProxyObjTrustedCa(PxyObjTrustedCaCert cfgCert,
|
||
PxyObjTrustedCaCrl cfgCrl) {
|
||
List<ProxyObjTrustedCa> proxyObjTrustedCas = new ArrayList<>();
|
||
if (cfgCert != null && !StringUtil.isEmpty(cfgCert.getCompileId())) {
|
||
ProxyObjTrustedCa proxyObjTrustedCaCert = new ProxyObjTrustedCa();
|
||
proxyObjTrustedCaCert.setId(Long.valueOf(cfgCert.getCompileId()));
|
||
proxyObjTrustedCaCert.setCfgId(cfgCert.getCompileId());
|
||
proxyObjTrustedCaCert.setCertId(cfgCert.getCompileId());
|
||
proxyObjTrustedCaCert.setCertName(keywordsEscape(cfgCert.getCfgDesc()));
|
||
proxyObjTrustedCaCert.setCertFile(cfgCert.getCertFile());
|
||
proxyObjTrustedCaCert.setService(cfgCert.getServiceId());
|
||
proxyObjTrustedCaCert.setIsValid(cfgCert.getIsValid());
|
||
proxyObjTrustedCaCert.setOpTime(cfgCert.getAuditTime());
|
||
proxyObjTrustedCas.add(proxyObjTrustedCaCert);
|
||
}
|
||
if (cfgCrl != null && !StringUtil.isEmpty(cfgCrl.getCompileId())) {
|
||
ProxyObjTrustedCa proxyObjTrustedCaCert = new ProxyObjTrustedCa();
|
||
proxyObjTrustedCaCert.setId(Long.valueOf(cfgCrl.getCompileId()));
|
||
proxyObjTrustedCaCert.setCfgId(cfgCrl.getCompileId());
|
||
proxyObjTrustedCaCert.setCertId(cfgCrl.getCertId());
|
||
proxyObjTrustedCaCert.setService(cfgCrl.getServiceId());
|
||
proxyObjTrustedCaCert.setIsValid(cfgCrl.getIsValid());
|
||
proxyObjTrustedCaCert.setOpTime(cfgCrl.getAuditTime());
|
||
proxyObjTrustedCaCert.setCrlId(cfgCrl.getCompileId());
|
||
proxyObjTrustedCaCert.setCrlFile(cfgCrl.getCrlFile());
|
||
proxyObjTrustedCas.add(proxyObjTrustedCaCert);
|
||
}
|
||
|
||
return proxyObjTrustedCas;
|
||
}
|
||
|
||
// ip转换为callback用ip
|
||
public static NtcDnsResStrategy convertCallBackDnsResStrategy(DnsResStrategy cfg) {
|
||
NtcDnsResStrategy resStrategy = new NtcDnsResStrategy();
|
||
resStrategy.init();
|
||
resStrategy.setId(Long.valueOf(cfg.getCompileId()));
|
||
resStrategy.setCfgId(cfg.getCompileId());
|
||
resStrategy.setReqStrateId(cfg.getCfgId());
|
||
resStrategy.setStrateName(keywordsEscape(cfg.getCfgDesc()));
|
||
resStrategy.setAction(cfg.getAction());
|
||
resStrategy.setService(cfg.getServiceId());
|
||
resStrategy.setResGroup1Id(cfg.getResGroup1Id());
|
||
resStrategy.setResGroup1Num(cfg.getResGroup1Num());
|
||
resStrategy.setMinTtl(cfg.getMinTtl());
|
||
resStrategy.setMaxTtl(cfg.getMaxTtl());
|
||
resStrategy.setIsValid(cfg.getIsValid());
|
||
resStrategy.setOpTime(cfg.getAuditTime());
|
||
return resStrategy;
|
||
}
|
||
|
||
// ip转换为callback用ip
|
||
public static InlineIp convertCallBackIp(BaseIpCfg cfg, Integer policyGroup) {
|
||
List<IpCfg> cfgs = ipConvert(new IpCfg(), cfg);
|
||
if (cfgs.size() > 1) {
|
||
throw new RuntimeException("CallBack IP did not support IP range!");
|
||
}
|
||
IpCfg c = cfgs.get(0);
|
||
InlineIp ip = new InlineIp();
|
||
ip.setId(cfg.getCompileId());
|
||
ip.setCfgId(cfg.getCompileId());
|
||
ip.setAction(cfg.getAction());
|
||
ip.setService(cfg.getServiceId());
|
||
ip.setAddrType(cfg.getIpType());
|
||
ip.setSrcIp(c.getSrcIp());
|
||
ip.setMaskSrcIp(c.getSrcIpMask());
|
||
ip.setDstIp(c.getDstIp());
|
||
ip.setMaskDstIp(c.getDstIpMask());
|
||
ip.setSrcPort(c.getSrcPort());
|
||
ip.setMaskSrcPort(c.getSrcPortMask());
|
||
ip.setDstPort(c.getDstPort());
|
||
ip.setMaskDstPort(c.getDstPortMask());
|
||
ip.setProtocol(cfg.getProtocol());
|
||
ip.setDirection(cfg.getDirection());
|
||
ip.setIsValid(cfg.getIsValid());
|
||
ip.setOpTime(cfg.getAuditTime());
|
||
ip.setPolicyGroup(policyGroup);
|
||
ip.setAreaEffectiveIds(cfg.getAreaEffectiveIds());//添加区域管控
|
||
return ip;
|
||
}
|
||
|
||
// 区域IPsetAreaEffectiveIds设置
|
||
public void setAreaEffectiveIds(BaseCfg<?> entity) {
|
||
List<AreaIpCfg> areaCfg = entity.getAreaCfg();
|
||
List<AreaBean> areaIsps = entity.getAreaIsp();
|
||
if (Constants.IS_AREA_EFFECTIVE_NO == entity.getIsAreaEffective()) {
|
||
entity.setAreaEffectiveIds("");
|
||
entity.setAreaType(null);
|
||
} else if (Constants.IS_AREA_EFFECTIVE_YES == entity.getIsAreaEffective()) {
|
||
if (Constants.AREA_EFFECTIVE_TYPE_AREA_ISP == entity.getAreaType() && areaIsps != null
|
||
&& areaIsps.size() > 0) {
|
||
StringBuffer areaEffectiveIds = new StringBuffer();
|
||
for (int i = 0; i < areaIsps.size(); i++) {
|
||
if (StringUtils.isBlank(areaIsps.get(i).getArea())) {
|
||
areaEffectiveIds.append(areaIsps.get(i).getIsp());
|
||
} else if (StringUtils.isBlank(areaIsps.get(i).getIsp())) {
|
||
areaEffectiveIds.append(areaIsps.get(i).getArea());
|
||
} else {
|
||
areaEffectiveIds.append(areaIsps.get(i).getArea() + ":" + areaIsps.get(i).getIsp());
|
||
}
|
||
if (i != areaIsps.size() - 1) {
|
||
areaEffectiveIds.append(",");
|
||
}
|
||
}
|
||
entity.setAreaEffectiveIds(areaEffectiveIds.toString());
|
||
} else if (Constants.AREA_EFFECTIVE_TYPE_AREA_IP == entity.getAreaType() && areaCfg != null
|
||
&& areaCfg.size() > 0) {
|
||
entity.setAreaEffectiveIds("");
|
||
}
|
||
}
|
||
}
|
||
|
||
public static String keywordsEscape(String cfgKeywords) {
|
||
if (StringUtils.isNotEmpty(cfgKeywords)) {
|
||
// 不转译特殊字符
|
||
cfgKeywords = cfgKeywords.trim();// 首先去掉首尾空格
|
||
cfgKeywords = StringEscapeUtils.unescapeHtml4(cfgKeywords);
|
||
cfgKeywords = cfgKeywords.replace("\\", "\\\\");
|
||
cfgKeywords = cfgKeywords.replace("&", "\\&");
|
||
cfgKeywords = cfgKeywords.replace(" ", "\\b");
|
||
// ***and***在界面表示多个关键字的与表达式,此特殊字符串在common.js中使用定义,maat端以&表示
|
||
cfgKeywords = cfgKeywords.replace(Constants.KEYWORD_EXPR, "&");
|
||
|
||
}
|
||
return cfgKeywords;
|
||
}
|
||
|
||
public static String replaceContentEscape(String replaceContent) {
|
||
if (StringUtils.isNotEmpty(replaceContent)) {
|
||
// 不转译特殊字符
|
||
replaceContent = replaceContent.trim();// 首先去掉首尾空格
|
||
replaceContent = replaceContent.replace("/", "\\/");// 首先转意斜杠“/”
|
||
}
|
||
return replaceContent;
|
||
}
|
||
|
||
// asn IP 复用转换
|
||
public List<IpCfg> groupReuseCfgAddRemoveConvert(List<? extends BaseCfg<?>> ipCfgList, Integer isValid,
|
||
Integer groupId) {
|
||
logger.warn("convert data start");
|
||
long start = System.currentTimeMillis();
|
||
Date opTime = new Date();
|
||
List<IpCfg> maatIpList = new ArrayList<>();
|
||
if (ipCfgList.size() > 0) {
|
||
// 只用一次instanceof,取代循环中每次都用一次instanceof
|
||
if (ipCfgList.get(0) instanceof AsnIpCfg) {
|
||
for (BaseCfg<?> _cfg : ipCfgList) {
|
||
IpCfg cfg = new IpCfg();
|
||
BaseIpCfg baseIpCfg = new BaseIpCfg();
|
||
AsnIpCfg asnIpCfg = (AsnIpCfg) _cfg;
|
||
BeanUtils.copyProperties(asnIpCfg, baseIpCfg);
|
||
BeanUtils.copyProperties(baseIpCfg, cfg);
|
||
cfg.setGroupId(asnIpCfg.getAsnIpGroup());
|
||
cfg.setRegionId(asnIpCfg.getRegionId());
|
||
String userRegion = "ASN_ID=AS" + asnIpCfg.getUserRegion1();
|
||
cfg.setUserRegion(userRegion);
|
||
cfg.setIsValid(isValid);
|
||
cfg.setAuditTime(opTime);
|
||
List<IpCfg> cfgs = ipConvert(cfg, baseIpCfg);
|
||
maatIpList.addAll(cfgs);
|
||
}
|
||
} else if (ipCfgList.get(0) instanceof AppIpCfg) {
|
||
for (BaseCfg<?> _cfg : ipCfgList) {
|
||
IpCfg cfg = new IpCfg();
|
||
BaseIpCfg baseIpCfg = new BaseIpCfg();
|
||
AppIpCfg appIpCfg = (AppIpCfg) _cfg;
|
||
BeanUtils.copyProperties(appIpCfg, baseIpCfg);
|
||
BeanUtils.copyProperties(baseIpCfg, cfg);
|
||
cfg.setGroupId(groupId);
|
||
cfg.setRegionId(Integer.parseInt(appIpCfg.getUserRegion1()));
|
||
String userRegion = "APP_ID=" + appIpCfg.getAppCode();
|
||
cfg.setUserRegion(userRegion);
|
||
cfg.setIsValid(isValid);
|
||
cfg.setAuditTime(opTime);
|
||
List<IpCfg> cfgs = ipConvert(cfg, baseIpCfg);
|
||
maatIpList.addAll(cfgs);
|
||
}
|
||
}
|
||
}
|
||
long end = System.currentTimeMillis();
|
||
logger.warn("convert data finish,cost:" + (end - start));
|
||
return maatIpList;
|
||
}
|
||
public MaatCfg convertMaatCfg(BaseCfg _cfg,Integer cfgType) {
|
||
MaatCfg maatCfg = new MaatCfg();
|
||
maatCfg.initDefaultValue();
|
||
BeanUtils.copyProperties(_cfg, maatCfg);
|
||
maatCfg.setAction(_cfg.getAction());
|
||
maatCfg.setAuditTime(_cfg.getAuditTime());
|
||
Map<String,List> regions=cfgConvert(_cfg, cfgType);
|
||
if(regions.get("ipRegionList")!=null) {
|
||
maatCfg.setIpRegionList(regions.get("ipRegionList"));
|
||
}else {
|
||
maatCfg.setIpRegionList(new ArrayList<IpCfg>());
|
||
}
|
||
if(regions.get("strRegionList")!=null) {
|
||
maatCfg.setStrRegionList(regions.get("strRegionList"));
|
||
}else {
|
||
maatCfg.setStrRegionList(new ArrayList<StringCfg>());
|
||
}
|
||
if(regions.get("numRegionList")!=null) {
|
||
maatCfg.setNumRegionList(regions.get("numRegionList"));
|
||
}else {
|
||
maatCfg.setNumRegionList(new ArrayList<NumBoundaryCfg>());
|
||
}
|
||
if(regions.get("digestRegionList")!=null) {
|
||
maatCfg.setDigestRegionList(regions.get("digestRegionList"));
|
||
}else {
|
||
maatCfg.setDigestRegionList(new ArrayList<DigestCfg>());
|
||
}
|
||
if(regions.get("groupRelationList")!=null) {
|
||
maatCfg.setGroupRelationList(regions.get("groupRelationList"));
|
||
maatCfg.setGroupNum(regions.get("groupRelationList").size());
|
||
}else {
|
||
maatCfg.setGroupRelationList(new ArrayList<GroupCfg>());
|
||
maatCfg.setGroupNum(0);
|
||
}
|
||
|
||
maatCfg.setAreaIpRegionList(new ArrayList<IpCfg>());
|
||
maatCfg.setIsValid(_cfg.getIsValid());
|
||
return maatCfg;
|
||
}
|
||
/**
|
||
* MaatCfg 追加region
|
||
*/
|
||
public MaatCfg maatCfgAppendRegion(MaatCfg maatCfg,BaseCfg _cfg,Integer cfgType) {
|
||
if(maatCfg==null) return maatCfg;
|
||
Map<String,List> regions=cfgConvert(_cfg, cfgType);
|
||
if(regions.get("ipRegionList")!=null) {
|
||
maatCfg.getIpRegionList().addAll(regions.get("ipRegionList"));
|
||
}
|
||
if(regions.get("strRegionList")!=null) {
|
||
maatCfg.getStrRegionList().addAll(regions.get("strRegionList"));
|
||
}
|
||
if(regions.get("numRegionList")!=null) {
|
||
maatCfg.getNumRegionList().addAll(regions.get("numRegionList"));
|
||
}
|
||
if(regions.get("digestRegionList")!=null) {
|
||
maatCfg.getDigestRegionList().addAll(regions.get("digestRegionList"));
|
||
}
|
||
if(regions.get("groupRelationList")!=null) {
|
||
maatCfg.getGroupRelationList().addAll(regions.get("groupRelationList"));
|
||
maatCfg.setGroupNum(maatCfg.getGroupNum()+regions.get("groupRelationList").size());
|
||
}
|
||
return maatCfg;
|
||
}
|
||
/**
|
||
* 分割并保存
|
||
* @param regionDict
|
||
* @param serviceDict
|
||
* @param specificServiceCfg
|
||
* @param asnNoMaps
|
||
* @param list
|
||
* @param cfgIndexInfos
|
||
* @param appPolicyCfgs
|
||
*/
|
||
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)
|
||
public void saveAndSend(FunctionRegionDict regionDict,FunctionServiceDict serviceDict,
|
||
SpecificServiceCfg specificServiceCfg,
|
||
List<? extends BaseCfg> list,List<CfgIndexInfo> cfgIndexInfos,
|
||
List<AppPolicyCfg> appPolicyCfgs,
|
||
List<AppFeatureIndex> appFeatureCfgs,
|
||
List<Map<Long,AsnGroupInfo>> asnNoMaps,
|
||
boolean send){
|
||
if(list!=null&&list.size()>0) {
|
||
String type=null;
|
||
if (list.get(0) instanceof BaseIpCfg) {
|
||
type="BaseIpCfg";
|
||
}else if(list.get(0) instanceof BaseStringCfg) {
|
||
type="BaseStringCfg";
|
||
}else if(list.get(0) instanceof ComplexkeywordCfg) {
|
||
type="ComplexkeywordCfg";
|
||
}else if(list.get(0) instanceof DnsResStrategy) {
|
||
type="DnsResStrategy";
|
||
}else if(list.get(0) instanceof AsnIpCfg) {
|
||
type="AsnIpCfg";
|
||
}else if(list.get(0) instanceof AppComplexFeatureCfg) {
|
||
type="AppComplexFeature";
|
||
}else if(list.get(0) instanceof AppTopicDomainCfg) {
|
||
type="AppTopicDomain";
|
||
}
|
||
|
||
if(regionDict.getFunctionId().equals(214)) { // 处理IpSpoofing配置导入
|
||
this.saveAndSendSpoofingIpPool(list,cfgIndexInfos,send);
|
||
}
|
||
if (cfgIndexInfos != null && cfgIndexInfos.size() > 0) {
|
||
this.saveCfgIndexOf(cfgIndexInfos);
|
||
}
|
||
if (appPolicyCfgs != null && appPolicyCfgs.size() > 0) {
|
||
this.savePolicyList(regionDict,serviceDict,appPolicyCfgs,list,send);
|
||
}
|
||
if (appFeatureCfgs != null && appFeatureCfgs.size() > 0) {
|
||
this.saveAppFeatureList(appFeatureCfgs);
|
||
}
|
||
|
||
if("BaseIpCfg".equals(type)) {
|
||
List<BaseIpCfg> listPage = (List<BaseIpCfg>) list;
|
||
if (specificServiceCfg!=null&®ionDict.getFunctionId().equals(405)) {
|
||
this.saveAppIpCfg((List<BaseIpCfg>)listPage,specificServiceCfg,send);
|
||
}else if(appPolicyCfgs==null||appPolicyCfgs.isEmpty()){
|
||
this.saveIpBatch(regionDict,serviceDict,(List<BaseIpCfg>)listPage,send);
|
||
}
|
||
}else if("AsnIpCfg".equals(type)) {
|
||
List<AsnIpCfg> listPage = (List<AsnIpCfg>) list;
|
||
this.saveAsnIpBatch(listPage,asnNoMaps,send);
|
||
}else if("AppComplexFeature".equals(type)) {// APP Payload
|
||
List<AppComplexFeatureCfg> listPage = (List<AppComplexFeatureCfg>) list;
|
||
this.saveAppComplexFeatureBatch(regionDict,serviceDict,listPage,send);
|
||
}else if("AppTopicDomain".equals(type)) {// 主题网站
|
||
List<AppTopicDomainCfg> listPage = (List<AppTopicDomainCfg>) list;
|
||
this.saveTopicDomainCfgBatch(regionDict,serviceDict,listPage,send);
|
||
}else if("BaseStringCfg".equals(type)) {
|
||
List<BaseStringCfg<?>> listPage = (List<BaseStringCfg<?>>) list;
|
||
// 调用对应配置的service
|
||
// ip_payload
|
||
if (regionDict.getDictId().intValue() == 167) {
|
||
// interceptCfgService.saveInterceptCfg(listPage);
|
||
this.saveStringCfgBatch(regionDict,serviceDict,listPage, "intercept_pkt_bin",send);
|
||
}else
|
||
// http url
|
||
if (regionDict.getDictId().intValue() == 9||regionDict.getDictId().intValue() == 15 || regionDict.getDictId().intValue() == 596) {
|
||
// websiteCfgService.saveHttpUrlCfg(listPage);
|
||
this.saveStringCfgBatch(regionDict,serviceDict,listPage, "http_url_cfg",send);
|
||
}else
|
||
// FTP url/content
|
||
if (regionDict.getDictId().intValue() == 36||regionDict.getDictId().intValue() == 37) {
|
||
// fileTransferCfgService.saveFtpCfg(listPage);
|
||
this.saveStringCfgBatch(regionDict,serviceDict,listPage, "ftp_keyword_cfg",send);
|
||
}else
|
||
// P2P eMule Keyword
|
||
if(regionDict.getDictId().intValue() == 158){
|
||
this.saveStringCfgBatch(regionDict,serviceDict,listPage, "p2p_keyword_cfg",send);
|
||
}else
|
||
// P2P File Marking
|
||
if(regionDict.getDictId().intValue() == 159){
|
||
// fileTransferCfgService.saveP2pCfg(listPage);
|
||
this.saveStringCfgBatch(regionDict,serviceDict,listPage, "p2p_hash_cfg",send);
|
||
}else
|
||
// BGP AS
|
||
if (regionDict.getFunctionId().equals(61)) {
|
||
// bgpCfgService.saveBgpAsCfg(listPage);
|
||
this.saveStringCfgBatch(regionDict,serviceDict,listPage, "ntc_bgp_as_cfg",send);
|
||
}else
|
||
// SSL SNI/SAN/CN
|
||
if (regionDict.getFunctionId().intValue() == 34) {
|
||
// websiteCfgService.saveSslCfg(listPage);
|
||
this.saveStringCfgBatch(regionDict,serviceDict,listPage, "ssl_keyword_cfg",send);
|
||
}else
|
||
// HTTP 请求/应答内容
|
||
if(regionDict.getDictId().intValue()==12||regionDict.getDictId().intValue()==13||regionDict.getDictId().intValue()==601||regionDict.getDictId().intValue()==602) {
|
||
// websiteCfgService.saveHttpBodyCfg(listPage);
|
||
this.saveStringCfgBatch(regionDict,serviceDict,listPage, "http_body_cfg",send);
|
||
}else
|
||
// 流媒体协议
|
||
if(regionDict.getDictId().intValue()==25){
|
||
// avContentCfgService.saveContUrlCfg(listPage);
|
||
this.saveStringCfgBatch(regionDict,serviceDict,listPage, "av_cont_url_cfg",send);
|
||
}else
|
||
// Voip Account
|
||
if(regionDict.getDictId().intValue()==16){
|
||
// avContentCfgService.saveVoIpAccountCfg(listPage);
|
||
this.saveStringCfgBatch(regionDict,serviceDict,listPage, "av_voip_account_cfg",send);
|
||
}else
|
||
// APP域名特征
|
||
if(regionDict.getDictId().intValue()==64){
|
||
// appCfgService.saveAppDomainCfg(listPage);
|
||
this.saveStringCfgBatch(regionDict,serviceDict,listPage, AppDomainCfg.getTablename(),send);
|
||
}else
|
||
// 域名拦截
|
||
if(regionDict.getDictId().intValue()==56){
|
||
this.saveStringCfgBatch(regionDict,serviceDict,listPage, "http_url_cfg",send);
|
||
}
|
||
//账号
|
||
else if("subscribe_id".equals(regionDict.getConfigServiceType())&&(appPolicyCfgs==null||appPolicyCfgs.isEmpty())){
|
||
this.saveStringCfgBatch(regionDict,serviceDict,listPage, "ntc_subscribe_id_cfg",send);
|
||
}
|
||
// HTTP(s) URL
|
||
else if(regionDict.getDictId().intValue()==97 || regionDict.getDictId().intValue()==79 ||
|
||
regionDict.getDictId().intValue()==85 || regionDict.getDictId().intValue()==91 ||
|
||
regionDict.getDictId().intValue()==99 || regionDict.getDictId().intValue()==700){
|
||
this.saveStringCfgBatch(regionDict,serviceDict,listPage, "http_url_cfg",send);
|
||
}
|
||
// HTTP(s) 请求/应答内容
|
||
else if(regionDict.getDictId().intValue()==94 || regionDict.getDictId().intValue()==95 ||
|
||
regionDict.getDictId().intValue()==88 || regionDict.getDictId().intValue()==89 ||
|
||
regionDict.getDictId().intValue()==82 || regionDict.getDictId().intValue()==83 ||
|
||
regionDict.getDictId().intValue()==103 || regionDict.getDictId().intValue()==104 ||
|
||
regionDict.getDictId().intValue()==703 || regionDict.getDictId().intValue()==704){
|
||
this.saveStringCfgBatch(regionDict,serviceDict,listPage, "http_body_cfg",send);
|
||
}
|
||
}else if("ComplexkeywordCfg".equals(type)) {
|
||
List<ComplexkeywordCfg> listPage = (List<ComplexkeywordCfg>) list;
|
||
// DNS
|
||
if (regionDict.getDictId().intValue() == 28) {
|
||
// websiteCfgService.saveDnsCfg(listPage);
|
||
this.saveComplexkeywordCfgBatch(regionDict,serviceDict,listPage, "dns_domain_cfg",send);
|
||
}else
|
||
// Mail
|
||
if (regionDict.getDictId().intValue() == 30 || regionDict.getDictId().intValue() == 31||regionDict.getDictId().intValue() == 599) {
|
||
// mailCfgService.saveMailCfg(listPage);
|
||
this.saveComplexkeywordCfgBatch(regionDict,serviceDict,listPage, "mail_keyword_cfg",send);
|
||
}else
|
||
// HTTP请求头域
|
||
if(regionDict.getDictId().intValue()==10) {
|
||
// websiteCfgService.saveHttpReqHeadCfg(listPage);
|
||
this.saveComplexkeywordCfgBatch(regionDict,serviceDict,listPage, "http_req_head_cfg",send);
|
||
}else
|
||
// HTTP响应头域
|
||
if(regionDict.getDictId().intValue()==11) {
|
||
// websiteCfgService.saveHttpResHeadCfg(listPage);
|
||
this.saveComplexkeywordCfgBatch(regionDict,serviceDict,listPage, "http_res_head_cfg",send);
|
||
}else
|
||
// APP http特征
|
||
if(regionDict.getDictId().intValue()==63) {
|
||
// appCfgService.saveAppHttpCfg(listPage);
|
||
this.saveComplexkeywordCfgBatch(regionDict,serviceDict,listPage, AppHttpCfg.getTablename(),send);
|
||
}else
|
||
//app Http特征
|
||
if(regionDict.getDictId().intValue()==220 || regionDict.getDictId().intValue()==216 || regionDict.getDictId().intValue()==224){
|
||
this.saveComplexkeywordCfgBatch(regionDict,serviceDict,listPage,"app_complex_feature_cfg",send);
|
||
}
|
||
// HTTP(s)请求头域
|
||
if(regionDict.getDictId().intValue()==98 || regionDict.getDictId().intValue()==80 ||
|
||
regionDict.getDictId().intValue()==86 || regionDict.getDictId().intValue()==92 ||
|
||
regionDict.getDictId().intValue()==100 || regionDict.getDictId().intValue()==701) {
|
||
this.saveComplexkeywordCfgBatch(regionDict,serviceDict,listPage, "http_req_head_cfg",send);
|
||
}else
|
||
// HTTP(s)响应头域
|
||
if(regionDict.getConfigRegionValue().equals(Constants.HTTP_REDIRECT_RES_HEAD_REGION)) {
|
||
this.saveComplexkeywordCfgBatch(regionDict,serviceDict,listPage, "http_res_head_cfg",send);
|
||
}
|
||
}else if("DnsResStrategy".equals(type)) {
|
||
List<DnsResStrategy> listPage = (List<DnsResStrategy>) list;
|
||
// dnsResStrategyService.saveDnsResStrategies(listPage);
|
||
this.saveDnsResStrategyCfgBatch(listPage);
|
||
}
|
||
}
|
||
}
|
||
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)
|
||
public void saveAsnIpBatch(List<AsnIpCfg> cfgs,List<Map<Long,AsnGroupInfo>> asnNoMaps,boolean send){
|
||
logger.warn("Start to save IP,size:"+cfgs.size());
|
||
long start=System.currentTimeMillis();
|
||
SqlSessionFactory sqlSessionFactory=SpringContextHolder.getBean(SqlSessionFactory.class);
|
||
SqlSession batchSqlSession = null;
|
||
//需要通过新增域接口新增的ip集合
|
||
List<AsnIpCfg> toAddRegionAsnIpCfgs=Lists.newArrayList();
|
||
Map<Long,List<AsnIpCfg>> toSendFirstAsnIpCfgs=Maps.newHashMap();
|
||
Map<Long,Integer> asnGroupAddRegions=Maps.newHashMap();
|
||
// AsnCacheUtils.init(true);
|
||
try{
|
||
batchSqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH, false);
|
||
for(AsnIpCfg cfg:cfgs) {
|
||
((AsnIpCfgDao) batchSqlSession.getMapper(AsnIpCfgDao.class)).insert(cfg);
|
||
if(send) {
|
||
AsnGroupInfo group=asnNoMaps.get(0).get(Long.parseLong(cfg.getUserRegion1()));
|
||
if(group==null) {
|
||
group=asnNoMaps.get(1).get(Long.parseLong(cfg.getUserRegion1()));
|
||
}
|
||
//AsnGroupInfo group=AsnCacheUtils.get(Long.parseLong(cfg.getUserRegion1()));
|
||
if(group!=null&&group.getIsValid().intValue()==1) {
|
||
if(asnGroupAddRegions.containsKey(group.getAsnId())) {
|
||
int count=asnGroupAddRegions.get(group.getAsnId());
|
||
asnGroupAddRegions.put(group.getAsnId(), count+1);
|
||
}else {
|
||
asnGroupAddRegions.put(group.getAsnId(), 1);
|
||
}
|
||
toAddRegionAsnIpCfgs.add(cfg);
|
||
}else if(group!=null) {
|
||
if(toSendFirstAsnIpCfgs.containsKey(group.getAsnId())) {
|
||
toSendFirstAsnIpCfgs.get(group.getAsnId()).add(cfg);
|
||
}else {
|
||
toSendFirstAsnIpCfgs.put(group.getAsnId(), new ArrayList());
|
||
toSendFirstAsnIpCfgs.get(group.getAsnId()).add(cfg);
|
||
}
|
||
|
||
|
||
}
|
||
}
|
||
|
||
}
|
||
if(send) {
|
||
if(toAddRegionAsnIpCfgs.size()>0) {
|
||
for(Entry<Long,Integer> asnGroupAddRegion:asnGroupAddRegions.entrySet()) {
|
||
AsnGroupInfo group=new AsnGroupInfo();
|
||
group.setAsnId(asnGroupAddRegion.getKey());
|
||
group.setIssuedIPs(asnGroupAddRegion.getValue()+0l);
|
||
((AsnGroupInfoDao) batchSqlSession.getMapper(AsnGroupInfoDao.class)).modifyIssuedIp(group);;
|
||
}
|
||
asnIPRegionSendToMaat(toAddRegionAsnIpCfgs,Constants.VALID_YES);
|
||
}
|
||
if(toSendFirstAsnIpCfgs.size()>0) {
|
||
List<MaatCfg> configCompileList = new ArrayList();
|
||
ToMaatBean maatBean = new ToMaatBean();
|
||
for(Entry<Long, List<AsnIpCfg>> info:toSendFirstAsnIpCfgs.entrySet()) {
|
||
AsnGroupInfo group=asnNoMaps.get(0).get(info.getKey());
|
||
if(group==null) {
|
||
group=asnNoMaps.get(1).get(info.getKey());
|
||
}
|
||
//AsnGroupInfo group=AsnCacheUtils.get(info.getKey());
|
||
List<GroupCfg> groupRelationList = new ArrayList();
|
||
List<IpCfg> ipRegionList = new ArrayList();
|
||
List<StringCfg> strRegionList = new ArrayList();
|
||
List<NumBoundaryCfg> numRegionList = new ArrayList();
|
||
List<DigestCfg> digestRegionList = new ArrayList();
|
||
List<IpCfg> areaIpRegionList = new ArrayList();
|
||
MaatCfg maatCfg = new MaatCfg();
|
||
maatCfg.initDefaultValue();
|
||
//group
|
||
GroupCfg groupCfg=new GroupCfg();
|
||
groupCfg.setCompileId(group.getCompileId());
|
||
groupCfg.setGroupId(group.getGroupId());
|
||
groupCfg.setIsValid(Constants.VALID_YES);
|
||
groupCfg.setAuditTime(info.getValue().get(0).getAuditTime());
|
||
groupRelationList.add(groupCfg);
|
||
BeanUtils.copyProperties(info.getValue().get(0), maatCfg);
|
||
ipRegionList.addAll(groupReuseCfgAddRemoveConvert(info.getValue(),Constants.VALID_YES,group.getGroupId()));
|
||
maatCfg.setCompileId(group.getCompileId());
|
||
maatCfg.setAction(info.getValue().get(0).getAction());
|
||
maatCfg.setAuditTime(info.getValue().get(0).getAuditTime());
|
||
maatCfg.setIpRegionList(ipRegionList);
|
||
maatCfg.setStrRegionList(strRegionList);
|
||
maatCfg.setNumRegionList(numRegionList);
|
||
maatCfg.setDigestRegionList(digestRegionList);
|
||
maatCfg.setGroupRelationList(groupRelationList);
|
||
maatCfg.setGroupNum(groupRelationList.size());
|
||
maatCfg.setAreaIpRegionList(areaIpRegionList);
|
||
maatCfg.setIsValid(info.getValue().get(0).getIsValid());
|
||
// 设置自定义域
|
||
String userRegion = "ASN_ID=AS" + info.getKey();
|
||
maatCfg.setUserRegion(userRegion);
|
||
configCompileList.add(maatCfg);
|
||
|
||
group.setIsValid(1);
|
||
group.setIssuedIPs(info.getValue().size()+0L);
|
||
((AsnGroupInfoDao) batchSqlSession.getMapper(AsnGroupInfoDao.class)).updateValid(group);
|
||
}
|
||
maatBean.setConfigCompileList(configCompileList);
|
||
maatBean.setAuditTime(cfgs.get(0).getAuditTime());
|
||
maatBean.setCreatorName(cfgs.get(0).getCurrentUser().getName());
|
||
maatBean.setVersion(Constants.MAAT_VERSION);
|
||
maatBean.setOpAction(Constants.INSERT_ACTION);
|
||
// 调用服务接口下发配置数据
|
||
String json = gsonToJson(maatBean);
|
||
if(configCompileList.size()<=100) {
|
||
logger.info("asn IP配置下发配置参数:" + json);
|
||
}else {
|
||
logger.info("asn IP配置下发配置数量:" + configCompileList.size());
|
||
}
|
||
|
||
// 调用服务接口下发配置
|
||
ToMaatResult result = ConfigServiceUtil.postMaatCfg(json);
|
||
logger.info("asn IP配置下发响应信息:" + result.getMsg());
|
||
}
|
||
}
|
||
batchSqlSession.commit();
|
||
}finally {
|
||
if(batchSqlSession != null){
|
||
batchSqlSession.close();
|
||
}
|
||
}
|
||
long end=System.currentTimeMillis();
|
||
logger.warn("Save IP finish,cost:"+(end-start));
|
||
cfgs.clear();
|
||
toAddRegionAsnIpCfgs.clear();
|
||
cfgs=null;
|
||
toAddRegionAsnIpCfgs=null;
|
||
}
|
||
/**
|
||
* 导入配置时数据批量入库
|
||
* @param data
|
||
*/
|
||
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)
|
||
public void saveDnsResStrategyCfgBatch(List<DnsResStrategy> data) {
|
||
SqlSessionFactory sqlSessionFactory=SpringContextHolder.getBean(SqlSessionFactory.class);
|
||
SqlSession batchSqlSession = null;
|
||
try{
|
||
batchSqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH, false);
|
||
for(int index = 0; index < data.size();index++){
|
||
DnsResStrategy cfg = data.get(index);
|
||
((DnsResStrategyDao) batchSqlSession.getMapper(DnsResStrategyDao.class)).insert(cfg);
|
||
}
|
||
batchSqlSession.commit();
|
||
}finally {
|
||
if(batchSqlSession != null){
|
||
batchSqlSession.close();
|
||
}
|
||
}
|
||
|
||
}
|
||
|
||
/**
|
||
* 导入配置时数据批量入库
|
||
* @param serviceDict
|
||
* @param regionDict
|
||
* @param data
|
||
* @param send
|
||
*/
|
||
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)
|
||
public void saveTopicDomainCfgBatch(FunctionRegionDict regionDict, FunctionServiceDict serviceDict, List<AppTopicDomainCfg> data, boolean send) {
|
||
if (regionDict != null) {
|
||
Integer regionType = regionDict.getRegionType();
|
||
if (2 == regionType.intValue()) {
|
||
SqlSessionFactory sqlSessionFactory=SpringContextHolder.getBean(SqlSessionFactory.class);
|
||
AppCfgDao appCfgDao = SpringContextHolder.getBean(AppCfgDao.class);
|
||
List<MaatCfg> configCompileList = new ArrayList();
|
||
SqlSession batchSqlSession = null;
|
||
try{
|
||
batchSqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH, false);
|
||
for(int index = 0; index < data.size();index++){
|
||
AppTopicDomainCfg cfg = data.get(index);
|
||
((AppCfgDao) batchSqlSession.getMapper(AppCfgDao.class)).insertAppTopicDomainCfgBatch(cfg);
|
||
if (send) {
|
||
if(regionDict.getIsMaat().intValue()==1) {
|
||
MaatCfg maatCfg=convertMaatCfg(cfg,2);
|
||
//userRegion处理
|
||
WebsiteDomainTopic websiteDomainTopic = new WebsiteDomainTopic();
|
||
websiteDomainTopic.setDomain(cfg.getCfgKeywords());
|
||
List<WebsiteDomainTopic> domainDict = appCfgDao.getDomainDict(websiteDomainTopic);
|
||
Long domainId = domainDict.get(0).getId();
|
||
maatCfg.setUserRegion("WEB_ID=" + domainId);
|
||
configCompileList.add(maatCfg);
|
||
}
|
||
}
|
||
|
||
}
|
||
if (send && configCompileList.size() > 0) {
|
||
ToMaatBean maatBean = new ToMaatBean();
|
||
maatBean.setConfigCompileList(configCompileList);
|
||
maatBean.setAuditTime(new Date());
|
||
maatBean.setCreatorName(UserUtils.getUser().getName());
|
||
maatBean.setVersion(Constants.MAAT_VERSION);
|
||
maatBean.setOpAction(Constants.INSERT_ACTION);
|
||
// 调用服务接口下发配置数据
|
||
String json = BaseService.gsonToJson(maatBean);
|
||
if(json.length()>Constants.JSON_PRINT_LENTH) {
|
||
logger.info("APP主题网站配置下发配置参数:" + configCompileList.size());
|
||
}else {
|
||
logger.info("APP主题网站配置下发配置参数:" + json);
|
||
}
|
||
// 调用服务接口下发配置
|
||
ToMaatResult result = ConfigServiceUtil.postMaatCfg(json);
|
||
logger.info("APP主题网站配置下发响应信息:" + result.getMsg());
|
||
|
||
}
|
||
batchSqlSession.commit();
|
||
|
||
}finally {
|
||
if(batchSqlSession != null){
|
||
batchSqlSession.close();
|
||
}
|
||
|
||
}
|
||
}
|
||
}
|
||
|
||
}
|
||
|
||
/**
|
||
* APP Payload导入配置时数据批量入库
|
||
* @param serviceDict
|
||
* @param regionDict
|
||
* @param data
|
||
* @param send
|
||
*/
|
||
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)
|
||
public void saveAppComplexFeatureBatch(FunctionRegionDict regionDict, FunctionServiceDict serviceDict, List<AppComplexFeatureCfg> data, boolean send) {
|
||
if (regionDict != null) {
|
||
Integer regionType = regionDict.getRegionType();
|
||
if (3 == regionType.intValue()) {
|
||
SqlSessionFactory sqlSessionFactory=SpringContextHolder.getBean(SqlSessionFactory.class);
|
||
List<MaatCfg> configCompileList = new ArrayList();
|
||
SqlSession batchSqlSession = null;
|
||
try{
|
||
batchSqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH, false);
|
||
for(int index = 0; index < data.size();index++){
|
||
AppComplexFeatureCfg cfg = data.get(index);
|
||
((AppMultiFeatureCfgDao) batchSqlSession.getMapper(AppMultiFeatureCfgDao.class)).insertAppComplexFeatureCfgBatch(cfg);
|
||
if (send) {
|
||
if(regionDict.getIsMaat().intValue()==1) {
|
||
MaatCfg maatCfg=convertMaatCfg(cfg,3);
|
||
//userRegion处理
|
||
if(regionDict.getFunctionId()==563) {
|
||
maatCfg.setUserRegion(Constants.APP_ID_REGION+"="+cfg.getAppCode());
|
||
}
|
||
configCompileList.add(maatCfg);
|
||
}
|
||
}
|
||
|
||
}
|
||
if (send && configCompileList.size() > 0) {
|
||
ToMaatBean maatBean = new ToMaatBean();
|
||
maatBean.setConfigCompileList(configCompileList);
|
||
maatBean.setAuditTime(new Date());
|
||
maatBean.setCreatorName(UserUtils.getUser().getName());
|
||
maatBean.setVersion(Constants.MAAT_VERSION);
|
||
maatBean.setOpAction(Constants.INSERT_ACTION);
|
||
// 调用服务接口下发配置数据
|
||
String json = BaseService.gsonToJson(maatBean);
|
||
if(json.length()>Constants.JSON_PRINT_LENTH) {
|
||
logger.info("APP Feature增强字符串配置下发配置条数:" + configCompileList.size());
|
||
}else {
|
||
logger.info("APP Feature增强字符串配置下发配置参数:" + json);
|
||
}
|
||
// 调用服务接口下发配置
|
||
ToMaatResult result = ConfigServiceUtil.postMaatCfg(json);
|
||
logger.info("APP Feature增强字符串配置下发响应信息:" + result.getMsg());
|
||
|
||
}
|
||
batchSqlSession.commit();
|
||
|
||
}finally {
|
||
if(batchSqlSession != null){
|
||
batchSqlSession.close();
|
||
}
|
||
|
||
}
|
||
}
|
||
}
|
||
|
||
}
|
||
|
||
/**
|
||
* 同一个app下的ip批量保存
|
||
* @param cfgs
|
||
* @param specificServiceCfg
|
||
* @throws Exception
|
||
*/
|
||
@Transactional(readOnly = false, rollbackFor = RuntimeException.class)
|
||
public void saveAppIpCfg(List<BaseIpCfg> cfgs,SpecificServiceCfg specificServiceCfg,boolean send){
|
||
logger.warn("Start to save IP");
|
||
ConfigGroupInfoDao configGroupInfoDao=SpringContextHolder.getBean(ConfigGroupInfoDao.class);
|
||
SpecificServiceCfgDao specificServiceCfgDao=SpringContextHolder.getBean(SpecificServiceCfgDao.class);
|
||
AppCfgDao appCfgDao=SpringContextHolder.getBean(AppCfgDao.class);
|
||
long start=System.currentTimeMillis();
|
||
ConfigGroupInfo configGroupInfo=configGroupInfoDao.getConfigGroupInfoByGroupId(specificServiceCfg.getGroupId());
|
||
if(configGroupInfo==null) {//一般特定服务的组号是新增之后就有的,不会进入这一步。
|
||
Date date = new Date();
|
||
Integer groupId = ConfigServiceUtil.getId(2, 1).get(0);
|
||
Integer compileId=ConfigServiceUtil.getId(1, 1).get(0);
|
||
specificServiceCfg.setGroupId(groupId);
|
||
configGroupInfo = new ConfigGroupInfo();
|
||
configGroupInfo.setGroupId(specificServiceCfg.getGroupId());
|
||
configGroupInfo.setGroupName(specificServiceCfg.getSpecServiceName());
|
||
configGroupInfo.setIsIssued(0);
|
||
configGroupInfo.setGroupType(1);
|
||
configGroupInfo.setCompileId(compileId);
|
||
configGroupInfo.setInsertTime(date);
|
||
configGroupInfoDao.insertConfigGroupInfo(configGroupInfo);
|
||
//更新group_id
|
||
specificServiceCfg.setOpTime(date);
|
||
specificServiceCfgDao.update(specificServiceCfg);
|
||
}
|
||
Integer compileId = configGroupInfo.getCompileId();
|
||
// Varibles maxPacket=asnIpCfgDao.getVaribles("max_allowed_packet");
|
||
List<AppIpCfg> tempList=Lists.newArrayList();
|
||
|
||
int len=0;
|
||
int index=0;
|
||
for(BaseIpCfg cfg:cfgs) {
|
||
AppIpCfg entity=new AppIpCfg();
|
||
BeanUtils.copyProperties(cfg, entity);
|
||
entity.setCompileId(compileId);
|
||
cfg.setCompileId(compileId);
|
||
cfg.setGroupId(specificServiceCfg.getGroupId());
|
||
int tempLen=entity.toString().getBytes(Charset.forName("UTF-8")).length;
|
||
if((len+tempLen)<Constants.MAX_ALLOWED_PACKET) {
|
||
tempList.add(entity);
|
||
len+=tempLen;
|
||
}else {
|
||
appCfgDao.insertAppIpCfgBatch(tempList);
|
||
if(send) {
|
||
List<MaatCfg> configCompileList = new ArrayList();
|
||
List<GroupCfg> groupRelationList = new ArrayList();
|
||
List<IpCfg> ipRegionList = new ArrayList();
|
||
List<StringCfg> strRegionList = new ArrayList();
|
||
List<NumBoundaryCfg> numRegionList = new ArrayList();
|
||
List<DigestCfg> digestRegionList = new ArrayList();
|
||
List<IpCfg> areaIpRegionList = new ArrayList();
|
||
if(configGroupInfo.getIsIssued()==0) {//未下发,下发region compile,group.
|
||
MaatCfg maatCfg = new MaatCfg();
|
||
ToMaatBean maatBean = new ToMaatBean();
|
||
maatCfg.initDefaultValue();
|
||
//group
|
||
GroupCfg groupCfg=new GroupCfg();
|
||
groupCfg.setCompileId(compileId);
|
||
groupCfg.setGroupId(configGroupInfo.getGroupId());
|
||
groupCfg.setIsValid(Constants.VALID_YES);
|
||
groupCfg.setAuditTime(tempList.get(0).getAuditTime());
|
||
groupRelationList.add(groupCfg);
|
||
BeanUtils.copyProperties(cfgs.get(0), maatCfg);
|
||
ipRegionList.addAll(groupReuseCfgAddRemoveConvert(tempList,Constants.VALID_YES,configGroupInfo.getGroupId()));
|
||
maatCfg.setAction(tempList.get(0).getAction());
|
||
maatCfg.setAuditTime(tempList.get(0).getAuditTime());
|
||
maatCfg.setIpRegionList(ipRegionList);
|
||
maatCfg.setStrRegionList(strRegionList);
|
||
maatCfg.setNumRegionList(numRegionList);
|
||
maatCfg.setDigestRegionList(digestRegionList);
|
||
maatCfg.setGroupRelationList(groupRelationList);
|
||
maatCfg.setGroupNum(groupRelationList.size());
|
||
maatCfg.setAreaIpRegionList(areaIpRegionList);
|
||
maatCfg.setIsValid(tempList.get(0).getIsValid());
|
||
// 设置APP自定义域
|
||
String userRegion = "APP_ID=" + tempList.get(0).getAppCode()/*+Constants.USER_REGION_SPLIT+"ASEV_ID="+businessType*/;
|
||
maatCfg.setUserRegion(userRegion);
|
||
configCompileList.add(maatCfg);
|
||
maatBean.setConfigCompileList(configCompileList);
|
||
maatBean.setAuditTime(tempList.get(0).getAuditTime());
|
||
maatBean.setCreatorName(tempList.get(0).getCurrentUser().getName());
|
||
maatBean.setVersion(Constants.MAAT_VERSION);
|
||
maatBean.setOpAction(Constants.INSERT_ACTION);
|
||
// 调用服务接口下发配置数据
|
||
String json = gsonToJson(maatBean);
|
||
logger.info("app协议IP配置下发配置参数:" + json);
|
||
// 调用服务接口下发配置
|
||
ToMaatResult result = ConfigServiceUtil.postMaatCfg(json);
|
||
logger.info("app协议IP配置下发响应信息:" + result.getMsg());
|
||
configGroupInfo.setIsIssued(1);
|
||
configGroupInfo.setUpdateTime(new Date());
|
||
configGroupInfoDao.updateConfigGroupInfobyGroupId(configGroupInfo);
|
||
}else if(configGroupInfo.getIsIssued()==1) {//已经下发,分组复用下发
|
||
GroupReuseAddBean maatBean = new GroupReuseAddBean();
|
||
List<GroupReuseCfg> groupReuseList=new ArrayList<>();
|
||
GroupReuseCfg groupReuseCfg=new GroupReuseCfg();
|
||
/*groupReuseCfg.setUserRegion(userRegion);*/
|
||
groupReuseCfg.setServiceId(tempList.get(0).getServiceId());
|
||
ipRegionList.addAll(groupReuseCfgAddRemoveConvert(tempList,Constants.VALID_YES,configGroupInfo.getGroupId()));
|
||
groupReuseCfg.setIpRegionList(ipRegionList);
|
||
groupReuseCfg.setStrRegionList(strRegionList);
|
||
groupReuseCfg.setNumRegionList(numRegionList);
|
||
groupReuseList.add(groupReuseCfg);
|
||
maatBean.setGroupReuseCfgList(groupReuseList);
|
||
maatBean.setAuditTime(tempList.get(0).getAuditTime());
|
||
maatBean.setCreatorName(tempList.get(0).getCurrentUser().getName());
|
||
maatBean.setVersion(Constants.MAAT_VERSION);
|
||
maatBean.setOpAction(Constants.INSERT_ACTION);
|
||
//调用服务接口下发配置数据
|
||
String json=gsonToJson(maatBean);
|
||
logger.info("app协议IP域新增配置下发配置参数:"+json);
|
||
//调用服务接口下发配置
|
||
ToMaatResult result = ConfigServiceUtil.postGroupReuseSources(json);
|
||
logger.info("app协议IP域新增配置响应信息:"+result.getMsg());
|
||
}else {
|
||
throw new RuntimeException("Unknown configGroupInfo isIssued value");
|
||
}
|
||
}
|
||
tempList.clear();
|
||
tempList.add(entity);
|
||
len=tempLen;
|
||
}
|
||
index ++;
|
||
}
|
||
if(tempList.size()>0) {
|
||
logger.warn("save ip size:"+tempList.size());
|
||
appCfgDao.insertAppIpCfgBatch(tempList);
|
||
if(send) {
|
||
if(send) {
|
||
List<MaatCfg> configCompileList = new ArrayList();
|
||
List<GroupCfg> groupRelationList = new ArrayList();
|
||
List<IpCfg> ipRegionList = new ArrayList();
|
||
List<StringCfg> strRegionList = new ArrayList();
|
||
List<NumBoundaryCfg> numRegionList = new ArrayList();
|
||
List<DigestCfg> digestRegionList = new ArrayList();
|
||
List<IpCfg> areaIpRegionList = new ArrayList();
|
||
if(configGroupInfo.getIsIssued()==0) {//未下发,下发region compile,group.
|
||
MaatCfg maatCfg = new MaatCfg();
|
||
ToMaatBean maatBean = new ToMaatBean();
|
||
maatCfg.initDefaultValue();
|
||
//group
|
||
GroupCfg groupCfg=new GroupCfg();
|
||
groupCfg.setCompileId(compileId);
|
||
groupCfg.setGroupId(configGroupInfo.getGroupId());
|
||
groupCfg.setIsValid(Constants.VALID_YES);
|
||
groupCfg.setAuditTime(tempList.get(0).getAuditTime());
|
||
groupRelationList.add(groupCfg);
|
||
BeanUtils.copyProperties(cfgs.get(0), maatCfg);
|
||
ipRegionList.addAll(groupReuseCfgAddRemoveConvert(tempList,Constants.VALID_YES,configGroupInfo.getGroupId()));
|
||
maatCfg.setAction(tempList.get(0).getAction());
|
||
maatCfg.setAuditTime(tempList.get(0).getAuditTime());
|
||
maatCfg.setIpRegionList(ipRegionList);
|
||
maatCfg.setStrRegionList(strRegionList);
|
||
maatCfg.setNumRegionList(numRegionList);
|
||
maatCfg.setDigestRegionList(digestRegionList);
|
||
maatCfg.setGroupRelationList(groupRelationList);
|
||
maatCfg.setGroupNum(groupRelationList.size());
|
||
maatCfg.setAreaIpRegionList(areaIpRegionList);
|
||
maatCfg.setIsValid(tempList.get(0).getIsValid());
|
||
// 设置APP自定义域
|
||
String userRegion = "APP_ID=" + tempList.get(0).getAppCode()/*+Constants.USER_REGION_SPLIT+"ASEV_ID="+businessType*/;
|
||
maatCfg.setUserRegion(userRegion);
|
||
configCompileList.add(maatCfg);
|
||
maatBean.setConfigCompileList(configCompileList);
|
||
maatBean.setAuditTime(tempList.get(0).getAuditTime());
|
||
maatBean.setCreatorName(tempList.get(0).getCurrentUser().getName());
|
||
maatBean.setVersion(Constants.MAAT_VERSION);
|
||
maatBean.setOpAction(Constants.INSERT_ACTION);
|
||
// 调用服务接口下发配置数据
|
||
String json = gsonToJson(maatBean);
|
||
logger.info("app协议IP配置下发配置参数:" + json);
|
||
// 调用服务接口下发配置
|
||
ToMaatResult result = ConfigServiceUtil.postMaatCfg(json);
|
||
logger.info("app协议IP配置下发响应信息:" + result.getMsg());
|
||
configGroupInfo.setIsIssued(1);
|
||
configGroupInfo.setUpdateTime(new Date());
|
||
configGroupInfoDao.updateConfigGroupInfobyGroupId(configGroupInfo);
|
||
}else if(configGroupInfo.getIsIssued()==1) {//已经下发,分组复用下发
|
||
GroupReuseAddBean maatBean = new GroupReuseAddBean();
|
||
List<GroupReuseCfg> groupReuseList=new ArrayList<>();
|
||
GroupReuseCfg groupReuseCfg=new GroupReuseCfg();
|
||
/*groupReuseCfg.setUserRegion(userRegion);*/
|
||
groupReuseCfg.setServiceId(tempList.get(0).getServiceId());
|
||
ipRegionList.addAll(groupReuseCfgAddRemoveConvert(tempList,Constants.VALID_YES,configGroupInfo.getGroupId()));
|
||
groupReuseCfg.setIpRegionList(ipRegionList);
|
||
groupReuseCfg.setStrRegionList(strRegionList);
|
||
groupReuseCfg.setNumRegionList(numRegionList);
|
||
groupReuseList.add(groupReuseCfg);
|
||
maatBean.setGroupReuseCfgList(groupReuseList);
|
||
maatBean.setAuditTime(tempList.get(0).getAuditTime());
|
||
maatBean.setCreatorName(tempList.get(0).getCurrentUser().getName());
|
||
maatBean.setVersion(Constants.MAAT_VERSION);
|
||
maatBean.setOpAction(Constants.INSERT_ACTION);
|
||
//调用服务接口下发配置数据
|
||
String json=gsonToJson(maatBean);
|
||
logger.info("app协议IP域新增配置下发配置参数:"+json);
|
||
//调用服务接口下发配置
|
||
ToMaatResult result = ConfigServiceUtil.postGroupReuseSources(json);
|
||
logger.info("app协议IP域新增配置响应信息:"+result.getMsg());
|
||
}else {
|
||
throw new RuntimeException("Unknown configGroupInfo isIssued value");
|
||
}
|
||
}
|
||
}
|
||
tempList.clear();
|
||
}
|
||
long end=System.currentTimeMillis();
|
||
logger.warn("Save IP finish,cost:"+(end-start));
|
||
}
|
||
|
||
/**
|
||
* 导入配置保存CfgIndex
|
||
* @param cfgIndexInfos
|
||
*/
|
||
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)
|
||
public void saveCfgIndexOf(List<CfgIndexInfo> cfgIndexInfos){
|
||
SqlSessionFactory sqlSessionFactory=SpringContextHolder.getBean(SqlSessionFactory.class);
|
||
SqlSession batchSqlSession = null;
|
||
try{
|
||
batchSqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH, false);
|
||
for(int index = 0; index < cfgIndexInfos.size();index++){
|
||
CfgIndexInfo cfgIndexInfo = cfgIndexInfos.get(index);
|
||
((IpCfgDao) batchSqlSession.getMapper(IpCfgDao.class)).saveCfgIndexForBatch(cfgIndexInfo);
|
||
}
|
||
batchSqlSession.commit();
|
||
}finally {
|
||
if(batchSqlSession != null){
|
||
batchSqlSession.close();
|
||
}
|
||
}
|
||
}
|
||
/**
|
||
* 导入配置保存App策略
|
||
* @param appPolicyCfgs
|
||
* @throws CloneNotSupportedException
|
||
*/
|
||
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)
|
||
public void savePolicyList(FunctionRegionDict regionDict,FunctionServiceDict serviceDict,List<AppPolicyCfg> appPolicyCfgs,List<? extends BaseCfg> list,boolean send){
|
||
SqlSessionFactory sqlSessionFactory=SpringContextHolder.getBean(SqlSessionFactory.class);
|
||
SqlSession batchSqlSession = null;
|
||
List<MaatCfg> configCompileList = new ArrayList();
|
||
try{
|
||
batchSqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH, false);
|
||
for(int index = 0; index < appPolicyCfgs.size();index++){
|
||
AppPolicyCfg _cfg = appPolicyCfgs.get(index);
|
||
((AppCfgDao) batchSqlSession.getMapper(AppCfgDao.class)).insertAppPolicyCfgForBatch(_cfg);
|
||
|
||
}
|
||
if(send) {
|
||
StringBuffer cfgKeywords = new StringBuffer();
|
||
if (appPolicyCfgs.get(0).getBehavCode() != null) {
|
||
if (regionDict.getFunctionId().equals(63)) {
|
||
cfgKeywords.append(Constants.APP_ID_REGION + "=" + appPolicyCfgs.get(0).getAppCode());
|
||
} else if (regionDict.getFunctionId().equals(407)
|
||
|| regionDict.getFunctionId().equals(408)) {
|
||
cfgKeywords.append(Constants.PROTO_ID_REGION + "=" + appPolicyCfgs.get(0).getAppCode());
|
||
}
|
||
cfgKeywords.append(Constants.KEYWORD_EXPR);
|
||
cfgKeywords.append(Constants.BEHAV_ID_REGION + "=" + appPolicyCfgs.get(0).getBehavCode());
|
||
// appPolicyCfgs.get(0.setCfgKeywords(appPolicyCfgs.get(0.getAppCode()+Constants.KEYWORD_EXPR+appPolicyCfgs.get(0.getBehavCode());
|
||
} else {
|
||
if (regionDict.getFunctionId().equals(63)) {
|
||
cfgKeywords.append(Constants.APP_ID_REGION + "=" + appPolicyCfgs.get(0).getAppCode());
|
||
} else if (regionDict.getFunctionId().equals(407)
|
||
|| regionDict.getFunctionId().equals(408)) {
|
||
cfgKeywords.append(Constants.PROTO_ID_REGION + "=" + appPolicyCfgs.get(0).getAppCode());
|
||
}
|
||
// entity.setCfgKeywords(entity.getAppCode()+"");
|
||
}
|
||
appPolicyCfgs.get(0).setCfgKeywords(cfgKeywords.toString());
|
||
}
|
||
List<Integer> groupIds=Lists.newArrayList();
|
||
List<Integer> regionIds=Lists.newArrayList();
|
||
if(send) {
|
||
groupIds=ConfigServiceUtil.getId(2, list.size());
|
||
regionIds=ConfigServiceUtil.getId(3, list.size());
|
||
}
|
||
for(int index = 0; index < list.size();index++){
|
||
MaatCfg maatCfg=null;
|
||
if(send) {
|
||
if(regionDict.getIsMaat().intValue()==1) {
|
||
AppPolicyCfg cfg=(AppPolicyCfg) appPolicyCfgs.get(0);
|
||
cfg.setCompileId(list.get(index).getCompileId());
|
||
cfg.setRegionId(regionIds.get(index));
|
||
cfg.setGroupId(groupIds.get(index));
|
||
maatCfg=convertMaatCfg(cfg,2);
|
||
if(regionDict.getFunctionId()==407) {// Protocol Identify
|
||
//PROTOCOL IDENTITY USER_REGION PROTOCOL_ID=ProtocolId
|
||
maatCfg.setUserRegion(Constants.PROTO_ID_REGION + "=" + appPolicyCfgs.get(0).getAppCode());
|
||
|
||
// 限速业务需要设置 USER_REGION Droprate=userregion3
|
||
if (Constants.RATELIMIT_ACTION.equals(appPolicyCfgs.get(0).getAction())) {
|
||
appPolicyCfgs.get(0).setUserRegion1(StringUtil.isEmpty(appPolicyCfgs.get(0).getUserRegion1()) ? "0":appPolicyCfgs.get(0).getUserRegion1());
|
||
//限速 需要发Droprate=0.001 ,暂不支持Bandwidth=200kbps
|
||
if(appPolicyCfgs.get(0).getUserRegion1().equals("0")){//丢包率
|
||
appPolicyCfgs.get(0).setUserRegion2(StringUtil.isEmpty(appPolicyCfgs.get(0).getUserRegion2()) ? "":appPolicyCfgs.get(0).getUserRegion2());
|
||
maatCfg.setUserRegion(maatCfg.getUserRegion()+Constants.USER_REGION_SPLIT +Constants.INTERCEPT_IP_RATELIMIT_DROPRATE_USER_REGION_KEY+"="+appPolicyCfgs.get(0).getUserRegion2());
|
||
}else if(appPolicyCfgs.get(0).getUserRegion1().equals("1")){//带宽
|
||
appPolicyCfgs.get(0).setUserRegion3(StringUtil.isEmpty(appPolicyCfgs.get(0).getUserRegion3()) ? "":appPolicyCfgs.get(0).getUserRegion3());
|
||
maatCfg.setUserRegion(maatCfg.getUserRegion()+Constants.USER_REGION_SPLIT +Constants.INTERCEPT_IP_RATELIMIT_BANDWITH_USER_REGION_KEY+"="+appPolicyCfgs.get(0).getUserRegion3());
|
||
}
|
||
}
|
||
//DKC=8 USER_REGION DKC=userregion4
|
||
if(!StringUtil.isEmpty(appPolicyCfgs.get(0).getUserRegion4()) && Constants.REJECT_ACTION.equals(appPolicyCfgs.get(0).getAction())){
|
||
maatCfg.setUserRegion(maatCfg.getUserRegion()+Constants.USER_REGION_SPLIT +Constants.APP_VIGNORE_USER_REGION_KEY+"="+appPolicyCfgs.get(0).getUserRegion4());
|
||
}
|
||
// USER_REGION config_id=compileId
|
||
maatCfg.setUserRegion(maatCfg.getUserRegion()+Constants.USER_REGION_SPLIT+"config_id="+maatCfg.getCompileId());
|
||
}else if(regionDict.getFunctionId()==63) {// APP Policy
|
||
//APP IDENTITY USER_REGION包含APP_ID=AppCode;BEHAV_ID=ProtocolId
|
||
maatCfg.setUserRegion(Constants.APP_ID_REGION + "=" + appPolicyCfgs.get(0).getAppCode()+Constants.USER_REGION_SPLIT+ Constants.BEHAV_ID_REGION + "=" + appPolicyCfgs.get(0).getBehavCode());
|
||
// 限速业务需要设置
|
||
if (Constants.RATELIMIT_ACTION.equals(appPolicyCfgs.get(0).getAction())) {
|
||
appPolicyCfgs.get(0).setUserRegion1(StringUtil.isEmpty(appPolicyCfgs.get(0).getUserRegion1()) ? "0":appPolicyCfgs.get(0).getUserRegion1());
|
||
//限速 需要发Droprate=0.001 ,暂不支持Bandwidth=200kbps
|
||
if(appPolicyCfgs.get(0).getUserRegion1().equals("0")){//丢包率
|
||
appPolicyCfgs.get(0).setUserRegion2(StringUtil.isEmpty(appPolicyCfgs.get(0).getUserRegion2()) ? "":appPolicyCfgs.get(0).getUserRegion2());
|
||
maatCfg.setUserRegion(maatCfg.getUserRegion()+Constants.USER_REGION_SPLIT +Constants.INTERCEPT_IP_RATELIMIT_DROPRATE_USER_REGION_KEY+"="+appPolicyCfgs.get(0).getUserRegion2());
|
||
}else if(appPolicyCfgs.get(0).getUserRegion1().equals("1")){//带宽
|
||
appPolicyCfgs.get(0).setUserRegion3(StringUtil.isEmpty(appPolicyCfgs.get(0).getUserRegion3()) ? "":appPolicyCfgs.get(0).getUserRegion3());
|
||
maatCfg.setUserRegion(maatCfg.getUserRegion()+Constants.USER_REGION_SPLIT +Constants.INTERCEPT_IP_RATELIMIT_BANDWITH_USER_REGION_KEY+"="+appPolicyCfgs.get(0).getUserRegion3());
|
||
}
|
||
}
|
||
//DKC=8
|
||
if(!StringUtil.isEmpty(appPolicyCfgs.get(0).getUserRegion4()) && Constants.REJECT_ACTION.equals(appPolicyCfgs.get(0).getAction())){
|
||
maatCfg.setUserRegion(Constants.USER_REGION_SPLIT +Constants.APP_VIGNORE_USER_REGION_KEY+"="+appPolicyCfgs.get(0).getUserRegion4());
|
||
}
|
||
maatCfg.setUserRegion(maatCfg.getUserRegion()+Constants.USER_REGION_SPLIT+"config_id="+appPolicyCfgs.get(0).getCompileId());
|
||
}else if(regionDict.getFunctionId()==408) {// Behavior Identify
|
||
//BEHAVIOR IDENTITY USER_REGION包含APP_ID=AppCode;BEHAV_ID=ProtocolId
|
||
maatCfg.setUserRegion(Constants.PROTO_ID_REGION + "=" + appPolicyCfgs.get(0).getAppCode()+Constants.USER_REGION_SPLIT+ Constants.BEHAV_ID_REGION + "=" + appPolicyCfgs.get(0).getBehavCode());
|
||
// 限速业务需要设置
|
||
if (Constants.RATELIMIT_ACTION.equals(appPolicyCfgs.get(0).getAction())) {
|
||
appPolicyCfgs.get(0).setUserRegion1(StringUtil.isEmpty(appPolicyCfgs.get(0).getUserRegion1()) ? "0":appPolicyCfgs.get(0).getUserRegion1());
|
||
//限速 需要发Droprate=0.001 ,暂不支持Bandwidth=200kbps
|
||
if(appPolicyCfgs.get(0).getUserRegion1().equals("0")){//丢包率
|
||
appPolicyCfgs.get(0).setUserRegion2(StringUtil.isEmpty(appPolicyCfgs.get(0).getUserRegion2()) ? "":appPolicyCfgs.get(0).getUserRegion2());
|
||
maatCfg.setUserRegion(maatCfg.getUserRegion()+Constants.USER_REGION_SPLIT +Constants.INTERCEPT_IP_RATELIMIT_DROPRATE_USER_REGION_KEY+"="+appPolicyCfgs.get(0).getUserRegion2());
|
||
}else if(appPolicyCfgs.get(0).getUserRegion1().equals("1")){//带宽
|
||
appPolicyCfgs.get(0).setUserRegion3(StringUtil.isEmpty(appPolicyCfgs.get(0).getUserRegion3()) ? "":appPolicyCfgs.get(0).getUserRegion3());
|
||
maatCfg.setUserRegion(maatCfg.getUserRegion()+Constants.USER_REGION_SPLIT +Constants.INTERCEPT_IP_RATELIMIT_BANDWITH_USER_REGION_KEY+"="+appPolicyCfgs.get(0).getUserRegion3());
|
||
}
|
||
}
|
||
//DKC=8
|
||
if(!StringUtil.isEmpty(appPolicyCfgs.get(0).getUserRegion4()) && Constants.REJECT_ACTION.equals(appPolicyCfgs.get(0).getAction())){
|
||
maatCfg.setUserRegion(Constants.USER_REGION_SPLIT +Constants.APP_VIGNORE_USER_REGION_KEY+"="+appPolicyCfgs.get(0).getUserRegion4());
|
||
}
|
||
maatCfg.setUserRegion(maatCfg.getUserRegion()+Constants.USER_REGION_SPLIT+"config_id="+appPolicyCfgs.get(0).getCompileId());
|
||
}
|
||
}
|
||
|
||
}
|
||
if(list.get(0) instanceof BaseIpCfg) {
|
||
BaseIpCfg _cfg=(BaseIpCfg)list.get(index);
|
||
batchSqlSession.getMapper(IpCfgDao.class).insertForBatch(_cfg);
|
||
if(send) {
|
||
maatCfg=maatCfgAppendRegion(maatCfg,_cfg,1);
|
||
//是否需要处理字符串域and表达式
|
||
configCompileList.add(maatCfg);
|
||
}
|
||
|
||
}else if(list.get(0) instanceof BaseStringCfg) {
|
||
BaseStringCfg _cfg=(BaseStringCfg)list.get(index);
|
||
if("subscribe_id".equals(regionDict.getConfigServiceType())) {
|
||
_cfg.setTableName("ntc_subscribe_id_cfg");
|
||
}
|
||
((StringCfgDao) batchSqlSession.getMapper(StringCfgDao.class)).saveStringCfgBatch(_cfg);
|
||
if(send) {
|
||
maatCfg=maatCfgAppendRegion(maatCfg,_cfg,2);
|
||
//是否需要处理字符串域and表达式
|
||
configCompileList.add(maatCfg);
|
||
}
|
||
}
|
||
}
|
||
if (send) {
|
||
if(configCompileList.size() > 0) {
|
||
ToMaatBean maatBean = new ToMaatBean();
|
||
maatBean.setConfigCompileList(configCompileList);
|
||
maatBean.setAuditTime(new Date());
|
||
maatBean.setCreatorName(UserUtils.getUser().getName());
|
||
maatBean.setVersion(Constants.MAAT_VERSION);
|
||
maatBean.setOpAction(Constants.INSERT_ACTION);
|
||
// 调用服务接口下发配置数据
|
||
String json = BaseService.gsonToJson(maatBean);
|
||
if(json.length()>Constants.JSON_PRINT_LENTH) {
|
||
logger.info("APP策略 配置下发配置条数:" + configCompileList.size());
|
||
}else {
|
||
logger.info("APP策略 配置下发配置参数:" + json);
|
||
}
|
||
// 调用服务接口下发配置
|
||
ToMaatResult result = ConfigServiceUtil.postMaatCfg(json);
|
||
logger.info("APP策略 配置下发响应信息:" + result.getMsg());
|
||
}
|
||
}
|
||
|
||
batchSqlSession.commit();
|
||
}finally {
|
||
if(batchSqlSession != null){
|
||
batchSqlSession.close();
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
/**
|
||
* 导入配置保存App特征
|
||
* @param appFeatures
|
||
*/
|
||
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)
|
||
public void saveAppFeatureList(List<AppFeatureIndex> appFeatures){
|
||
SqlSessionFactory sqlSessionFactory=SpringContextHolder.getBean(SqlSessionFactory.class);
|
||
SqlSession batchSqlSession = null;
|
||
try{
|
||
batchSqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH, false);
|
||
for(int index = 0; index < appFeatures.size();index++){
|
||
AppFeatureIndex _cfg = appFeatures.get(index);
|
||
((AppMultiFeatureCfgDao) batchSqlSession.getMapper(AppMultiFeatureCfgDao.class)).insertAppFeatureIndex(_cfg);
|
||
}
|
||
batchSqlSession.commit();
|
||
}finally {
|
||
if(batchSqlSession != null){
|
||
batchSqlSession.close();
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
/**
|
||
* 导入配置时数据批量入库(IP配置)
|
||
*
|
||
* @param regionDict
|
||
* @param serviceDict
|
||
* @param cfgs
|
||
* @param send
|
||
*/
|
||
@Transactional(readOnly = false, rollbackFor = RuntimeException.class)
|
||
public void saveIpBatch(FunctionRegionDict regionDict, FunctionServiceDict serviceDict,List<BaseIpCfg> cfgs, boolean send) {
|
||
if (regionDict != null) {
|
||
Integer regionType = regionDict.getRegionType();
|
||
if (1 == regionType.intValue()) {
|
||
SqlSessionFactory sqlSessionFactory=SpringContextHolder.getBean(SqlSessionFactory.class);
|
||
SqlSession batchSqlSession = null;
|
||
List<MaatCfg> configCompileList = new ArrayList();
|
||
List<InlineIp> callbackIpList = new ArrayList();
|
||
try{
|
||
batchSqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH, false);
|
||
for(int index = 0; index < cfgs.size();index++){
|
||
BaseIpCfg _cfg = cfgs.get(index);
|
||
if (regionDict.getFunctionId().equals(301)) {
|
||
DdosIpCfg ddosIpCfg=new DdosIpCfg();
|
||
BeanUtils.copyProperties(_cfg, ddosIpCfg);
|
||
//如果insert加入了select last_insert_id,会拖慢6~7倍以上的效率
|
||
((DdosCfgDao) batchSqlSession.getMapper(DdosCfgDao.class)).insert(ddosIpCfg);
|
||
}else if (regionDict.getFunctionId().equals(401)) {
|
||
DnsIpCfg dnsIpCfg=new DnsIpCfg();
|
||
BeanUtils.copyProperties(_cfg, dnsIpCfg);
|
||
//如果insert加入了select last_insert_id,会拖慢6~7倍以上的效率
|
||
((DnsIpCfgDao) batchSqlSession.getMapper(DnsIpCfgDao.class)).insert(dnsIpCfg);
|
||
} else if(regionDict.getFunctionId().equals(565) || regionDict.getFunctionId().equals(566) || regionDict.getFunctionId().equals(563)){
|
||
AppIpCfg app =new AppIpCfg();
|
||
BeanUtils.copyProperties(_cfg, app);
|
||
((AppMultiFeatureCfgDao) batchSqlSession.getMapper(AppMultiFeatureCfgDao.class)).insertAppIpRangeCfg(app);
|
||
}
|
||
else {
|
||
batchSqlSession.getMapper(IpCfgDao.class).insertForBatch(_cfg);
|
||
}
|
||
|
||
if(send) {
|
||
if(regionDict.getIsMaat().intValue()==1) {
|
||
MaatCfg maatCfg=convertMaatCfg(_cfg,1);
|
||
//userregion处理
|
||
//限速需要发Droprate=0.001 ,暂不支持Bandwidth=200kbps
|
||
if(_cfg.getAction().equals(Constants.RATELIMIT_ACTION)){
|
||
if(_cfg.getUserRegion1().equals("0")){//丢包率
|
||
_cfg.setUserRegion2(StringUtil.isEmpty(_cfg.getUserRegion2()) ? "":_cfg.getUserRegion2());
|
||
maatCfg.setUserRegion(Constants.INTERCEPT_IP_RATELIMIT_DROPRATE_USER_REGION_KEY+"="+_cfg.getUserRegion2());
|
||
}else if(_cfg.getUserRegion1().equals("1")){//带宽
|
||
_cfg.setUserRegion3(StringUtil.isEmpty(_cfg.getUserRegion3()) ? "":_cfg.getUserRegion3());
|
||
maatCfg.setUserRegion(Constants.INTERCEPT_IP_RATELIMIT_BANDWITH_USER_REGION_KEY+"="+_cfg.getUserRegion3());
|
||
}
|
||
}else if(regionDict.getFunctionId()==510) {
|
||
maatCfg.setUserRegion(Constants.P2P_IP_TYPE_USER_REGION_KEY+"="+_cfg.getUserRegion2());
|
||
}else if(regionDict.getFunctionId()==7) {
|
||
if(!StringUtil.isEmpty(_cfg.getDnsStrategyId())){
|
||
// maatCfg.setUserRegion(Constants.USER_REGION_SPLIT+entity.getDnsStrategyId()+Constants.USER_REGION_SPLIT);
|
||
maatCfg.setUserRegion(Constants.DNS_STRATEGY_USER_REGION_KEY+"="+_cfg.getDnsStrategyId());
|
||
}
|
||
}else if(regionDict.getFunctionId()==301) {// Anti DDOS
|
||
Map umap= new HashMap();
|
||
umap.put("protocol", _cfg.getAntiddosProtocol());
|
||
umap.put("bps_threadshold", _cfg.getBpsThreadshold());
|
||
umap.put("pps_threadshold", _cfg.getPpsThreadshold());
|
||
maatCfg.setUserRegion(new Gson().toJson(umap));
|
||
}else if(regionDict.getFunctionId()==200) {// IP Intercept
|
||
/*maatCfg.setUserRegion(Constants.USER_REGION_PLACEHOLDER);
|
||
if(_cfg.getAction().equals(Constants.MONIT_ACTION)) {
|
||
maatCfg.setUserRegion(Constants.INTERCEPT_IP_MONIT_USER_REGION_KEY+"="+Constants.USER_REGION_PLACEHOLDER);
|
||
}*/
|
||
/*if(serviceDict!=null&&serviceDict.getAction().equals(Constants.MONIT_ACTION)) {// 监测 需要发keyring_id、拦截强度
|
||
_cfg.setUserRegion1(StringUtil.isEmpty(_cfg.getUserRegion1()) ? "0":_cfg.getUserRegion1());
|
||
_cfg.setUserRegion5(StringUtil.isEmpty(_cfg.getUserRegion5()) ? "1":_cfg.getUserRegion5());
|
||
maatCfg.setUserRegion(Constants.INTERCEPT_IP_MONIT_USER_REGION_KEY+"=0"+";"+Constants.INTERCEPT_DOMAN_INTENSITY_USER_REGION_KEY+"="+_cfg.getUserRegion5());
|
||
}*/
|
||
if(serviceDict!=null&&serviceDict.getServiceId().equals(512)) {
|
||
maatCfg.setUserRegion(_cfg.getUserRegion1());
|
||
}
|
||
if(serviceDict!=null&&serviceDict.getAction().equals(64)) {
|
||
maatCfg.setUserRegion(Constants.INTERCEPT_IP_RATELIMIT_DROPRATE_USER_REGION_KEY+"="+_cfg.getUserRegion2());
|
||
}
|
||
|
||
}else if(regionDict.getFunctionId()==207 || regionDict.getFunctionId()==208 || regionDict.getFunctionId()==209) {// HTTP(s)阻断、重定向、替换
|
||
String userRegion = Constants.USER_REGION_PLACEHOLDER;
|
||
if(_cfg.getAction().equals(Constants.REJECT_ACTION)) {// 阻断
|
||
userRegion = Constants.REDIRECT_RESPONSE_CODE_KEY+"="+_cfg.getUserRegion1()+";"+Constants.REDIRECT_CONTENT_KEY+"="+_cfg.getUserRegion2();
|
||
}else if(_cfg.getAction().equals(48)) {// 重定向
|
||
userRegion = Constants.REDIRECT_RESPONSE_CODE_KEY+"="+_cfg.getUserRegion1()+";"+Constants.REDIRECT_URL_KEY+"="+_cfg.getUserRegion2();;
|
||
}else if(_cfg.getAction().equals(Constants.REPLACE_ACTION)) {// 替换
|
||
String substitute = "/"+_cfg.getUserRegion2()+"/"+_cfg.getUserRegion3();
|
||
userRegion = Constants.REPLACE_ZONE_KEY+"="+_cfg.getUserRegion1()+";"+Constants.REPLACE_SUBSTITUTE_KEY+"="+substitute;
|
||
}
|
||
maatCfg.setUserRegion(userRegion);
|
||
}else if(regionDict.getFunctionId()==563 || regionDict.getFunctionId()==565 || regionDict.getFunctionId()==566) {// APP Payload、HTTP、SSL Admin
|
||
maatCfg.setUserRegion(Constants.APP_ID_REGION+"="+_cfg.getAppCode());
|
||
}else if(regionDict.getFunctionId()==214) {
|
||
String userRegion="nat_type="+_cfg.getUserRegion1()+";spoofing_ip_pool="+_cfg.getUserRegion3();
|
||
maatCfg.setUserRegion(userRegion);
|
||
}else if(regionDict.getFunctionId()==212) {
|
||
String userRegion=Constants.REPLACE_ZONE_KEY+"="+_cfg.getUserRegion1();
|
||
String substitute="";
|
||
String userRegion2=StringUtil.isEmpty(_cfg.getUserRegion2()) ? "":_cfg.getUserRegion2();
|
||
substitute="/";
|
||
userRegion2 = BaseService.replaceContentEscape(userRegion2);
|
||
substitute=substitute+userRegion2;
|
||
|
||
String userRegion3=StringUtil.isEmpty(_cfg.getUserRegion3()) ? "":_cfg.getUserRegion3();
|
||
userRegion3 = BaseService.replaceContentEscape(userRegion3);
|
||
substitute=substitute+"/"+userRegion3;
|
||
|
||
userRegion=userRegion+";"+Constants.REPLACE_SUBSTITUTE_KEY+"="+substitute;
|
||
maatCfg.setUserRegion(userRegion);
|
||
}else if(regionDict.getFunctionId()==215) {
|
||
ManipulatActionParam actionParam = new ManipulatActionParam();
|
||
if(regionDict.getAction().equals(48)) {
|
||
actionParam.setMethod("redirect");
|
||
actionParam.setCode(Integer.valueOf(_cfg.getUserRegion1()));
|
||
actionParam.setTo(_cfg.getUserRegion2());
|
||
}else if(regionDict.getAction().equals(80)) {
|
||
List<ReplaceCfg> ReplaceCfgList = new ArrayList();
|
||
ReplaceCfg replaceCfg = new ReplaceCfg();
|
||
replaceCfg.setSearch_in(_cfg.getUserRegion1());
|
||
replaceCfg.setFind(_cfg.getUserRegion2());
|
||
replaceCfg.setReplace_with(_cfg.getUserRegion3());
|
||
ReplaceCfgList.add(replaceCfg);
|
||
actionParam.setMethod("replace");
|
||
actionParam.setRules(ReplaceCfgList);
|
||
}else if(regionDict.getAction().equals(16)) {
|
||
actionParam.setMethod("block");
|
||
actionParam.setCode(Integer.valueOf(_cfg.getUserRegion1()));
|
||
actionParam.setMessage(_cfg.getUserRegion2());
|
||
actionParam.setHtml_profile(0);
|
||
}else if(regionDict.getAction().equals(85)) {
|
||
actionParam.setMethod("hijack");
|
||
actionParam.setHijack_profile(Integer.valueOf(_cfg.getUserRegion4()));
|
||
}else if(regionDict.getAction().equals(90)) {
|
||
actionParam.setMethod("insert");
|
||
actionParam.setInsert_profile(Integer.valueOf(_cfg.getUserRegion4()));
|
||
}
|
||
maatCfg.setUserRegion(gsonToJson(actionParam));
|
||
}else if(regionDict.getFunctionId()==211 || regionDict.getFunctionId()==210){
|
||
maatCfg.setUserRegion("{}");
|
||
}
|
||
|
||
configCompileList.add(maatCfg);
|
||
}else {
|
||
//根据具体情况判断
|
||
callbackIpList.add(this.convertCallBackIp(_cfg,_cfg.getDnsStrategyId()));
|
||
}
|
||
}
|
||
}
|
||
long start=System.currentTimeMillis();
|
||
long end=System.currentTimeMillis();
|
||
if (send) {
|
||
if(configCompileList.size() > 0) {
|
||
ToMaatBean maatBean = new ToMaatBean();
|
||
maatBean.setConfigCompileList(configCompileList);
|
||
maatBean.setAuditTime(new Date());
|
||
maatBean.setCreatorName(UserUtils.getUser().getName());
|
||
maatBean.setVersion(Constants.MAAT_VERSION);
|
||
maatBean.setOpAction(Constants.INSERT_ACTION);
|
||
start=System.currentTimeMillis();
|
||
// 调用服务接口下发配置数据
|
||
String json = BaseService.gsonToJson(maatBean);
|
||
if(json.length()>Constants.JSON_PRINT_LENTH) {
|
||
logger.info("IP 配置下发配置条数:" + configCompileList.size());
|
||
}else {
|
||
logger.info("IP 配置下发配置参数:" + json);
|
||
}
|
||
// 调用服务接口下发配置
|
||
|
||
ToMaatResult result = ConfigServiceUtil.postMaatCfg(json);
|
||
logger.info("IP 配置下发响应信息:" + result.getMsg());
|
||
end=System.currentTimeMillis();
|
||
logger.info("IP 配置下发配置耗时:" + (end-start));
|
||
}else {
|
||
//调用服务接口下发配置数据
|
||
String json=gsonToJson(callbackIpList);
|
||
logger.info("IP配置下发配置参数:"+json);
|
||
//调用服务接口下发配置
|
||
try {
|
||
ToMaatResult result = ConfigServiceUtil.postCallbackCfg(json);
|
||
if(result!=null){
|
||
logger.info("IP配置配置下发响应信息:"+result.getMsg());
|
||
}
|
||
} catch (Exception e) {
|
||
logger.error("IP配置配置下发失败",e);
|
||
throw e;
|
||
}
|
||
}
|
||
}
|
||
batchSqlSession.commit();
|
||
}finally {
|
||
if(batchSqlSession != null){
|
||
batchSqlSession.close();
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
}
|
||
/**
|
||
* 导入配置时数据批量入库(字符串配置)
|
||
*
|
||
* @param data
|
||
* @param tableName
|
||
*/
|
||
@Transactional(readOnly = false, rollbackFor = RuntimeException.class)
|
||
public void saveStringCfgBatch(FunctionRegionDict regionDict, FunctionServiceDict serviceDict,
|
||
List<BaseStringCfg<?>> data, String tableName, boolean send) {
|
||
if (regionDict != null) {
|
||
Integer regionType = regionDict.getRegionType();
|
||
if (2 == regionType.intValue()) {
|
||
SqlSessionFactory sqlSessionFactory = SpringContextHolder.getBean(SqlSessionFactory.class);
|
||
List<MaatCfg> configCompileList = new ArrayList();
|
||
SqlSession batchSqlSession = null;
|
||
try {
|
||
batchSqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH, false);
|
||
for (int index = 0; index < data.size(); index++) {
|
||
BaseStringCfg<?> _cfg = data.get(index);
|
||
_cfg.setTableName(tableName);
|
||
if(regionDict.getDictId().intValue()==64){
|
||
AppDomainCfg cfg=new AppDomainCfg();
|
||
BeanUtils.copyProperties(_cfg, cfg);
|
||
((AppCfgDao) batchSqlSession.getMapper(AppCfgDao.class)).insertAppDomainCfgBatch(cfg);
|
||
}else {
|
||
((StringCfgDao) batchSqlSession.getMapper(StringCfgDao.class)).saveStringCfgBatch(_cfg);
|
||
}
|
||
if (send) {
|
||
if(regionDict.getIsMaat().intValue()==1) {
|
||
MaatCfg maatCfg=convertMaatCfg(_cfg,2);
|
||
//userregion处理
|
||
if(regionDict.getFunctionId()==7) {
|
||
if(!StringUtil.isEmpty(_cfg.getDnsStrategyId())){
|
||
// maatCfg.setUserRegion(Constants.USER_REGION_SPLIT+entity.getDnsStrategyId()+Constants.USER_REGION_SPLIT);
|
||
maatCfg.setUserRegion(Constants.DNS_STRATEGY_USER_REGION_KEY+"="+_cfg.getDnsStrategyId());
|
||
}
|
||
}else if(regionDict.getDictId()==159) {
|
||
maatCfg.setUserRegion(Constants.P2P_HASH_TYPE_USER_REGION_KEY+"="+_cfg.getUserRegion1());
|
||
}else if(regionDict.getFunctionId()==200) {// Domain Intercept
|
||
if(serviceDict!=null&&serviceDict.getServiceId().equals(512)) {
|
||
maatCfg.setUserRegion(_cfg.getUserRegion1());
|
||
}else {
|
||
String userRegion = Constants.USERREGION_DOMAIN_ID+"="+_cfg.getCompileId()+";"+Constants.USERREGION_DOMAIN_STR+"="+_cfg.getCfgKeywords();
|
||
/*if(_cfg.getAction().equals(Constants.MONIT_ACTION)) {// 监测 需要发keyring_id、拦截强度
|
||
userRegion = Constants.INTERCEPT_IP_MONIT_USER_REGION_KEY+"=0"+";"+Constants.INTERCEPT_DOMAN_INTENSITY_USER_REGION_KEY+"="+_cfg.getUserRegion5()+";" + userRegion;
|
||
}else*/ if(_cfg.getAction().equals(Constants.RATELIMIT_ACTION)) {// 限速 需要发Droprate
|
||
userRegion = Constants.INTERCEPT_IP_RATELIMIT_DROPRATE_USER_REGION_KEY+"="+_cfg.getUserRegion2()+";" + userRegion;
|
||
}
|
||
maatCfg.setUserRegion(userRegion);
|
||
}
|
||
|
||
}else if(regionDict.getFunctionId()==207 || regionDict.getFunctionId()==208 || regionDict.getFunctionId()==209) {// HTTP(s)阻断、重定向、替换
|
||
String userRegion = Constants.USER_REGION_PLACEHOLDER;
|
||
if(_cfg.getAction().equals(Constants.REJECT_ACTION)) {// 阻断
|
||
userRegion = Constants.REDIRECT_RESPONSE_CODE_KEY+"="+_cfg.getUserRegion1()+";"+Constants.REDIRECT_CONTENT_KEY+"="+_cfg.getUserRegion2();
|
||
}else if(_cfg.getAction().equals(48)) {// 重定向
|
||
userRegion = Constants.REDIRECT_RESPONSE_CODE_KEY+"="+_cfg.getUserRegion1()+";"+Constants.REDIRECT_URL_KEY+"="+_cfg.getUserRegion2();;
|
||
}else if(_cfg.getAction().equals(Constants.REPLACE_ACTION)) {// 替换
|
||
String substitute = "/"+_cfg.getUserRegion2()+"/"+_cfg.getUserRegion3();
|
||
userRegion = Constants.REPLACE_ZONE_KEY+"="+_cfg.getUserRegion1()+";"+Constants.REPLACE_SUBSTITUTE_KEY+"="+substitute;
|
||
}
|
||
maatCfg.setUserRegion(userRegion);
|
||
}else if(regionDict.getFunctionId()==215) {
|
||
ManipulatActionParam actionParam = new ManipulatActionParam();
|
||
if(regionDict.getAction().equals(48)) {
|
||
actionParam.setMethod("redirect");
|
||
actionParam.setCode(Integer.valueOf(_cfg.getUserRegion1()));
|
||
actionParam.setTo(_cfg.getUserRegion2());
|
||
}else if(regionDict.getAction().equals(80)) {
|
||
List<ReplaceCfg> ReplaceCfgList = new ArrayList();
|
||
ReplaceCfg replaceCfg = new ReplaceCfg();
|
||
replaceCfg.setSearch_in(_cfg.getUserRegion1());
|
||
replaceCfg.setFind(_cfg.getUserRegion2());
|
||
replaceCfg.setReplace_with(_cfg.getUserRegion3());
|
||
ReplaceCfgList.add(replaceCfg);
|
||
actionParam.setMethod("replace");
|
||
actionParam.setRules(ReplaceCfgList);
|
||
}else if(regionDict.getAction().equals(16)) {
|
||
actionParam.setMethod("block");
|
||
actionParam.setCode(Integer.valueOf(_cfg.getUserRegion1()));
|
||
actionParam.setMessage(_cfg.getUserRegion2());
|
||
actionParam.setHtml_profile(0);
|
||
}else if(regionDict.getAction().equals(85)) {
|
||
actionParam.setMethod("hijack");
|
||
actionParam.setHijack_profile(Integer.valueOf(_cfg.getUserRegion4()));
|
||
}else if(regionDict.getAction().equals(90)) {
|
||
actionParam.setMethod("insert");
|
||
actionParam.setInsert_profile(Integer.valueOf(_cfg.getUserRegion4()));
|
||
}
|
||
maatCfg.setUserRegion(gsonToJson(actionParam));
|
||
}else if(regionDict.getFunctionId()==211 || regionDict.getFunctionId()==210){
|
||
maatCfg.setUserRegion("{}");
|
||
}
|
||
configCompileList.add(maatCfg);
|
||
}
|
||
|
||
}
|
||
}
|
||
long start=System.currentTimeMillis();
|
||
long end=System.currentTimeMillis();
|
||
if (send && configCompileList.size() > 0) {
|
||
ToMaatBean maatBean = new ToMaatBean();
|
||
maatBean.setConfigCompileList(configCompileList);
|
||
maatBean.setAuditTime(new Date());
|
||
maatBean.setCreatorName(UserUtils.getUser().getName());
|
||
maatBean.setVersion(Constants.MAAT_VERSION);
|
||
maatBean.setOpAction(Constants.INSERT_ACTION);
|
||
start=System.currentTimeMillis();
|
||
// 调用服务接口下发配置数据
|
||
String json = BaseService.gsonToJson(maatBean);
|
||
if(json.length()>Constants.JSON_PRINT_LENTH) {
|
||
logger.info("字符串配置下发配置条数:" + configCompileList.size());
|
||
}else {
|
||
logger.info("字符串配置下发配置参数:" + json);
|
||
}
|
||
// 调用服务接口下发配置
|
||
ToMaatResult result = ConfigServiceUtil.postMaatCfg(json);
|
||
logger.info("字符串配置下发响应信息:" + result.getMsg());
|
||
end=System.currentTimeMillis();
|
||
logger.info("字符串配置下发配置耗时:" + (end-start));
|
||
|
||
}
|
||
batchSqlSession.commit();
|
||
} finally {
|
||
if (batchSqlSession != null) {
|
||
batchSqlSession.close();
|
||
}
|
||
}
|
||
} else {
|
||
throw new RuntimeException("Region type must be 2!");
|
||
}
|
||
}
|
||
}
|
||
/**
|
||
* 导入配置时数据批量入库(增强字符串配置)
|
||
* @param data
|
||
* @param tableName
|
||
*/
|
||
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)
|
||
public void saveComplexkeywordCfgBatch(FunctionRegionDict regionDict, FunctionServiceDict serviceDict,List<ComplexkeywordCfg> data, String tableName,boolean send) {
|
||
if (regionDict != null) {
|
||
Integer regionType = regionDict.getRegionType();
|
||
if (3 == regionType.intValue()) {
|
||
SqlSessionFactory sqlSessionFactory=SpringContextHolder.getBean(SqlSessionFactory.class);
|
||
List<MaatCfg> configCompileList = new ArrayList();
|
||
SqlSession batchSqlSession = null;
|
||
try{
|
||
batchSqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH, false);
|
||
for(int index = 0; index < data.size();index++){
|
||
ComplexkeywordCfg cfg = data.get(index);
|
||
cfg.setTableName(tableName);
|
||
if(regionDict.getDictId().intValue()==63) {
|
||
AppHttpCfg _cfg=new AppHttpCfg();
|
||
BeanUtils.copyProperties(cfg, _cfg);
|
||
((AppCfgDao) batchSqlSession.getMapper(AppCfgDao.class)).insertAppHttpCfgBatch(_cfg);
|
||
}else if(regionDict.getDictId().intValue()==220 || regionDict.getDictId().intValue()==216 || regionDict.getDictId().intValue()==224){
|
||
AppComplexFeatureCfg appCfg=new AppComplexFeatureCfg();
|
||
BeanUtils.copyProperties(cfg, appCfg);
|
||
((AppMultiFeatureCfgDao) batchSqlSession.getMapper(AppMultiFeatureCfgDao.class)).insertAppComplexFeatureCfg(appCfg);
|
||
}
|
||
else {
|
||
((StringCfgDao) batchSqlSession.getMapper(StringCfgDao.class)).saveComplexkeywordCfgBatch(cfg);
|
||
}
|
||
if (send) {
|
||
if(regionDict.getIsMaat().intValue()==1) {
|
||
MaatCfg maatCfg=convertMaatCfg(cfg,3);
|
||
//userregion处理
|
||
if(regionDict.getFunctionId()==7) {
|
||
if(!StringUtil.isEmpty(cfg.getDnsStrategyId())){
|
||
// maatCfg.setUserRegion(Constants.USER_REGION_SPLIT+entity.getDnsStrategyId()+Constants.USER_REGION_SPLIT);
|
||
maatCfg.setUserRegion(Constants.DNS_STRATEGY_USER_REGION_KEY+"="+cfg.getDnsStrategyId());
|
||
}
|
||
}else if(regionDict.getDictId()==10) {
|
||
String dictValue = DictUtils.getDictCode(Constants.HTTP_HEADER_DICT_MODULE, cfg.getDistrict());
|
||
if(StringUtil.isEmpty(dictValue) || dictValue.equals("默认")){
|
||
maatCfg.setUserRegion(Constants.HTTP_HEADER_USER_REGION_KEY+"="+cfg.getDistrict());
|
||
}
|
||
}else if(regionDict.getDictId()==11) {
|
||
String dictValue = DictUtils.getDictCode(Constants.HTTP_HEADER_DICT_MODULE, cfg.getDistrict());
|
||
if(StringUtil.isEmpty(dictValue) || dictValue.equals("默认")){
|
||
maatCfg.setUserRegion(Constants.HTTP_HEADER_USER_REGION_KEY+"="+cfg.getDistrict());
|
||
}
|
||
}else if(regionDict.getFunctionId()==207 || regionDict.getFunctionId()==208 || regionDict.getFunctionId()==209) {// HTTP(s)阻断、重定向、替换
|
||
String userRegion = Constants.USER_REGION_PLACEHOLDER;
|
||
if(cfg.getAction().equals(Constants.REJECT_ACTION)) {// 阻断
|
||
userRegion = Constants.REDIRECT_RESPONSE_CODE_KEY+"="+cfg.getUserRegion1()+";"+Constants.REDIRECT_CONTENT_KEY+"="+cfg.getUserRegion2();
|
||
}else if(cfg.getAction().equals(48)) {// 重定向
|
||
userRegion = Constants.REDIRECT_RESPONSE_CODE_KEY+"="+cfg.getUserRegion1()+";"+Constants.REDIRECT_URL_KEY+"="+cfg.getUserRegion2();;
|
||
}else if(cfg.getAction().equals(Constants.REPLACE_ACTION)) {// 替换
|
||
String substitute = "/"+cfg.getUserRegion2()+"/"+cfg.getUserRegion3();
|
||
userRegion = Constants.REPLACE_ZONE_KEY+"="+cfg.getUserRegion1()+";"+Constants.REPLACE_SUBSTITUTE_KEY+"="+substitute;
|
||
}
|
||
maatCfg.setUserRegion(userRegion);
|
||
}else if(regionDict.getFunctionId()==564 || regionDict.getFunctionId()==565 || regionDict.getFunctionId()==566) {// APP HTTP、DNS、SSL Admin
|
||
maatCfg.setUserRegion(Constants.APP_ID_REGION+"="+cfg.getAppCode());
|
||
}else if(regionDict.getFunctionId()==215) {
|
||
ManipulatActionParam actionParam = new ManipulatActionParam();
|
||
if(regionDict.getAction().equals(48)) {
|
||
actionParam.setMethod("redirect");
|
||
actionParam.setCode(Integer.valueOf(cfg.getUserRegion1()));
|
||
actionParam.setTo(cfg.getUserRegion2());
|
||
}else if(regionDict.getAction().equals(80)) {
|
||
List<ReplaceCfg> ReplaceCfgList = new ArrayList();
|
||
ReplaceCfg replaceCfg = new ReplaceCfg();
|
||
replaceCfg.setSearch_in(cfg.getUserRegion1());
|
||
replaceCfg.setFind(cfg.getUserRegion2());
|
||
replaceCfg.setReplace_with(cfg.getUserRegion3());
|
||
ReplaceCfgList.add(replaceCfg);
|
||
actionParam.setMethod("replace");
|
||
actionParam.setRules(ReplaceCfgList);
|
||
}else if(regionDict.getAction().equals(16)) {
|
||
actionParam.setMethod("block");
|
||
actionParam.setCode(Integer.valueOf(cfg.getUserRegion1()));
|
||
actionParam.setMessage(cfg.getUserRegion2());
|
||
actionParam.setHtml_profile(0);
|
||
}else if(regionDict.getAction().equals(85)) {
|
||
actionParam.setMethod("hijack");
|
||
actionParam.setHijack_profile(Integer.valueOf(cfg.getUserRegion4()));
|
||
}else if(regionDict.getAction().equals(90)) {
|
||
actionParam.setMethod("insert");
|
||
actionParam.setInsert_profile(Integer.valueOf(cfg.getUserRegion4()));
|
||
}
|
||
maatCfg.setUserRegion(gsonToJson(actionParam));
|
||
}else if(regionDict.getFunctionId()==211 || regionDict.getFunctionId()==210) {
|
||
maatCfg.setUserRegion("{}");
|
||
}
|
||
configCompileList.add(maatCfg);
|
||
}
|
||
}
|
||
|
||
}
|
||
if (send && configCompileList.size() > 0) {
|
||
ToMaatBean maatBean = new ToMaatBean();
|
||
maatBean.setConfigCompileList(configCompileList);
|
||
maatBean.setAuditTime(new Date());
|
||
maatBean.setCreatorName(UserUtils.getUser().getName());
|
||
maatBean.setVersion(Constants.MAAT_VERSION);
|
||
maatBean.setOpAction(Constants.INSERT_ACTION);
|
||
// 调用服务接口下发配置数据
|
||
String json = BaseService.gsonToJson(maatBean);
|
||
if(json.length()>Constants.JSON_PRINT_LENTH) {
|
||
logger.info("增强字符串配置下发配置条数:" + configCompileList.size());
|
||
}else {
|
||
logger.info("增强字符串配置下发配置参数:" + json);
|
||
}
|
||
// 调用服务接口下发配置
|
||
ToMaatResult result = ConfigServiceUtil.postMaatCfg(json);
|
||
logger.info("增强字符串配置下发响应信息:" + result.getMsg());
|
||
|
||
}
|
||
batchSqlSession.commit();
|
||
}finally {
|
||
if(batchSqlSession != null){
|
||
batchSqlSession.close();
|
||
}
|
||
}
|
||
}
|
||
|
||
}
|
||
|
||
}
|
||
/**
|
||
* asn ip分组复用新增
|
||
* @param asnIpCfgs
|
||
*/
|
||
public void asnIPRegionSendToMaat(List<AsnIpCfg> asnIpCfgs,Integer valid) {
|
||
logger.warn("asnIPRegionSendToMaat start");
|
||
long start=System.currentTimeMillis();
|
||
GroupReuseAddBean maatBean = new GroupReuseAddBean();
|
||
List<GroupReuseCfg> groupReuseList=new ArrayList<>();
|
||
GroupReuseCfg groupReuseCfg=new GroupReuseCfg();
|
||
List<IpCfg> ipRegionList = groupReuseCfgAddRemoveConvert(asnIpCfgs,valid,null);
|
||
List<StringCfg> strRegionList = new ArrayList<>();
|
||
List<NumBoundaryCfg> numRegionList = new ArrayList<>();
|
||
groupReuseCfg.setIpRegionList(ipRegionList);
|
||
groupReuseCfg.setStrRegionList(strRegionList);
|
||
groupReuseCfg.setNumRegionList(numRegionList);
|
||
groupReuseList.add(groupReuseCfg);
|
||
maatBean.setGroupReuseCfgList(groupReuseList);
|
||
maatBean.setAuditTime(new Date());
|
||
maatBean.setCreatorName(UserUtils.getUser().getName());
|
||
maatBean.setVersion(Constants.MAAT_VERSION);
|
||
if(valid==Constants.VALID_YES) {
|
||
maatBean.setOpAction(Constants.INSERT_ACTION);
|
||
//调用服务接口下发配置数据
|
||
String json=gsonToJson(maatBean);
|
||
if(asnIpCfgs.size()<=100) {
|
||
logger.info("asn ip复用域新增配置下发配置参数:"+json);
|
||
}else {
|
||
logger.info("asn ip复用域新增配置下发region条数:"+asnIpCfgs.size());
|
||
}
|
||
//调用服务接口下发配置
|
||
ToMaatResult result =ConfigServiceUtil.postGroupReuseSources(json);
|
||
logger.info("asn ip复用域新增配置响应信息:"+result.getMsg());
|
||
}else {
|
||
maatBean.setOpAction(Constants.UPDATE_ACTION);
|
||
//调用服务接口下发配置数据
|
||
String json=gsonToJson(maatBean);
|
||
if(asnIpCfgs.size()<=100) {
|
||
logger.info("asn ip复用域删除配置下发配置参数:"+json);
|
||
}else {
|
||
logger.info("asn ip复用域删除配置下发region条数:"+asnIpCfgs.size());
|
||
|
||
}
|
||
//调用服务接口下发配置
|
||
ToMaatResult result = ConfigServiceUtil.put(json,3);
|
||
logger.info("asn ip复用域删除配置响应信息:"+result.getMsg());
|
||
}
|
||
long end=System.currentTimeMillis();
|
||
logger.warn("asnIPRegionSendToMaat finish,cost:"+(end-start));
|
||
}
|
||
|
||
/**
|
||
* 处理IpSpoofing配置导入
|
||
* @param list
|
||
* @param cfgIndexInfos
|
||
* @param send
|
||
*/
|
||
public void saveAndSendSpoofingIpPool(List<? extends BaseCfg> list, List<CfgIndexInfo> cfgIndexInfos, boolean send) {
|
||
List<BaseIpCfg> ipCfgList = (List<BaseIpCfg>)list;
|
||
List<Integer> spoofingPoolIds=Lists.newArrayList();
|
||
List<PxyObjSpoofingIpPool> spoofingPools = new ArrayList<PxyObjSpoofingIpPool>();
|
||
PxyObjSpoofingIpPoolDao pxyObjSpoofingIpPoolDao = SpringContextHolder.getBean(PxyObjSpoofingIpPoolDao.class);
|
||
|
||
try {
|
||
spoofingPoolIds = ConfigServiceUtil.getId(1,ipCfgList.size());
|
||
} catch (Exception e) {
|
||
e.printStackTrace();
|
||
logger.info("获取编译ID出错");
|
||
throw new MaatConvertException("<spring:message code=\"request_service_failed\"/>:"+e.getMessage());
|
||
}
|
||
int index = 0;
|
||
for (BaseIpCfg cfg : ipCfgList) {
|
||
// 保存IP仿冒池
|
||
PxyObjSpoofingIpPool spoofingPool = new PxyObjSpoofingIpPool();
|
||
spoofingPool.setIpType(4);//ipv4
|
||
spoofingPool.setIpAddress(cfg.getUserRegion2());//仿冒IP
|
||
spoofingPool.setProtocol(0);
|
||
if("dnat".equals(cfg.getUserRegion1().toLowerCase())){//spoofing server ip->dnat
|
||
spoofingPool.setDirection(1);
|
||
}else{
|
||
spoofingPool.setDirection(2);//spoofing client ip->snat
|
||
}
|
||
spoofingPool.setPort("0");
|
||
spoofingPool.setUserRegion("0");
|
||
spoofingPool.setLocation(0);
|
||
spoofingPool.setServiceId(642);
|
||
spoofingPool.setAreaEffectiveIds("0");
|
||
spoofingPool.setIsAreaEffective(0);
|
||
spoofingPool.setCreateTime(cfg.getCreateTime());
|
||
spoofingPool.setCreatorId(UserUtils.getUser().getId());
|
||
if(spoofingPoolIds.size() == ipCfgList.size()) {
|
||
spoofingPool.setCompileId(spoofingPoolIds.get(index));
|
||
}
|
||
spoofingPool.setAction(1);
|
||
spoofingPool.setFunctionId(666);
|
||
spoofingPool.setRequestId(0);
|
||
if(send) {
|
||
spoofingPool.setIsAudit(Constants.AUDIT_YES);
|
||
spoofingPool.setIsValid(Constants.VALID_YES);
|
||
spoofingPool.setAuditorId(UserUtils.getUser().getId());
|
||
spoofingPool.setAuditTime(cfg.getAuditTime());
|
||
|
||
}else {
|
||
spoofingPool.setIsValid(Constants.VALID_NO);
|
||
spoofingPool.setIsAudit(Constants.AUDIT_NOT_YET);
|
||
|
||
}
|
||
pxyObjSpoofingIpPoolDao.insert(spoofingPool);//保存仿冒IP池配置
|
||
cfg.setUserRegion3(String.valueOf(spoofingPool.getCfgId()));//将仿冒IP池配置ID作为策略组ID
|
||
|
||
if(send) {
|
||
PxyObjSpoofingIpPool pool=new PxyObjSpoofingIpPool();
|
||
pool.setCfgId(Long.valueOf(cfg.getUserRegion3()));
|
||
pool.setIsValid(cfg.getIsValid());
|
||
pool.setIsAudit(cfg.getIsAudit());
|
||
pool.setAuditorId(UserUtils.getUser().getId());
|
||
pool.setAuditTime(cfg.getAuditTime());
|
||
pxyObjSpoofingIpPoolDao.update(pool);
|
||
|
||
spoofingPool.setAreaEffectiveIds("0");
|
||
spoofingPool.setGroupId(spoofingPool.getCfgId().intValue());
|
||
spoofingPools.add(spoofingPool);
|
||
}
|
||
|
||
CfgIndexInfo cfgIndexInfo = new CfgIndexInfo();
|
||
BeanUtils.copyProperties(cfg, cfgIndexInfo,new String[] {"cfgId"});
|
||
cfgIndexInfos.add(cfgIndexInfo);
|
||
|
||
index ++;
|
||
}
|
||
|
||
if(send && spoofingPools.size()>0) {
|
||
//调用服务接口下发配置数据
|
||
String json=gsonToJson(spoofingPools);
|
||
if(spoofingPools.size()>10) {
|
||
logger.info("欺骗IP池配置下发配置条数:" + spoofingPools.size());
|
||
}else {
|
||
logger.info("欺骗IP池配置下发配置参数:" + json);
|
||
}
|
||
//调用服务接口下发配置
|
||
try {
|
||
ToMaatResult result = ConfigServiceUtil.postCallbackCfg(json);
|
||
if(result!=null){
|
||
logger.info("欺骗IP池配置下发响应信息:"+result.getMsg());
|
||
}
|
||
} catch (Exception e) {
|
||
logger.error("欺骗IP池配置配置下发失败",e);
|
||
throw e;
|
||
}
|
||
}
|
||
}
|
||
/**
|
||
* 新增:修改旧的定时任务为无效(实际不需要)--》新增sche(1)用于生成新的定时任务trigger(清理旧定时任务的trigger)
|
||
* 修改:修改旧的定时任务为无效--》新增sche(1)用于生成新的定时任务trigger(清理旧定时任务的trigger)
|
||
* 审核通过:不需要操作
|
||
* 审核不通过:修改旧的定时任务为无效--》新增sche(0)用于清理旧定时任务的trigger
|
||
* 配置取消:修改旧的定时任务为无效--》新增sche(0)用于清理旧定时任务的trigger
|
||
* 删除:修改旧的定时任务为无效--》新增sche(0)用于清理旧定时任务的trigger
|
||
* @param parameterObject
|
||
* @param tableName
|
||
* @throws SQLException
|
||
*/
|
||
public void handelScheduleCfg(Object parameterObject,String tableName,BaseCfg cfg){
|
||
logger.info("handelScheduleCfg==》开始处理定时任务");
|
||
List<BaseCfg> cfgList = Lists.newArrayList();
|
||
//确保 单个,批量都适用
|
||
if(parameterObject instanceof BaseCfg<?>) {//单个添加
|
||
BaseCfg<?> baseCfg = (BaseCfg<?>)parameterObject;
|
||
cfgList.add(baseCfg);
|
||
}else if(parameterObject instanceof Collection) {
|
||
Collection<BaseCfg<?>> bcCollection = (Collection<BaseCfg<?>>)parameterObject;
|
||
cfgList.addAll(bcCollection);
|
||
}else if(parameterObject.getClass().isArray()) {
|
||
int length = Array.getLength(parameterObject);
|
||
for(int i = 0;i< length;i++) {
|
||
BaseCfg<?> baseCfg = (BaseCfg<?>)Array.get(parameterObject, i);
|
||
cfgList.add(baseCfg);
|
||
}
|
||
}
|
||
|
||
//存放需要删除的定时任务(根据compileId删除之前所有的定时任务)
|
||
String delCompileIds="";
|
||
//存放需要失效的定时任务
|
||
String inValidCompileIds="";
|
||
//存放需要新增的定时任务
|
||
List<ScheduleCfg> addScheduleList = Lists.newArrayList();
|
||
|
||
for(BaseCfg<?> baseCfg : cfgList) {
|
||
//有新的定时任务时,新增新的
|
||
if(cfg.getIsValid()==0 && cfg.getIsAudit()==0){
|
||
delCompileIds+=baseCfg.getCompileId()+",";
|
||
ScheduleCfg scheduleCfgAdd = copyScheduleCfgFromBaseCfg(baseCfg, tableName);
|
||
if(scheduleCfgAdd!=null){
|
||
scheduleCfgAdd.setIsValid(0);
|
||
scheduleCfgAdd.setIsAudit(0);
|
||
scheduleCfgAdd.setDelFlag(1);
|
||
addScheduleList.add(scheduleCfgAdd);
|
||
}
|
||
}
|
||
//需要失效的定时任务
|
||
if(cfg.getIsValid()==-1 || cfg.getIsAudit()==2 ||cfg.getIsAudit()==3){
|
||
inValidCompileIds+=baseCfg.getCompileId()+",";
|
||
}
|
||
|
||
}
|
||
|
||
//将type=2定时任务删除
|
||
if(!StringUtil.isEmpty(inValidCompileIds) || !StringUtil.isEmpty(delCompileIds) ) {
|
||
String syncDelCompileIds=delCompileIds+inValidCompileIds;
|
||
syncDelCompileIds=syncDelCompileIds.substring(0,syncDelCompileIds.length()-1);
|
||
SqlSessionFactory sqlSessionFactory=SpringContextHolder.getBean(SqlSessionFactory.class);
|
||
SqlSession batchSqlSession = null;
|
||
try {
|
||
batchSqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH, false);
|
||
((SchedulerDao) batchSqlSession.getMapper(SchedulerDao.class)).deleteByCompileIds(syncDelCompileIds,2);
|
||
batchSqlSession.commit();
|
||
} finally {
|
||
if(batchSqlSession != null) {
|
||
batchSqlSession.close();
|
||
}
|
||
}
|
||
}
|
||
|
||
//将type=1定时任务删除
|
||
if(!StringUtil.isEmpty(delCompileIds) ) {
|
||
delCompileIds=delCompileIds.substring(0,delCompileIds.length()-1);
|
||
SqlSessionFactory sqlSessionFactory=SpringContextHolder.getBean(SqlSessionFactory.class);
|
||
SqlSession batchSqlSession = null;
|
||
try {
|
||
batchSqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH, false);
|
||
((SchedulerDao) batchSqlSession.getMapper(SchedulerDao.class)).deleteByCompileIds(delCompileIds,1);
|
||
batchSqlSession.commit();
|
||
} finally {
|
||
if(batchSqlSession != null) {
|
||
batchSqlSession.close();
|
||
}
|
||
}
|
||
}
|
||
|
||
//将定时任务失效
|
||
if(!StringUtil.isEmpty(inValidCompileIds)) {
|
||
inValidCompileIds=inValidCompileIds.substring(0,inValidCompileIds.length()-1);
|
||
SqlSessionFactory sqlSessionFactory=SpringContextHolder.getBean(SqlSessionFactory.class);
|
||
SqlSession batchSqlSession = null;
|
||
try {
|
||
batchSqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH, false);
|
||
((SchedulerDao) batchSqlSession.getMapper(SchedulerDao.class)).inValidByCompileIds(inValidCompileIds);
|
||
batchSqlSession.commit();
|
||
} finally {
|
||
if(batchSqlSession != null) {
|
||
batchSqlSession.close();
|
||
}
|
||
}
|
||
}
|
||
|
||
//新增sche,用于新增新定时任务
|
||
if(!StringUtil.isEmpty(addScheduleList)) {
|
||
SqlSessionFactory sqlSessionFactory=SpringContextHolder.getBean(SqlSessionFactory.class);
|
||
SqlSession batchSqlSession = null;
|
||
try {
|
||
batchSqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH, false);
|
||
for(ScheduleCfg entity : addScheduleList) {
|
||
((SchedulerDao) batchSqlSession.getMapper(SchedulerDao.class)).insert(entity);
|
||
}
|
||
batchSqlSession.commit();
|
||
} finally {
|
||
if(batchSqlSession != null) {
|
||
batchSqlSession.close();
|
||
}
|
||
}
|
||
}
|
||
logger.info("handelScheduleCfg==》定时任务处理完成");
|
||
}
|
||
|
||
/**
|
||
* 从 basecfg 实体类中获取 schedule cfg
|
||
* @param baseCfg
|
||
* @param tableName
|
||
* @return
|
||
*/
|
||
private ScheduleCfg copyScheduleCfgFromBaseCfg(BaseCfg<?> baseCfg,String tableName){
|
||
ScheduleCfg schedule = baseCfg.getSchedule();
|
||
if(schedule != null ) {
|
||
BeanUtils.copyProperties(baseCfg, schedule,new String[]{"userRegion1","userRegion2","userRegion3","userRegion4","userRegion5"});
|
||
schedule.setTableName(tableName);
|
||
schedule.setType(1);
|
||
}
|
||
return schedule;
|
||
}
|
||
|
||
//劫持文件
|
||
public static ProxyFileHijackCfgAudit convertCallBackProxyFileHijack(ProxyFileHijackCfg cfg) {
|
||
ProxyFileHijackCfgAudit hijackTemp = new ProxyFileHijackCfgAudit();
|
||
hijackTemp.setId(Long.valueOf(cfg.getCompileId()));
|
||
hijackTemp.setCfgId(cfg.getCompileId());
|
||
hijackTemp.setProfileId(cfg.getCompileId());
|
||
hijackTemp.setContentType(cfg.getContentType());
|
||
hijackTemp.setContentName(keywordsEscape(cfg.getContentName()));
|
||
hijackTemp.setProfileName(keywordsEscape(cfg.getCfgDesc()));
|
||
hijackTemp.setPath(cfg.getPath());
|
||
hijackTemp.setAction(cfg.getAction());
|
||
hijackTemp.setService(cfg.getServiceId());
|
||
hijackTemp.setIsValid(cfg.getIsValid());
|
||
hijackTemp.setOpTime(cfg.getAuditTime());
|
||
hijackTemp.setOpUser(UserUtils.getUser().getId());
|
||
return hijackTemp;
|
||
}
|
||
//注入脚本文件
|
||
public static ProxyFileInsertScriptCfgAudit convertCallBackProxyFileInsertScript(ProxyFileInsertScriptCfg cfg) {
|
||
ProxyFileInsertScriptCfgAudit fileInsertScriptTemp = new ProxyFileInsertScriptCfgAudit();
|
||
fileInsertScriptTemp.setId(Long.valueOf(cfg.getCompileId()));
|
||
fileInsertScriptTemp.setCfgId(cfg.getCompileId());
|
||
fileInsertScriptTemp.setProfileId(cfg.getCompileId());
|
||
fileInsertScriptTemp.setFormat(cfg.getFormat());
|
||
fileInsertScriptTemp.setProfileName(keywordsEscape(cfg.getCfgDesc()));
|
||
fileInsertScriptTemp.setPath(cfg.getPath());
|
||
fileInsertScriptTemp.setAction(cfg.getAction());
|
||
fileInsertScriptTemp.setService(cfg.getServiceId());
|
||
fileInsertScriptTemp.setIsValid(cfg.getIsValid());
|
||
fileInsertScriptTemp.setOpTime(cfg.getAuditTime());
|
||
fileInsertScriptTemp.setOpUser(UserUtils.getUser().getId());
|
||
return fileInsertScriptTemp;
|
||
}
|
||
//流量转发目的地址
|
||
public static ProxyFileTrafficMirrorCfgAudit convertCallBackProxyFileTrafficMirror(ProxyFileTrafficMirrorCfg cfg) {
|
||
ProxyFileTrafficMirrorCfgAudit fileTemp = new ProxyFileTrafficMirrorCfgAudit();
|
||
Map map = new HashMap<String,List<String>>();
|
||
map.put(cfg.getAddrType(),Arrays.asList(cfg.getAddrList().split(",")));
|
||
fileTemp.setId(Long.valueOf(cfg.getCompileId()));
|
||
fileTemp.setCfgId(cfg.getCompileId());
|
||
fileTemp.setProfileId(cfg.getCompileId());
|
||
fileTemp.setProfileName(keywordsEscape(cfg.getCfgDesc()));
|
||
fileTemp.setAddrList(gsonToJson(map));
|
||
fileTemp.setAddrContent(cfg.getAddrList());
|
||
fileTemp.setAddrType(cfg.getAddrType());
|
||
fileTemp.setAction(cfg.getAction());
|
||
fileTemp.setService(cfg.getServiceId());
|
||
fileTemp.setIsValid(cfg.getIsValid());
|
||
fileTemp.setOpTime(cfg.getAuditTime());
|
||
fileTemp.setOpUser(UserUtils.getUser().getId());
|
||
return fileTemp;
|
||
}
|
||
//文件策略
|
||
public static ProxyFileStrategyCfgAudit convertCallBackProxyFileStrategy(ProxyFileStrategyCfg cfg) {
|
||
ProxyFileStrategyCfgAudit fileTemp = new ProxyFileStrategyCfgAudit();
|
||
fileTemp.setId(Long.valueOf(cfg.getCompileId()));
|
||
fileTemp.setCfgId(cfg.getCompileId());
|
||
fileTemp.setFileId(Long.valueOf(cfg.getCompileId()));
|
||
fileTemp.setFileDesc(keywordsEscape(cfg.getFileDesc()));
|
||
fileTemp.setContentType(cfg.getContentType());
|
||
fileTemp.setContentLength(cfg.getContentLength());
|
||
fileTemp.setAction(cfg.getAction());
|
||
fileTemp.setService(cfg.getServiceId());
|
||
fileTemp.setFilePath(cfg.getUrl());
|
||
fileTemp.setIsValid(cfg.getIsValid());
|
||
fileTemp.setOpTime(cfg.getAuditTime());
|
||
fileTemp.setOpUser(UserUtils.getUser().getId());
|
||
return fileTemp;
|
||
}
|
||
//访问阻断页面
|
||
public static ProxyFileResponsePageCfgAudit convertCallBackProxyFileResponsePage(ProxyFileResponsePageCfg cfg) {
|
||
ProxyFileResponsePageCfgAudit fileTemp = new ProxyFileResponsePageCfgAudit();
|
||
fileTemp.setId(Long.valueOf(cfg.getCompileId()));
|
||
fileTemp.setCfgId(cfg.getCompileId());
|
||
fileTemp.setProfileId((Long.valueOf(cfg.getCompileId())));
|
||
fileTemp.setProfileName(keywordsEscape(cfg.getFileDesc()));
|
||
fileTemp.setFormat(cfg.getContentType());
|
||
fileTemp.setContentLength(cfg.getContentLength());
|
||
fileTemp.setAction(cfg.getAction());
|
||
fileTemp.setService(cfg.getServiceId());
|
||
fileTemp.setPath(cfg.getUrl());
|
||
fileTemp.setIsValid(cfg.getIsValid());
|
||
fileTemp.setOpTime(cfg.getAuditTime());
|
||
fileTemp.setOpUser(UserUtils.getUser().getId());
|
||
return fileTemp;
|
||
}
|
||
|
||
// Proxy Manipulate
|
||
public static String setUserRegionOfMantipulateCfg(CfgIndexInfo cfg, String userRegion) {
|
||
|
||
ManipulatActionParam actionParam = new ManipulatActionParam();
|
||
if(cfg.getUserRegion5().equals("48")) {
|
||
actionParam.setMethod("redirect");
|
||
actionParam.setCode(Integer.valueOf(cfg.getUserRegion1()));
|
||
actionParam.setTo(cfg.getUserRegion2());
|
||
}else if(cfg.getUserRegion5().equals("80")) {
|
||
List<ReplaceCfg> ReplaceCfgList = new ArrayList();
|
||
ReplaceCfg replaceCfg = new ReplaceCfg();
|
||
replaceCfg.setSearch_in(cfg.getUserRegion1());
|
||
replaceCfg.setFind(cfg.getUserRegion2());
|
||
replaceCfg.setReplace_with(cfg.getUserRegion3());
|
||
ReplaceCfgList.add(replaceCfg);
|
||
actionParam.setMethod("replace");
|
||
actionParam.setRules(ReplaceCfgList);
|
||
}else if(cfg.getUserRegion5().equals("85")) {
|
||
actionParam.setMethod("hijack");
|
||
actionParam.setHijack_profile(Integer.valueOf(cfg.getUserRegion4()));
|
||
}else if(cfg.getUserRegion5().equals("90")) {
|
||
actionParam.setMethod("insert");
|
||
actionParam.setInsert_profile(Integer.valueOf(cfg.getUserRegion4()));
|
||
}
|
||
userRegion = gsonToJson(actionParam);
|
||
return StringEscapeUtils.unescapeJson(userRegion);
|
||
}
|
||
|
||
/**
|
||
*只会更新maat配置,公共分组删除时会取消配置
|
||
* 调用场景(1)公共分组域增加(3)公共分组修改(2)公共分组域删除(3)公共分组删除
|
||
* @param policyGroupInfos
|
||
|
||
* @return
|
||
*/
|
||
public boolean transObjGroupToMaat(List<PolicyGroupInfo> policyGroupInfos){
|
||
IpCommGroupCfgDao ipCommGroupCfgDao=SpringContextHolder.getBean(IpCommGroupCfgDao.class);
|
||
UrlCommGroupDao urlCommGroupCfgDao=SpringContextHolder.getBean(UrlCommGroupDao.class);
|
||
ScriberIdCommGroupDao scriberIdCommGroupDao=SpringContextHolder.getBean(ScriberIdCommGroupDao.class);
|
||
DomainCommGroupDao domainCommGroupDao=SpringContextHolder.getBean(DomainCommGroupDao.class);
|
||
CommonPolicyDao commonPolicyDao=SpringContextHolder.getBean(CommonPolicyDao.class);
|
||
AreaIpCfgDao areaIpCfgDao=SpringContextHolder.getBean(AreaIpCfgDao.class);
|
||
Set<String> ipDeletedGroups=new HashSet<>();
|
||
Set<String> urlDeletedGroups=new HashSet<>();
|
||
Set<String> subIdDeletedGroups=new HashSet<>();
|
||
Set<String> domainDeletedGroups=new HashSet<>();
|
||
//遍历,获取需要下发配置的组
|
||
StringBuffer realGroupIds=new StringBuffer();
|
||
for(PolicyGroupInfo policyGroupInfo:policyGroupInfos){
|
||
/*
|
||
UdFlag=0时,为组新建或者域全部删除,域全部删除时需要清空cfg_index_info与policy_group_info的关系,如果cfg_index_info已经下发,则需要更新配置去除这个组,如果是cfg_index_info中最后一个组,取消maat配置
|
||
UdFlag=1时,组中有可选配置,obj-group-policy界面中组处于可选状态,该方法应不做任何处理
|
||
UdFlag=2时,组跟配置有明确关联,新增组下的域配置时,如果该配置未下发过,则不用处理,如果有下发过,则需下发最新的域。
|
||
*/
|
||
|
||
if(!policyGroupInfo.getUdFlag().equals(1)){
|
||
realGroupIds.append(policyGroupInfo.getServiceGroupId()).append(",");
|
||
}
|
||
//realGroupIds中包含ipDeletedGroups,urlDeletedGroups,subIdDeletedGroups,domainDeletedGroups
|
||
if(policyGroupInfo.getUdFlag().equals(0)){//所有域都删除的时候或者新建组的时候
|
||
if(policyGroupInfo.getGroupType().equals(Constants.IP_OBJ_GROUP_TYPE)){
|
||
ipDeletedGroups.add(policyGroupInfo.getServiceGroupId().toString());
|
||
}
|
||
if(policyGroupInfo.getGroupType().equals(Constants.URL_OBJ_GROUP_TYPE)){
|
||
urlDeletedGroups.add(policyGroupInfo.getServiceGroupId().toString());
|
||
}
|
||
if(policyGroupInfo.getGroupType().equals(Constants.SUBID_OBJ_GROUP_TYPE)){
|
||
subIdDeletedGroups.add(policyGroupInfo.getServiceGroupId().toString());
|
||
}
|
||
if(policyGroupInfo.getGroupType().equals(Constants.DOMAIN_OBJ_GROUP_TYPE)){
|
||
domainDeletedGroups.add(policyGroupInfo.getServiceGroupId().toString());
|
||
}
|
||
}
|
||
}
|
||
if(realGroupIds.toString().endsWith(",")){
|
||
realGroupIds.deleteCharAt(realGroupIds.toString().length()-1);
|
||
}
|
||
List<CfgIndexInfo> toUpdateCfgIndexInfos=new ArrayList<>();
|
||
List<CfgIndexInfo> toCancelCfgIndexInfos=new ArrayList<>();
|
||
//没有
|
||
if(StringUtils.isBlank(realGroupIds.toString())){
|
||
return true;
|
||
}
|
||
//查询cfg_index_info表,获取所有用到了这个group_id的非删除配置
|
||
List<CfgIndexInfo> cfgIndexInfos=commonPolicyDao.getObjGroupListByGroupIds(realGroupIds.toString(),null,null);
|
||
|
||
List compileIds=new ArrayList();
|
||
//组织一个大的json
|
||
ToMaatBean maatBean = new ToMaatBean();
|
||
ToMaatBean cancelMaatBean = new ToMaatBean();
|
||
ServiceConfigTemplateUtil templateUtil=new ServiceConfigTemplateUtil();
|
||
Map<String,Object> interceptUserRegionMap=new HashMap<>();
|
||
Map<Integer,FunctionServiceDict> serviceDictMap=cfgIndexInfos.size()>0?ConfigConvertUtil.objGetServiceDict(cfgIndexInfos.get(0).getFunctionId()):new HashMap<Integer, FunctionServiceDict>();
|
||
for(CfgIndexInfo cfgIndexInfo:cfgIndexInfos){
|
||
Integer serviceId=cfgIndexInfo.getServiceId();
|
||
if(serviceId!=null&&StringUtils.isNotBlank(cfgIndexInfo.getCommonGroupIds())){
|
||
MaatCfg maatCfg = new MaatCfg();
|
||
Set<Integer> groupIdSet=new HashSet<>();
|
||
List<MaatCfg> configCompileList = new ArrayList();
|
||
List<MaatCfg> cancelConfigCompileList = new ArrayList();
|
||
List<GroupCfg> groupRelationList = new ArrayList();
|
||
List<IpCfg> ipRegionList = new ArrayList();
|
||
List<StringCfg> strRegionList = new ArrayList();
|
||
List<NumBoundaryCfg> numRegionList = new ArrayList();
|
||
List<DigestCfg> digestRegionList = new ArrayList();
|
||
List<IpCfg> areaIpRegionList = new ArrayList();
|
||
Map<String,Object> userRgionMap=gsonFromJson(cfgIndexInfo.getCommonGroupIds(),Map.class);
|
||
cfgIndexInfo.setUserRegion(userRgionMap);
|
||
String oldCommonGroupIds=cfgIndexInfo.getCommonGroupIds();
|
||
//将所有要从配置中删除的组从配置中删除
|
||
this.processUserRegionMap(userRgionMap,"ipGroup",ipDeletedGroups,cfgIndexInfo,ipCommGroupCfgDao,IpCommCfg.class);
|
||
this.processUserRegionMap(userRgionMap,"urlGroup",urlDeletedGroups,cfgIndexInfo,urlCommGroupCfgDao,UrlCommCfg.class);
|
||
this.processUserRegionMap(userRgionMap,"subscribeIdGroup",subIdDeletedGroups,cfgIndexInfo,scriberIdCommGroupDao,ScriberIdCommCfg.class);
|
||
this.processUserRegionMap(userRgionMap,"domainGroup",domainDeletedGroups,cfgIndexInfo,domainCommGroupDao,DomainCommCfg.class);
|
||
|
||
//需要更新的组,组可能增加了,可能减少了,也有可能清空了(所有的域全删了)
|
||
cfgIndexInfo.setCommonGroupIds(gsonToJson(userRgionMap));
|
||
if(MapUtils.isEmpty(userRgionMap)){//组清空了
|
||
cfgIndexInfo.setCommonGroupIds("");
|
||
if(cfgIndexInfo.getIsValid()==Constants.VALID_NO){//未生效,直接更新配置,不用下发
|
||
toUpdateCfgIndexInfos.add(cfgIndexInfo);
|
||
}else{//生效,需要取消配置
|
||
cfgIndexInfo.setIsValid(Constants.VALID_NO);
|
||
cfgIndexInfo.setIsAudit(Constants.AUDIT_NOT_YES);
|
||
toCancelCfgIndexInfos.add(cfgIndexInfo);
|
||
}
|
||
}else if(!oldCommonGroupIds.equals(cfgIndexInfo.getCommonGroupIds())){//组有变化
|
||
toUpdateCfgIndexInfos.add(cfgIndexInfo);
|
||
//commonPolicyDao.updateCfgIndexCommonGroupIds(cfgIndexInfo);
|
||
}
|
||
|
||
if(cfgIndexInfo.getIsValid().equals(Constants.VALID_YES)){//生效配置
|
||
//没组了,取消配置,没域了,取消配置
|
||
if(userRgionMap.isEmpty()){
|
||
maatCfg.setCompileId(cfgIndexInfo.getCompileId());
|
||
maatCfg.setServiceId(cfgIndexInfo.getServiceId());
|
||
maatCfg.setIsValid(0);//无效
|
||
cancelConfigCompileList.add(maatCfg);
|
||
}else{//有组,重新下发配置
|
||
//保存区域IP信息
|
||
List<AreaIpCfg> areaIpCfgList=areaIpCfgDao.getByCompileId(cfgIndexInfo.getCompileId());
|
||
if(!StringUtil.isEmpty(areaIpCfgList)){
|
||
AreaIpCfg cfg = new AreaIpCfg();
|
||
BeanUtils.copyProperties(cfgIndexInfo, cfg, new String[]{"cfgId"});
|
||
cfg.setTableName(AreaIpCfg.getTablename());
|
||
commonPolicyDao.auditCfg(cfg);
|
||
|
||
Map<String,List> map = cfgConvert(areaIpRegionList,areaIpCfgList,1,cfgIndexInfo,groupRelationList);
|
||
groupRelationList=map.get("groupList");
|
||
areaIpRegionList=map.get("dstList");
|
||
}
|
||
|
||
Map<String,Object> maatTableMap=new HashMap<>();
|
||
StringBuffer userRegion=new StringBuffer();
|
||
List<Map<String,Object>> list= templateUtil.getServiceListByServiceId(serviceId);
|
||
//获取业务下的配置域
|
||
List<Map<String,Object>> cfgList = new ArrayList<>();
|
||
//获取业务下的自定义域
|
||
List<Map<String,Object>> userRegionList = new ArrayList<>();
|
||
for(Map<String,Object> service:list){
|
||
String serviceType = service.get("serviceType").toString();
|
||
//主表上有maatTable的一般是app的表
|
||
// if(service.containsKey("maatTable")){ }
|
||
if(service.containsKey("cfgList")) {
|
||
cfgList=(List<Map<String, Object>>) service.get("cfgList");
|
||
maatTableMap=ConfigConvertUtil.convertCommonGroupMaatTable(cfgIndexInfo,cfgList);
|
||
}
|
||
if(service.containsKey("userRegionList")){
|
||
//Map<String,Object> userregionMap=new HashMap<>();
|
||
//userRegionList=(List<Map<String, Object>>) service.get("userRegionList");
|
||
String _userregion=ConfigConvertUtil.generateCommonGroupDefaultUserRegion(interceptUserRegionMap,serviceId);
|
||
userRegion.append(_userregion);
|
||
}
|
||
}
|
||
compileIds.add(cfgIndexInfo.getCompileId());
|
||
//子表
|
||
//IP公共分组
|
||
if(CollectionUtils.isNotEmpty(cfgIndexInfo.getIpCommGroupCfgList())){
|
||
IpPortCfg cfg = new IpPortCfg();
|
||
BeanUtils.copyProperties(cfgIndexInfo, cfg, new String[]{"cfgId"});
|
||
Map<String,List> map = ConfigConvertUtil.objGroupCfgConvert(serviceDictMap,ipRegionList,cfgIndexInfo.getIpCommGroupCfgList(),1,cfgIndexInfo,groupRelationList,maatTableMap,groupIdSet);
|
||
groupRelationList=map.get("groupList");
|
||
ipRegionList=map.get("dstList");
|
||
if(map.get("numRegionList")!=null){
|
||
numRegionList.addAll(map.get("numRegionList"));
|
||
}
|
||
|
||
}
|
||
//URL公共分组
|
||
if(CollectionUtils.isNotEmpty(cfgIndexInfo.getUrlCommGroupList())){
|
||
CommonStringCfg cfg = new CommonStringCfg();
|
||
BeanUtils.copyProperties(cfgIndexInfo, cfg, new String[]{"cfgId"});
|
||
Map<String,List> map =ConfigConvertUtil.objGroupCfgConvert(serviceDictMap,strRegionList,cfgIndexInfo.getUrlCommGroupList(),2,cfgIndexInfo,groupRelationList,maatTableMap,groupIdSet);
|
||
groupRelationList=map.get("groupList");
|
||
strRegionList=map.get("dstList");
|
||
}
|
||
//账号公共分组
|
||
if(CollectionUtils.isNotEmpty(cfgIndexInfo.getScriberIdCommGroupList())){
|
||
CommonStringCfg cfg = new CommonStringCfg();
|
||
BeanUtils.copyProperties(cfgIndexInfo, cfg, new String[]{"cfgId"});
|
||
|
||
Map<String,List> map =ConfigConvertUtil.objGroupCfgConvert(serviceDictMap,strRegionList,cfgIndexInfo.getScriberIdCommGroupList(),2,cfgIndexInfo,groupRelationList,maatTableMap,groupIdSet);
|
||
groupRelationList=map.get("groupList");
|
||
strRegionList=map.get("dstList");
|
||
|
||
}
|
||
//域名公共分组
|
||
if(CollectionUtils.isNotEmpty(cfgIndexInfo.getDomainCommGroupList())){
|
||
CommonStringCfg cfg = new CommonStringCfg();
|
||
BeanUtils.copyProperties(cfgIndexInfo, cfg, new String[]{"cfgId"});
|
||
|
||
Map<String,List> map =ConfigConvertUtil.objGroupCfgConvert(serviceDictMap,strRegionList,cfgIndexInfo.getDomainCommGroupList(),2,cfgIndexInfo,groupRelationList,maatTableMap,groupIdSet);
|
||
groupRelationList=map.get("groupList");
|
||
strRegionList=map.get("dstList");
|
||
|
||
}
|
||
//构造提交综合服务参数格式
|
||
maatCfg.initDefaultValue();
|
||
BeanUtils.copyProperties(cfgIndexInfo, maatCfg);
|
||
if(cfgIndexInfo.getServiceId().equals(512)){
|
||
maatCfg.setAction(2);
|
||
}else{
|
||
maatCfg.setAction(cfgIndexInfo.getAction());
|
||
}
|
||
maatCfg.setAuditTime(cfgIndexInfo.getAuditTime());
|
||
maatCfg.setIpRegionList(ipRegionList);
|
||
maatCfg.setStrRegionList(strRegionList);
|
||
maatCfg.setNumRegionList(numRegionList);
|
||
maatCfg.setDigestRegionList(digestRegionList);
|
||
maatCfg.setGroupRelationList(groupRelationList);
|
||
maatCfg.setGroupNum(groupRelationList.size());
|
||
maatCfg.setAreaIpRegionList(areaIpRegionList);
|
||
maatCfg.setIsValid(Constants.VALID_YES);
|
||
//设置用户自定义域
|
||
String protpcolType=cfgIndexInfo.getUserRegion1();
|
||
|
||
if("HTTPS".equalsIgnoreCase(protpcolType)||"INTERCEPT".equalsIgnoreCase(protpcolType)){
|
||
if(StringUtils.isBlank(userRegion.toString())){
|
||
userRegion.append("{}");
|
||
}
|
||
}else if("HTTP".equalsIgnoreCase(protpcolType)){
|
||
}
|
||
maatCfg.setUserRegion(userRegion.toString());
|
||
|
||
configCompileList.add(maatCfg);
|
||
}
|
||
if(configCompileList.size()>0&&CollectionUtils.isEmpty(maatBean.getConfigCompileList())){
|
||
maatBean.setConfigCompileList(configCompileList);
|
||
maatBean.setAuditTime(cfgIndexInfo.getAuditTime());
|
||
maatBean.setCreatorName(cfgIndexInfo.getCurrentUser().getName());
|
||
maatBean.setVersion(Constants.MAAT_VERSION);
|
||
maatBean.setOpAction(Constants.UPDATE_ACTION);
|
||
}
|
||
}else if(userRgionMap.isEmpty()&&cfgIndexInfo.getIsValid().equals(Constants.VALID_NO)&&cfgIndexInfo.getIsAudit().equals(Constants.AUDIT_NOT_YES)){//生效的配置,组清空了,在方法已经将属性只为无效,生成取消配置maat
|
||
maatCfg.setCompileId(cfgIndexInfo.getCompileId());
|
||
maatCfg.setServiceId(cfgIndexInfo.getServiceId());
|
||
maatCfg.setIsValid(0);//无效
|
||
cancelConfigCompileList.add(maatCfg);
|
||
}
|
||
if(cancelConfigCompileList.size()>0&&CollectionUtils.isEmpty(cancelMaatBean.getConfigCompileList())){
|
||
cancelMaatBean.setConfigCompileList(cancelConfigCompileList);
|
||
cancelMaatBean.setAuditTime(cfgIndexInfo.getAuditTime());
|
||
cancelMaatBean.setCreatorName(cfgIndexInfo.getCurrentUser().getName());
|
||
cancelMaatBean.setVersion(Constants.MAAT_VERSION);
|
||
cancelMaatBean.setOpAction(Constants.UPDATE_ACTION);
|
||
}
|
||
//下发maat配置
|
||
//auditPolicy(cfgIndexInfo,cfgIndexInfo.getIsAudit(),Constants.UPDATE_ACTION);
|
||
}
|
||
}
|
||
//需要更新的cfg_index_info数据库更新
|
||
if(toCancelCfgIndexInfos.size()>0){
|
||
StringBuffer ids=new StringBuffer();
|
||
for(CfgIndexInfo info:toCancelCfgIndexInfos){
|
||
commonPolicyDao.updateCfgIndexCommonGroupIds(info);
|
||
if(StringUtils.isBlank(info.getCommonGroupIds())){
|
||
ids.append(info.getCompileId()+",");
|
||
}
|
||
}
|
||
//查询定时任务,失效定时任务
|
||
// if(ids.toString().length()>0){
|
||
// ids.deleteCharAt(ids.toString().length()-1);
|
||
// commonPolicyDao.cancelScheduCfg(ids.toString(),CfgIndexInfo.getTablename());
|
||
// }
|
||
}
|
||
if(toUpdateCfgIndexInfos.size()>0){
|
||
StringBuffer ids=new StringBuffer();
|
||
for(CfgIndexInfo info:toUpdateCfgIndexInfos){
|
||
commonPolicyDao.updateCfgIndexCommonGroupIds(info);
|
||
if(StringUtils.isBlank(info.getCommonGroupIds())){
|
||
ids.append(info.getCompileId()+",");
|
||
}
|
||
}
|
||
//查询定时任务,失效定时任务
|
||
if(ids.toString().length()>0){
|
||
ids.deleteCharAt(ids.toString().length()-1);
|
||
commonPolicyDao.cancelScheduCfg(ids.toString(),CfgIndexInfo.getTablename());
|
||
}
|
||
}
|
||
//向maat发送配置
|
||
if(CollectionUtils.isNotEmpty(cancelMaatBean.getConfigCompileList())){
|
||
//调用服务接口下发配置数据
|
||
String json=gsonToJson(cancelMaatBean);
|
||
logger.info("策略对象组取消配置参数:"+json);
|
||
//调用服务接口下发配置
|
||
ToMaatResult result = ConfigServiceUtil.put(json,1);
|
||
logger.info("策略对象组取消响应信息:"+result.getMsg());
|
||
}
|
||
//向maat发送配置
|
||
if(CollectionUtils.isNotEmpty(maatBean.getConfigCompileList())){
|
||
//调用服务接口下发配置数据
|
||
String json=gsonToJson(maatBean);
|
||
logger.info("策略对象组下发配置参数:"+json);
|
||
//调用服务接口下发配置
|
||
ToMaatResult result = ConfigServiceUtil.postMaatCfg(json);
|
||
logger.info("策略对象组下发响应信息:"+result.getMsg());
|
||
}
|
||
//commonPolicyDao.auditCfgBatch(CfgIndexInfo.getTablename(),auditCfg,compileIds,null);
|
||
return true;
|
||
}
|
||
private void processUserRegionMap(Map<String,Object> userRgionMap, String key, Set deletedGroups, CfgIndexInfo cfgIndexInfo, CrudDao dao,Class clazz) {
|
||
if(userRgionMap.containsKey(key)){
|
||
//排除删除的组,添加新的组
|
||
for(String urlGroup:((String)userRgionMap.get(key)).split(",")){
|
||
if(deletedGroups.contains(urlGroup)){
|
||
userRgionMap.put(key,((String) userRgionMap.get(key)).replace(","+urlGroup+",",","));
|
||
}
|
||
}
|
||
boolean contains=true;
|
||
//空了
|
||
if(userRgionMap.get(key).toString().equals(",")){
|
||
userRgionMap.remove(key);
|
||
contains=false;
|
||
}
|
||
if(contains&&cfgIndexInfo.getIsValid()==Constants.VALID_YES){
|
||
if("IpCommCfg".equals(clazz.getSimpleName())){
|
||
IpCommCfg searchCfg=new IpCommCfg();
|
||
searchCfg.setCommonGroupIds(userRgionMap.get(key).toString().substring(1,userRgionMap.get(key).toString().length()-1));
|
||
List commCfgs=dao.findAllList(searchCfg);
|
||
if(CollectionUtils.isNotEmpty(commCfgs)){
|
||
cfgIndexInfo.setIpCommGroupCfgList(commCfgs);
|
||
}
|
||
}else if("ScriberIdCommCfg".equals(clazz.getSimpleName()) ){
|
||
ScriberIdCommCfg searchCfg=new ScriberIdCommCfg();
|
||
searchCfg.setCommonGroupIds(userRgionMap.get(key).toString().substring(1,userRgionMap.get(key).toString().length()-1));
|
||
List commCfgs=dao.findAllList(searchCfg);
|
||
if(CollectionUtils.isNotEmpty(commCfgs)){
|
||
cfgIndexInfo.setScriberIdCommGroupList(commCfgs);
|
||
}
|
||
}else if("UrlCommCfg".equals(clazz.getSimpleName())){
|
||
UrlCommCfg searchCfg=new UrlCommCfg();
|
||
searchCfg.setCommonGroupIds(userRgionMap.get(key).toString().substring(1,userRgionMap.get(key).toString().length()-1));
|
||
List commCfgs=dao.findAllList(searchCfg);
|
||
if(CollectionUtils.isNotEmpty(commCfgs)){
|
||
cfgIndexInfo.setUrlCommGroupList(commCfgs);
|
||
}
|
||
}else if("DomainCommCfg".equals(clazz.getSimpleName())){
|
||
DomainCommCfg searchCfg=new DomainCommCfg();
|
||
searchCfg.setCommonGroupIds(userRgionMap.get(key).toString().substring(1,userRgionMap.get(key).toString().length()-1));
|
||
List commCfgs=dao.findAllList(searchCfg);
|
||
if(CollectionUtils.isNotEmpty(commCfgs)){
|
||
cfgIndexInfo.setDomainCommGroupList(commCfgs);
|
||
}
|
||
}
|
||
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|