1、增加maat结构配置对象类,以及界面配置转换maat配置的测试类
This commit is contained in:
@@ -367,7 +367,7 @@ public abstract class CrudService<D extends CrudDao<T>, T extends BaseEntity<T>>
|
||||
for(List<BaseCfg> cfg:cfgs){
|
||||
int compileId=0;
|
||||
ToMaatBean toMaatBean=new ToMaatBean();
|
||||
toMaatBean.setServiceCfg(new ArrayList<MaatCfg>());
|
||||
// toMaatBean.setServiceCfg(new ArrayList<MaatCfg>());
|
||||
MaatCfg maatCfg=new MaatCfg();
|
||||
for(BaseCfg c:cfg){
|
||||
if(c instanceof BaseIpCfg){
|
||||
@@ -472,60 +472,60 @@ public abstract class CrudService<D extends CrudDao<T>, T extends BaseEntity<T>>
|
||||
|
||||
}else if(c instanceof NumBoundaryCfg){
|
||||
compileId=compileId==0?c.getCompileId():compileId;
|
||||
if(maatCfg.getNumCfg()==null){
|
||||
/*if(maatCfg.getNumCfg()==null){
|
||||
List<NumBoundaryCfg> list=new ArrayList<NumBoundaryCfg>();
|
||||
list.add((NumBoundaryCfg)c);
|
||||
maatCfg.setNumCfg(list);
|
||||
}else{
|
||||
List<NumBoundaryCfg> list=maatCfg.getNumCfg();
|
||||
list.add((NumBoundaryCfg)c);
|
||||
}
|
||||
}*/
|
||||
}
|
||||
if(c.getAreaCfg()!=null){
|
||||
if(toMaatBean.getAreaCfg()!=null){
|
||||
/*if(toMaatBean.getAreaCfg()!=null){
|
||||
toMaatBean.getAreaCfg().addAll(c.getAreaCfg());
|
||||
}else{
|
||||
toMaatBean.setAreaCfg(new ArrayList<AreaIpCfg>());
|
||||
toMaatBean.getAreaCfg().addAll(c.getAreaCfg());
|
||||
}
|
||||
}*/
|
||||
}
|
||||
}
|
||||
toMaatBean.getServiceCfg().add(maatCfg);
|
||||
// toMaatBean.getServiceCfg().add(maatCfg);
|
||||
BaseCfg baseCfg=cfg.get(0);
|
||||
if(compileId==0){
|
||||
throw new RuntimeException("转换出错,未获取到正确的compileId");
|
||||
}else{
|
||||
toMaatBean.setCompileId(compileId);
|
||||
// toMaatBean.setCompileId(compileId);
|
||||
}
|
||||
if(baseCfg.getAction()==null){
|
||||
throw new RuntimeException("转换出错,未获取到正确的action");
|
||||
}else{
|
||||
toMaatBean.setAction(baseCfg.getAction());
|
||||
// toMaatBean.setAction(baseCfg.getAction());
|
||||
}
|
||||
if(baseCfg.getIsAreaEffective()==null){
|
||||
throw new RuntimeException("转换出错,未获取到正确的isAreaEffective");
|
||||
}else{
|
||||
toMaatBean.setIsAreaEffective(baseCfg.getIsAreaEffective());
|
||||
// toMaatBean.setIsAreaEffective(baseCfg.getIsAreaEffective());
|
||||
}
|
||||
if(baseCfg.getIsValid()==null){
|
||||
throw new RuntimeException("转换出错,未获取到正确的isValid");
|
||||
}else{
|
||||
toMaatBean.setIsValid(baseCfg.getIsValid());
|
||||
// toMaatBean.setIsValid(baseCfg.getIsValid());
|
||||
}
|
||||
if(baseCfg.getRequestId()==null){
|
||||
throw new RuntimeException("转换出错,未获取到正确的requestId");
|
||||
}else{
|
||||
toMaatBean.setRequestId(baseCfg.getRequestId());
|
||||
// toMaatBean.setRequestId(baseCfg.getRequestId());
|
||||
}
|
||||
if(baseCfg.getServiceId()==null){
|
||||
throw new RuntimeException("转换出错,未获取到正确的serviceId");
|
||||
}else{
|
||||
toMaatBean.setServiceId(baseCfg.getServiceId());
|
||||
// toMaatBean.setServiceId(baseCfg.getServiceId());
|
||||
}
|
||||
toMaatBean.setAreaEffectiveIds(baseCfg.getAreaEffectiveIds()==null?"":baseCfg.getAreaEffectiveIds());
|
||||
toMaatBean.setAttribute(baseCfg.getAttribute()==null?"":baseCfg.getAttribute());
|
||||
toMaatBean.setClassify(baseCfg.getClassify()==null?"":baseCfg.getClassify());
|
||||
toMaatBean.setLable(baseCfg.getLable()==null?"":baseCfg.getLable());
|
||||
// toMaatBean.setAreaEffectiveIds(baseCfg.getAreaEffectiveIds()==null?"":baseCfg.getAreaEffectiveIds());
|
||||
// toMaatBean.setAttribute(baseCfg.getAttribute()==null?"":baseCfg.getAttribute());
|
||||
// toMaatBean.setClassify(baseCfg.getClassify()==null?"":baseCfg.getClassify());
|
||||
// toMaatBean.setLable(baseCfg.getLable()==null?"":baseCfg.getLable());
|
||||
beans.add(toMaatBean);
|
||||
}
|
||||
String json=gson.toJson(beans);
|
||||
@@ -588,7 +588,7 @@ public abstract class CrudService<D extends CrudDao<T>, T extends BaseEntity<T>>
|
||||
}else{
|
||||
int compileId=0;
|
||||
ToMaatBean toMaatBean=new ToMaatBean();
|
||||
toMaatBean.setServiceCfg(new ArrayList<MaatCfg>());
|
||||
// toMaatBean.setServiceCfg(new ArrayList<MaatCfg>());
|
||||
MaatCfg maatCfg=new MaatCfg();
|
||||
for(BaseCfg c:cfg){
|
||||
if(c instanceof BaseIpCfg){
|
||||
@@ -692,7 +692,7 @@ public abstract class CrudService<D extends CrudDao<T>, T extends BaseEntity<T>>
|
||||
// }
|
||||
|
||||
}else if(c instanceof NumBoundaryCfg){
|
||||
compileId=compileId==0?c.getCompileId():compileId;
|
||||
/*compileId=compileId==0?c.getCompileId():compileId;
|
||||
if(maatCfg.getNumCfg()==null){
|
||||
List<NumBoundaryCfg> list=new ArrayList<NumBoundaryCfg>();
|
||||
list.add((NumBoundaryCfg)c);
|
||||
@@ -700,10 +700,10 @@ public abstract class CrudService<D extends CrudDao<T>, T extends BaseEntity<T>>
|
||||
}else{
|
||||
List<NumBoundaryCfg> list=maatCfg.getNumCfg();
|
||||
list.add((NumBoundaryCfg)c);
|
||||
}
|
||||
}*/
|
||||
}
|
||||
}
|
||||
if(areaCfg!=null){
|
||||
/*if(areaCfg!=null){
|
||||
toMaatBean.setAreaCfg(areaCfg);
|
||||
}else{
|
||||
toMaatBean.setAreaCfg(new ArrayList<AreaIpCfg>());
|
||||
@@ -743,7 +743,7 @@ public abstract class CrudService<D extends CrudDao<T>, T extends BaseEntity<T>>
|
||||
toMaatBean.setAreaEffectiveIds(baseCfg.getAreaEffectiveIds()==null?"":baseCfg.getAreaEffectiveIds());
|
||||
toMaatBean.setAttribute(baseCfg.getAttribute()==null?"":baseCfg.getAttribute());
|
||||
toMaatBean.setClassify(baseCfg.getClassify()==null?"":baseCfg.getClassify());
|
||||
toMaatBean.setLable(baseCfg.getLable()==null?"":baseCfg.getLable());
|
||||
toMaatBean.setLable(baseCfg.getLable()==null?"":baseCfg.getLable());*/
|
||||
|
||||
String json=gson.toJson(toMaatBean);
|
||||
logger.info("to maat json:"+json);
|
||||
|
||||
179
src/main/java/com/nis/web/test/MaatCfgConverTest.java
Normal file
179
src/main/java/com/nis/web/test/MaatCfgConverTest.java
Normal file
@@ -0,0 +1,179 @@
|
||||
package com.nis.web.test;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.beanutils.BeanUtils;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.nis.domain.configuration.BaseIpCfg;
|
||||
import com.nis.domain.configuration.BaseStringCfg;
|
||||
import com.nis.domain.configuration.ComplexkeywordCfg;
|
||||
import com.nis.domain.maat.MaatCfg;
|
||||
import com.nis.domain.maat.MaatCfg.GroupCfg;
|
||||
import com.nis.domain.maat.MaatCfg.IpCfg;
|
||||
import com.nis.domain.maat.MaatCfg.StringCfg;
|
||||
import com.nis.domain.maat.ToMaatBean;
|
||||
import com.nis.util.IpUtil;
|
||||
|
||||
public class MaatCfgConverTest {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// TODO Auto-generated method stub
|
||||
List<BaseIpCfg> ipList = new ArrayList();
|
||||
List<IpCfg> ipRegion = new ArrayList();
|
||||
List<StringCfg> strRegion = new ArrayList();
|
||||
List<MaatCfg> maatList = new ArrayList();
|
||||
List<GroupCfg> groupList = new ArrayList();
|
||||
ToMaatBean maat = new ToMaatBean();
|
||||
BaseStringCfg str = new BaseStringCfg();
|
||||
BaseIpCfg ip = new BaseIpCfg();
|
||||
ip.setIpPattern(1);
|
||||
ip.setIpType(4);
|
||||
ip.setSrcIpAddress("192.168.10.0/24");
|
||||
ip.setPortPattern(2);
|
||||
ip.setSrcPort("8080-8089");
|
||||
ip.setCompileId(123);
|
||||
ip.setProtocol(6);
|
||||
ip.setDirection(2);
|
||||
ipList.add(ip);
|
||||
ip = new BaseIpCfg();
|
||||
ip.setIpPattern(2);
|
||||
ip.setIpType(4);
|
||||
ip.setSrcIpAddress("10.0.6.0-10.0.6.100");
|
||||
ip.setPortPattern(1);
|
||||
ip.setSrcPort("7080/65534");
|
||||
ip.setCompileId(124);
|
||||
ip.setDirection(1);
|
||||
ip.setProtocol(17);
|
||||
ipList.add(ip);
|
||||
|
||||
GroupCfg group = new GroupCfg();
|
||||
int groupId = 0;
|
||||
if(ipList.size()>0){
|
||||
groupId++;
|
||||
group.setGroupId(groupId);
|
||||
group.setCompileId(1);
|
||||
group.setOpTime(new Date());
|
||||
group.setIsValid(1);
|
||||
groupList.add(group);
|
||||
}
|
||||
|
||||
int regionId = 1;
|
||||
|
||||
for(BaseIpCfg c:ipList){
|
||||
IpCfg ipCfg = new IpCfg();
|
||||
ipCfg.setRegionId(regionId);
|
||||
if(c.getIpPattern()==1){
|
||||
ipCfg.setSrcIp(c.getSrcIpAddress().split("/")[0]);
|
||||
ipCfg.setSrcIpMask(IpUtil.convertMask(Integer.parseInt(c.getSrcIpAddress().split("/")[1])));
|
||||
}else if(c.getIpPattern()==2){
|
||||
ipCfg.setSrcIp(c.getSrcIpAddress().split("-")[0]);
|
||||
ipCfg.setSrcIpMask(IpUtil.getMask(c.getSrcIpAddress().split("-")[0], c.getSrcIpAddress().split("-")[1]));
|
||||
}
|
||||
if(c.getPortPattern()==1){
|
||||
ipCfg.setSrcPort(c.getSrcPort().split("/")[0]);
|
||||
ipCfg.setSrcPortMask(c.getSrcPort().split("/")[1]);
|
||||
}else if(c.getPortPattern()==2){
|
||||
ipCfg.setSrcPort(c.getSrcPort().split("-")[0]);
|
||||
Integer portMask = Integer.parseInt(c.getSrcPort().split("-")[1])-Integer.parseInt(c.getSrcPort().split("-")[0]);
|
||||
ipCfg.setSrcPortMask(portMask.toString());
|
||||
}
|
||||
ipCfg.setDirection(c.getDirection());
|
||||
ipCfg.setProtocol(c.getProtocol());
|
||||
ipCfg.setGroupId(groupId);
|
||||
ipRegion.add(ipCfg);
|
||||
regionId++;
|
||||
}
|
||||
List<BaseStringCfg> list1 = new ArrayList();
|
||||
str.setAction(1);
|
||||
str.setCfgKeywords("测试1");
|
||||
list1.add(str);
|
||||
str = new BaseStringCfg();
|
||||
str.setAction(2);
|
||||
str.setCfgKeywords("测试2");
|
||||
list1.add(str);
|
||||
if(list1.size()>0){
|
||||
groupId++;
|
||||
group.setGroupId(groupId);
|
||||
group.setCompileId(1);
|
||||
group.setOpTime(new Date());
|
||||
group.setIsValid(1);
|
||||
groupList.add(group);
|
||||
}
|
||||
for(BaseStringCfg c:list1){
|
||||
StringCfg strCfg = new StringCfg();
|
||||
try {
|
||||
BeanUtils.copyProperties(strCfg, c);
|
||||
strCfg.setRegionId(regionId);
|
||||
strCfg.setGroupId(groupId);
|
||||
strRegion.add(strCfg);
|
||||
} catch (IllegalAccessException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (InvocationTargetException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
regionId++;
|
||||
}
|
||||
ComplexkeywordCfg complex = new ComplexkeywordCfg();
|
||||
List<ComplexkeywordCfg> list2 = new ArrayList();
|
||||
complex.setAction(1);
|
||||
complex.setDistrict("UA");
|
||||
complex.setKeywords("测试1");
|
||||
list2.add(complex);
|
||||
str = new BaseStringCfg();
|
||||
complex.setAction(1);
|
||||
complex.setDistrict("cookie");
|
||||
complex.setKeywords("测试2");
|
||||
list2.add(complex);
|
||||
if(list2.size()>0){
|
||||
groupId++;
|
||||
group.setGroupId(groupId);
|
||||
group.setCompileId(1);
|
||||
group.setOpTime(new Date());
|
||||
group.setIsValid(1);
|
||||
groupList.add(group);
|
||||
}
|
||||
for(ComplexkeywordCfg c:list2){
|
||||
StringCfg strCfg = new StringCfg();
|
||||
try {
|
||||
BeanUtils.copyProperties(strCfg, c);
|
||||
strCfg.setRegionId(regionId);
|
||||
strCfg.setGroupId(groupId);
|
||||
strRegion.add(strCfg);
|
||||
} catch (IllegalAccessException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (InvocationTargetException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
regionId++;
|
||||
}
|
||||
MaatCfg c = new MaatCfg();
|
||||
c.setCompileId(1);
|
||||
c.setGroupNum(groupList.size());
|
||||
c.setAction(1);
|
||||
c.setAttribute("11,12,13");
|
||||
c.setClassify("22,23,24");
|
||||
c.setLable("17,18,19");
|
||||
c.setFunctionId(30);
|
||||
c.setIpRegionList(ipRegion);
|
||||
c.setStrRegionList(strRegion);
|
||||
|
||||
maatList.add(c);
|
||||
maat.setAuditTime(new Date());
|
||||
maat.setVersion("1.0");
|
||||
maat.setCreatorName("test");
|
||||
maat.setConfigCompileList(maatList);
|
||||
Gson gson=new GsonBuilder().disableHtmlEscaping()
|
||||
.create();
|
||||
System.out.println(gson.toJson(maat));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user