2017-12-29 16:18:40 +08:00
|
|
|
|
package com.nis.web.service;
|
|
|
|
|
|
|
2018-05-23 13:15:57 +08:00
|
|
|
|
import java.lang.reflect.Type;
|
|
|
|
|
|
import java.text.SimpleDateFormat;
|
2018-05-29 12:48:27 +08:00
|
|
|
|
import java.util.ArrayList;
|
2018-05-23 13:15:57 +08:00
|
|
|
|
import java.util.Date;
|
2018-05-29 12:48:27 +08:00
|
|
|
|
import java.util.HashMap;
|
2017-12-29 16:18:40 +08:00
|
|
|
|
import java.util.List;
|
2018-05-29 12:48:27 +08:00
|
|
|
|
import java.util.Map;
|
2017-12-29 16:18:40 +08:00
|
|
|
|
|
|
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
|
|
import org.slf4j.LoggerFactory;
|
2018-05-29 12:48:27 +08:00
|
|
|
|
import org.springframework.beans.BeanUtils;
|
2017-12-29 16:18:40 +08:00
|
|
|
|
|
|
|
|
|
|
import com.google.common.collect.Lists;
|
2018-05-23 13:15:57 +08:00
|
|
|
|
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;
|
2018-05-30 15:12:11 +08:00
|
|
|
|
import com.googlecode.ipv6.IPv6Address;
|
|
|
|
|
|
import com.googlecode.ipv6.IPv6Network;
|
2017-12-29 16:18:40 +08:00
|
|
|
|
import com.nis.domain.SysRole;
|
|
|
|
|
|
import com.nis.domain.SysUser;
|
2018-06-05 17:28:45 +08:00
|
|
|
|
import com.nis.domain.callback.InlineIp;
|
2018-06-04 10:04:28 +08:00
|
|
|
|
import com.nis.domain.configuration.AreaBean;
|
|
|
|
|
|
import com.nis.domain.configuration.AreaIpCfg;
|
2018-05-29 12:48:27 +08:00
|
|
|
|
import com.nis.domain.configuration.BaseCfg;
|
|
|
|
|
|
import com.nis.domain.configuration.BaseIpCfg;
|
|
|
|
|
|
import com.nis.domain.configuration.BaseStringCfg;
|
|
|
|
|
|
import com.nis.domain.configuration.ComplexkeywordCfg;
|
|
|
|
|
|
import com.nis.domain.configuration.HttpBodyCfg;
|
|
|
|
|
|
import com.nis.domain.configuration.IpPortCfg;
|
|
|
|
|
|
import com.nis.domain.maat.MaatCfg.GroupCfg;
|
|
|
|
|
|
import com.nis.domain.maat.MaatCfg.IpCfg;
|
|
|
|
|
|
import com.nis.domain.maat.MaatCfg.NumBoundaryCfg;
|
|
|
|
|
|
import com.nis.domain.maat.MaatCfg.StringCfg;
|
|
|
|
|
|
import com.nis.util.ConfigServiceUtil;
|
2018-02-23 09:54:28 +08:00
|
|
|
|
import com.nis.util.Configurations;
|
2018-06-04 10:04:28 +08:00
|
|
|
|
import com.nis.util.Constants;
|
2018-05-29 12:48:27 +08:00
|
|
|
|
import com.nis.util.IpUtil;
|
2017-12-29 16:18:40 +08:00
|
|
|
|
import com.nis.util.StringUtils;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 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)){
|
|
|
|
|
|
|
2018-05-21 17:21:21 +08:00
|
|
|
|
sqlString.append(createScopeSql(r.getDataScope(),oa,user,null));
|
2017-12-29 16:18:40 +08:00
|
|
|
|
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 "";
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-05-21 17:21:21 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 数据范围过滤
|
|
|
|
|
|
* @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{
|
2018-06-05 18:25:40 +08:00
|
|
|
|
// 如果包含全部权限,则去掉之前添加的所有条件但增加配置审核取消以及删除的配置,并跳出循环。
|
2018-05-21 17:21:21 +08:00
|
|
|
|
sqlString = new StringBuilder();
|
2018-06-05 18:25:40 +08:00
|
|
|
|
sqlString.append(" OR " + configAlias + ".is_audit !=3");
|
2018-05-21 17:21:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if (StringUtils.isNotBlank(sqlString.toString())){
|
|
|
|
|
|
return " AND (" + sqlString.substring(4) + ")";
|
|
|
|
|
|
}
|
|
|
|
|
|
return "";
|
|
|
|
|
|
}
|
2017-12-29 16:18:40 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 测试数据是否包含全集
|
|
|
|
|
|
* @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;
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 过滤机构信息
|
2018-05-21 17:21:21 +08:00
|
|
|
|
* @param dataScope 数据范围(1:所有数据;2:所在公司及以下数据;3:所在公司数据;
|
|
|
|
|
|
* 4:所在部门及以下数据;5:所在部门数据;6:所在单位及以下数据;7:所在单位数据;
|
|
|
|
|
|
* 8:操作员数据;9:审核员数据,10:审计员数据)
|
2017-12-29 16:18:40 +08:00
|
|
|
|
* @return
|
|
|
|
|
|
*/
|
2018-05-21 17:21:21 +08:00
|
|
|
|
private static String createScopeSql(int dataScope,String officeAlias,SysUser user,String configAlias) {
|
2017-12-29 16:18:40 +08:00
|
|
|
|
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)");
|
|
|
|
|
|
|
2018-05-21 17:21:21 +08:00
|
|
|
|
}else if (SysRole.DATA_SCOPE_CREATOR.equals(dataScope)){
|
|
|
|
|
|
scopeSql.append(" OR " + configAlias + ".is_audit !=3");
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (SysRole.DATA_SCOPE_AUDITOR.equals(dataScope)){
|
|
|
|
|
|
scopeSql.append(" OR " + configAlias + ".is_audit = 0 and " + configAlias + ".is_valid = 0");
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (SysRole.DATA_SCOPE_SHOWER.equals(dataScope)){
|
|
|
|
|
|
scopeSql.append(" OR " + configAlias + ".is_audit = 1");
|
2017-12-29 16:18:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return scopeSql.toString();
|
|
|
|
|
|
}
|
2018-02-23 09:54:28 +08:00
|
|
|
|
/**
|
|
|
|
|
|
*
|
|
|
|
|
|
* getTableName(获取表名对应的Class)
|
|
|
|
|
|
* (这里描述这个方法适用条件 – 可选)
|
|
|
|
|
|
* @param clazz
|
|
|
|
|
|
* @return
|
|
|
|
|
|
*String
|
|
|
|
|
|
* @exception
|
|
|
|
|
|
* @since 1.0.0
|
|
|
|
|
|
*/
|
|
|
|
|
|
public String getClassName(String tableName){
|
|
|
|
|
|
return Configurations.getStringProperty(tableName, null);
|
|
|
|
|
|
}
|
2017-12-29 16:18:40 +08:00
|
|
|
|
|
|
|
|
|
|
|
2018-05-23 13:15:57 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 转换成字符串
|
|
|
|
|
|
* @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'T'HH:mm:ss.SSS";
|
|
|
|
|
|
long time= ((Date) src).getTime()-8*60*60*1000;
|
|
|
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat(format);
|
|
|
|
|
|
return new JsonPrimitive(sdf.format(time));
|
|
|
|
|
|
}
|
|
|
|
|
|
}).create();
|
|
|
|
|
|
return gson.toJson(obj);
|
|
|
|
|
|
}
|
2018-05-29 12:48:27 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 界面配置list转换为服务接口端的list
|
|
|
|
|
|
* @param dstList
|
|
|
|
|
|
* @param srcList
|
|
|
|
|
|
* @param cfgType,1为IP类型,2为字符串类型,3为增强字符串,4数值类型,5摘要类,6回调类[但字符串类域配置和增强字符串域配置在接口参数中同属于strRegionList]
|
2018-05-29 14:59:40 +08:00
|
|
|
|
* @param baseCfg,配置基本信息
|
|
|
|
|
|
* @param groupRelationList 配置分组列表
|
2018-05-29 12:48:27 +08:00
|
|
|
|
* @return
|
|
|
|
|
|
*/
|
|
|
|
|
|
public static Map<String,List> cfgConvert(List dstList,List srcList,Integer cfgType,BaseCfg baseCfg,List groupRelationList){
|
|
|
|
|
|
Map<String,List> map = new HashMap();
|
2018-05-31 17:07:26 +08:00
|
|
|
|
String regionValue = null;
|
2018-05-29 12:48:27 +08:00
|
|
|
|
if(cfgType==1){
|
|
|
|
|
|
List numRegionList = new ArrayList();
|
|
|
|
|
|
Integer groupId = 0;
|
|
|
|
|
|
for(int i=0;i<srcList.size();i++){
|
|
|
|
|
|
BaseIpCfg baseIpCfg = (BaseIpCfg) srcList.get(i);
|
|
|
|
|
|
IpCfg cfg = new IpCfg();
|
|
|
|
|
|
BeanUtils.copyProperties(baseIpCfg, cfg);
|
2018-05-31 17:07:26 +08:00
|
|
|
|
GroupCfg group = new GroupCfg();
|
|
|
|
|
|
if(!cfg.getCfgType().equals(regionValue)){
|
|
|
|
|
|
group.setGroupId(ConfigServiceUtil.getId(2, 1).get(0));
|
|
|
|
|
|
group.setCompileId(baseCfg.getCompileId());
|
|
|
|
|
|
group.setAuditTime(baseCfg.getAuditTime());
|
|
|
|
|
|
group.setIsValid(baseCfg.getIsValid());
|
|
|
|
|
|
groupRelationList.add(group);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-05-29 12:48:27 +08:00
|
|
|
|
cfg.setGroupId(group.getGroupId());
|
|
|
|
|
|
cfg.setRegionId(ConfigServiceUtil.getId(3, 1).get(0));
|
2018-05-29 14:59:40 +08:00
|
|
|
|
cfg.setAuditTime(baseCfg.getAuditTime());
|
|
|
|
|
|
cfg.setIsValid(baseCfg.getIsValid());
|
2018-05-29 12:48:27 +08:00
|
|
|
|
cfg = ipConvert(cfg,baseIpCfg);
|
|
|
|
|
|
dstList.add(cfg);
|
2018-05-31 17:07:26 +08:00
|
|
|
|
regionValue = cfg.getCfgType();
|
2018-05-29 14:59:40 +08:00
|
|
|
|
//如果protocolId非空非零,需要构造数值型域配置
|
|
|
|
|
|
if(baseIpCfg.getProtocolId()!=null && baseIpCfg.getProtocolId()!=0){
|
2018-05-29 12:48:27 +08:00
|
|
|
|
if(groupId==0){//只构造一次配置分组
|
|
|
|
|
|
GroupCfg group1 = new GroupCfg();
|
|
|
|
|
|
groupId = ConfigServiceUtil.getId(2, 1).get(0);
|
|
|
|
|
|
group1.setGroupId(groupId);
|
|
|
|
|
|
group1.setCompileId(baseIpCfg.getCompileId());
|
|
|
|
|
|
group1.setAuditTime(baseIpCfg.getAuditTime());
|
2018-05-29 14:59:40 +08:00
|
|
|
|
group1.setIsValid(baseCfg.getIsValid());
|
2018-05-29 12:48:27 +08:00
|
|
|
|
groupRelationList.add(group1);
|
|
|
|
|
|
}
|
|
|
|
|
|
NumBoundaryCfg numCfg = new NumBoundaryCfg();
|
|
|
|
|
|
numCfg.setLowBoundary(baseIpCfg.getProtocolId());
|
|
|
|
|
|
numCfg.setUpBoundary(baseIpCfg.getProtocolId());
|
|
|
|
|
|
numCfg.setRegionId(ConfigServiceUtil.getId(3, 1).get(0));
|
2018-05-29 14:59:40 +08:00
|
|
|
|
numCfg.setAuditTime(baseCfg.getAuditTime());
|
2018-05-29 12:48:27 +08:00
|
|
|
|
numCfg.setGroupId(groupId);
|
|
|
|
|
|
numCfg.setCfgType(baseIpCfg.getCfgType());
|
2018-05-29 14:59:40 +08:00
|
|
|
|
cfg.setIsValid(baseCfg.getIsValid());
|
2018-05-29 12:48:27 +08:00
|
|
|
|
numRegionList.add(numCfg);
|
|
|
|
|
|
map.put("numRegionList",numRegionList);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}else if(cfgType==2 || cfgType==3){
|
|
|
|
|
|
for(int i=0;i<srcList.size();i++){
|
2018-05-31 17:07:26 +08:00
|
|
|
|
GroupCfg group = new GroupCfg();
|
2018-05-29 12:48:27 +08:00
|
|
|
|
StringCfg cfg = new StringCfg();
|
|
|
|
|
|
BeanUtils.copyProperties(srcList.get(i), cfg);
|
2018-05-31 17:07:26 +08:00
|
|
|
|
if(!cfg.getCfgType().equals(regionValue)){
|
|
|
|
|
|
group.setGroupId(ConfigServiceUtil.getId(2, 1).get(0));
|
|
|
|
|
|
group.setCompileId(baseCfg.getCompileId());
|
|
|
|
|
|
group.setAuditTime(baseCfg.getAuditTime());
|
|
|
|
|
|
group.setIsValid(baseCfg.getIsValid());
|
|
|
|
|
|
groupRelationList.add(group);
|
|
|
|
|
|
}
|
2018-05-29 12:48:27 +08:00
|
|
|
|
cfg.setGroupId(group.getGroupId());
|
|
|
|
|
|
cfg.setRegionId(ConfigServiceUtil.getId(3, 1).get(0));
|
2018-05-29 14:59:40 +08:00
|
|
|
|
cfg.setAuditTime(baseCfg.getAuditTime());
|
|
|
|
|
|
cfg.setIsValid(baseCfg.getIsValid());
|
2018-06-01 17:17:22 +08:00
|
|
|
|
String cfgKeywords = cfg.getCfgKeywords();
|
|
|
|
|
|
cfgKeywords=cfgKeywords.replace("\\", "\\\\");
|
|
|
|
|
|
cfgKeywords=cfgKeywords.replace("&", "\\&");
|
|
|
|
|
|
cfgKeywords=cfgKeywords.replace(" ", "\\b");
|
|
|
|
|
|
//英文逗号在界面表示多个关键字的与表达式,maat端以&表示
|
|
|
|
|
|
cfgKeywords=cfgKeywords.replace(",", "&");
|
|
|
|
|
|
cfg.setCfgKeywords(cfgKeywords);
|
2018-05-29 12:48:27 +08:00
|
|
|
|
dstList.add(cfg);
|
2018-05-31 17:07:26 +08:00
|
|
|
|
regionValue = cfg.getCfgType();
|
2018-05-29 12:48:27 +08:00
|
|
|
|
}
|
|
|
|
|
|
}else if(cfgType==4){
|
|
|
|
|
|
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);
|
2018-05-31 17:07:26 +08:00
|
|
|
|
GroupCfg group = new GroupCfg();
|
|
|
|
|
|
if(!cfg.getCfgType().equals(regionValue)){
|
|
|
|
|
|
group.setGroupId(ConfigServiceUtil.getId(2, 1).get(0));
|
|
|
|
|
|
group.setCompileId(baseCfg.getCompileId());
|
|
|
|
|
|
group.setAuditTime(baseCfg.getAuditTime());
|
|
|
|
|
|
group.setIsValid(baseCfg.getIsValid());
|
|
|
|
|
|
groupRelationList.add(group);
|
|
|
|
|
|
}
|
2018-05-29 12:48:27 +08:00
|
|
|
|
cfg.setGroupId(group.getGroupId());
|
|
|
|
|
|
cfg.setRegionId(ConfigServiceUtil.getId(3, 1).get(0));
|
2018-05-29 14:59:40 +08:00
|
|
|
|
cfg.setAuditTime(baseCfg.getAuditTime());
|
|
|
|
|
|
cfg.setIsValid(baseCfg.getIsValid());
|
2018-05-29 12:48:27 +08:00
|
|
|
|
dstList.add(cfg);
|
|
|
|
|
|
}
|
2018-06-04 17:42:10 +08:00
|
|
|
|
}else if(cfgType==5){
|
|
|
|
|
|
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();
|
|
|
|
|
|
if(!cfg.getCfgType().equals(regionValue)){
|
|
|
|
|
|
group.setGroupId(ConfigServiceUtil.getId(2, 1).get(0));
|
|
|
|
|
|
group.setCompileId(baseCfg.getCompileId());
|
|
|
|
|
|
group.setAuditTime(baseCfg.getAuditTime());
|
|
|
|
|
|
group.setIsValid(baseCfg.getIsValid());
|
|
|
|
|
|
groupRelationList.add(group);
|
|
|
|
|
|
}
|
|
|
|
|
|
cfg.setGroupId(group.getGroupId());
|
|
|
|
|
|
cfg.setRegionId(ConfigServiceUtil.getId(3, 1).get(0));
|
|
|
|
|
|
cfg.setAuditTime(baseCfg.getAuditTime());
|
|
|
|
|
|
cfg.setIsValid(baseCfg.getIsValid());
|
|
|
|
|
|
dstList.add(cfg);
|
|
|
|
|
|
}
|
2018-05-29 12:48:27 +08:00
|
|
|
|
}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){
|
2018-05-30 11:40:55 +08:00
|
|
|
|
if(srcIp.getSrcIpAddress()!=null){
|
2018-05-29 12:48:27 +08:00
|
|
|
|
if(srcIp.getSrcIpAddress().indexOf("/")!=-1){
|
2018-05-30 15:12:11 +08:00
|
|
|
|
if(srcIp.getIpType()==4 || srcIp.getIpType()==46){
|
2018-05-30 11:40:55 +08:00
|
|
|
|
Integer srcMaskNum = Integer.parseInt(srcIp.getSrcIpAddress().split("/")[1]);
|
|
|
|
|
|
dstIp.setSrcIpMask(IpUtil.convertMask(srcMaskNum));
|
|
|
|
|
|
dstIp.setSrcIp(srcIp.getSrcIpAddress().split("/")[0]);
|
2018-05-30 15:12:11 +08:00
|
|
|
|
}else if(srcIp.getIpType()==6|| srcIp.getIpType()==64){
|
|
|
|
|
|
IPv6Network strangeNetwork = IPv6Network.fromString(srcIp.getSrcIpAddress());
|
|
|
|
|
|
dstIp.setSrcIp(srcIp.getSrcIpAddress().split("/")[0]);
|
|
|
|
|
|
dstIp.setSrcIpMask(strangeNetwork.getNetmask().asAddress().toString());
|
2018-05-30 11:40:55 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-05-29 12:48:27 +08:00
|
|
|
|
}else if(srcIp.getSrcIpAddress().indexOf("-")!=-1){
|
2018-05-30 15:12:11 +08:00
|
|
|
|
if(srcIp.getIpType()==4|| srcIp.getIpType()==46){
|
2018-05-30 11:40:55 +08:00
|
|
|
|
dstIp.setSrcIp(srcIp.getSrcIpAddress().split("-")[0]);
|
|
|
|
|
|
dstIp.setSrcIpMask(IpUtil.getMask(srcIp.getSrcIpAddress().split("-")[0], srcIp.getSrcIpAddress().split("-")[1]));
|
2018-05-30 15:12:11 +08:00
|
|
|
|
}else if(srcIp.getIpType()==6|| srcIp.getIpType()==64){
|
|
|
|
|
|
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());
|
2018-05-30 11:40:55 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-05-29 12:48:27 +08:00
|
|
|
|
}else{
|
2018-05-30 15:12:11 +08:00
|
|
|
|
if(srcIp.getIpType()==4|| srcIp.getIpType()==46){
|
2018-05-30 11:40:55 +08:00
|
|
|
|
dstIp.setSrcIp(srcIp.getSrcIpAddress());
|
|
|
|
|
|
dstIp.setSrcIpMask("0.0.0.0");
|
2018-05-30 15:12:11 +08:00
|
|
|
|
}else if(srcIp.getIpType()==6|| srcIp.getIpType()==64){
|
2018-05-30 11:40:55 +08:00
|
|
|
|
dstIp.setSrcIp(srcIp.getSrcIpAddress());
|
|
|
|
|
|
dstIp.setSrcIpMask("::");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}else{
|
2018-05-30 15:12:11 +08:00
|
|
|
|
if(srcIp.getIpType()==4|| srcIp.getIpType()==46){
|
2018-05-29 12:48:27 +08:00
|
|
|
|
dstIp.setSrcIp(srcIp.getSrcIpAddress());
|
|
|
|
|
|
dstIp.setSrcIpMask("0.0.0.0");
|
2018-05-30 15:12:11 +08:00
|
|
|
|
}else if(srcIp.getIpType()==6|| srcIp.getIpType()==64){
|
2018-05-30 11:40:55 +08:00
|
|
|
|
dstIp.setSrcIp(srcIp.getSrcIpAddress());
|
|
|
|
|
|
dstIp.setSrcIpMask("::");
|
2018-05-29 12:48:27 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if(srcIp.getDestIpAddress()!=null){
|
|
|
|
|
|
if(srcIp.getDestIpAddress().indexOf("/")!=-1){
|
2018-05-30 15:12:11 +08:00
|
|
|
|
if(srcIp.getIpType()==4|| srcIp.getIpType()==46){
|
2018-05-30 11:40:55 +08:00
|
|
|
|
Integer dstMaskNum = Integer.parseInt(srcIp.getDestIpAddress().split("/")[1]);
|
|
|
|
|
|
dstIp.setDstIpMask(IpUtil.convertMask(dstMaskNum));
|
|
|
|
|
|
dstIp.setDstIp(srcIp.getDestIpAddress().split("/")[0]);
|
2018-05-30 15:12:11 +08:00
|
|
|
|
}else if(srcIp.getIpType()==6|| srcIp.getIpType()==64){
|
|
|
|
|
|
IPv6Network strangeNetwork = IPv6Network.fromString(srcIp.getDestIpAddress());
|
|
|
|
|
|
dstIp.setDstIp(srcIp.getDestIpAddress().split("/")[0]);
|
|
|
|
|
|
dstIp.setDstIpMask(strangeNetwork.getNetmask().asAddress().toString());
|
2018-05-30 11:40:55 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-05-29 12:48:27 +08:00
|
|
|
|
}else if(srcIp.getDestIpAddress().indexOf("-")!=-1){
|
2018-05-30 15:12:11 +08:00
|
|
|
|
if(srcIp.getIpType()==4|| srcIp.getIpType()==46){
|
2018-05-30 11:40:55 +08:00
|
|
|
|
dstIp.setDstIp(srcIp.getDestIpAddress().split("-")[0]);
|
|
|
|
|
|
dstIp.setDstIpMask(IpUtil.getMask(srcIp.getDestIpAddress().split("-")[0], srcIp.getDestIpAddress().split("-")[1]));
|
2018-05-30 15:12:11 +08:00
|
|
|
|
}else if(srcIp.getIpType()==6|| srcIp.getIpType()==64){
|
|
|
|
|
|
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());
|
2018-05-30 11:40:55 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-05-29 12:48:27 +08:00
|
|
|
|
}else{
|
2018-05-30 15:12:11 +08:00
|
|
|
|
if(srcIp.getIpType()==4|| srcIp.getIpType()==46){
|
2018-05-30 11:40:55 +08:00
|
|
|
|
dstIp.setDstIp(srcIp.getDestIpAddress());
|
|
|
|
|
|
dstIp.setDstIpMask("0.0.0.0");
|
2018-05-30 15:12:11 +08:00
|
|
|
|
}else if(srcIp.getIpType()==6|| srcIp.getIpType()==64){
|
2018-05-30 11:40:55 +08:00
|
|
|
|
dstIp.setDstIp(srcIp.getDestIpAddress());
|
|
|
|
|
|
dstIp.setDstIpMask("::");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}else{
|
2018-05-30 15:12:11 +08:00
|
|
|
|
if(srcIp.getIpType()==4|| srcIp.getIpType()==46){
|
2018-05-29 12:48:27 +08:00
|
|
|
|
dstIp.setDstIp(srcIp.getDestIpAddress());
|
|
|
|
|
|
dstIp.setDstIpMask("0.0.0.0");
|
2018-05-30 15:12:11 +08:00
|
|
|
|
}else if(srcIp.getIpType()==6|| srcIp.getIpType()==64){
|
2018-05-30 11:40:55 +08:00
|
|
|
|
dstIp.setDstIp(srcIp.getDestIpAddress());
|
|
|
|
|
|
dstIp.setDstIpMask("::");
|
2018-05-29 12:48:27 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
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("0");
|
|
|
|
|
|
}
|
|
|
|
|
|
}else{
|
|
|
|
|
|
dstIp.setSrcPort("0");
|
|
|
|
|
|
dstIp.setSrcPortMask("0");
|
|
|
|
|
|
}
|
|
|
|
|
|
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("0");
|
|
|
|
|
|
}
|
|
|
|
|
|
}else{
|
|
|
|
|
|
dstIp.setDstPort("0");
|
|
|
|
|
|
dstIp.setDstPortMask("0");
|
|
|
|
|
|
}
|
|
|
|
|
|
return dstIp;
|
|
|
|
|
|
}
|
2018-06-05 17:28:45 +08:00
|
|
|
|
//ip转换为callback用ip
|
|
|
|
|
|
public InlineIp convertCallBackIp(BaseIpCfg cfg){
|
|
|
|
|
|
IpCfg c=ipConvert(new IpCfg(),cfg);
|
|
|
|
|
|
InlineIp ip=new InlineIp();
|
|
|
|
|
|
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());
|
|
|
|
|
|
return ip;
|
|
|
|
|
|
}
|
2018-06-04 10:04:28 +08:00
|
|
|
|
//区域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("");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2017-12-29 16:18:40 +08:00
|
|
|
|
}
|