563 lines
21 KiB
Java
563 lines
21 KiB
Java
package com.nis.web.service;
|
||
|
||
import java.lang.reflect.Type;
|
||
import java.text.SimpleDateFormat;
|
||
import java.util.ArrayList;
|
||
import java.util.Date;
|
||
import java.util.HashMap;
|
||
import java.util.List;
|
||
import java.util.Map;
|
||
|
||
import org.apache.commons.lang3.StringEscapeUtils;
|
||
import org.slf4j.Logger;
|
||
import org.slf4j.LoggerFactory;
|
||
import org.springframework.beans.BeanUtils;
|
||
|
||
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.googlecode.ipv6.IPv6Address;
|
||
import com.googlecode.ipv6.IPv6Network;
|
||
import com.nis.domain.SysRole;
|
||
import com.nis.domain.SysUser;
|
||
import com.nis.domain.callback.InlineIp;
|
||
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.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;
|
||
import com.nis.util.Configurations;
|
||
import com.nis.util.Constants;
|
||
import com.nis.util.IpUtil;
|
||
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)){
|
||
|
||
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");
|
||
}
|
||
}
|
||
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");
|
||
}
|
||
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");
|
||
}
|
||
|
||
return scopeSql.toString();
|
||
}
|
||
/**
|
||
*
|
||
* getTableName(获取表名对应的Class)
|
||
* (这里描述这个方法适用条件 – 可选)
|
||
* @param clazz
|
||
* @return
|
||
*String
|
||
* @exception
|
||
* @since 1.0.0
|
||
*/
|
||
public String getClassName(String tableName){
|
||
return Configurations.getStringProperty(tableName, null);
|
||
}
|
||
|
||
|
||
/**
|
||
* 转换成字符串
|
||
* @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()-Constants.TIME_ZONE*60*60*1000;
|
||
SimpleDateFormat sdf = new SimpleDateFormat(format);
|
||
return new JsonPrimitive(sdf.format(time));
|
||
}
|
||
}).create();
|
||
return gson.toJson(obj);
|
||
}
|
||
/**
|
||
* 界面配置list转换为服务接口端的list
|
||
* @param dstList
|
||
* @param srcList
|
||
* @param cfgType,1为IP类型,2为字符串类型,3为增强字符串,4数值类型,5摘要类,6回调类[但字符串类域配置和增强字符串域配置在接口参数中同属于strRegionList]
|
||
* @param baseCfg,配置基本信息
|
||
* @param groupRelationList 配置分组列表
|
||
* @return
|
||
*/
|
||
public static Map<String,List> cfgConvert(List dstList,List srcList,Integer cfgType,BaseCfg baseCfg,List groupRelationList){
|
||
Map<String,List> map = new HashMap();
|
||
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);
|
||
//区域IP配置,多条IP配置属于同一个分组,其他业务配置IP,一条配置一个分组
|
||
if(groupId==0 || !cfg.getCfgType().equals(Constants.AREA_REGION)){
|
||
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.setRegionId(ConfigServiceUtil.getId(3, 1).get(0));
|
||
cfg.setAuditTime(baseCfg.getAuditTime());
|
||
cfg.setIsValid(baseCfg.getIsValid());
|
||
cfg = ipConvert(cfg,baseIpCfg);
|
||
dstList.add(cfg);
|
||
|
||
//如果protocolId非空非零,需要构造数值型域配置
|
||
if(baseIpCfg.getProtocolId()!=null && baseIpCfg.getProtocolId()!=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);
|
||
}
|
||
}
|
||
|
||
}else if(cfgType==2 || cfgType==3){
|
||
for(int i=0;i<srcList.size();i++){
|
||
//一条业务配置创建一个分组
|
||
GroupCfg group = new GroupCfg();
|
||
StringCfg cfg = new StringCfg();
|
||
BeanUtils.copyProperties(srcList.get(i), cfg);
|
||
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());
|
||
//处理配置关键字转译
|
||
cfg.setCfgKeywords(keywordsEscape(cfg.getCfgKeywords()));
|
||
dstList.add(cfg);
|
||
}
|
||
}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);
|
||
GroupCfg group = new GroupCfg();
|
||
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);
|
||
}
|
||
}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();
|
||
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);
|
||
}
|
||
}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){
|
||
Integer srcMaskNum = Integer.parseInt(srcIp.getSrcIpAddress().split("/")[1]);
|
||
dstIp.setSrcIpMask(IpUtil.convertMask(srcMaskNum));
|
||
dstIp.setSrcIp(srcIp.getSrcIpAddress().split("/")[0]);
|
||
}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());
|
||
}
|
||
|
||
}else if(srcIp.getSrcIpAddress().indexOf("-")!=-1){
|
||
if(srcIp.getIpType()==4|| srcIp.getIpType()==46){
|
||
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){
|
||
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.getIpType()==4|| srcIp.getIpType()==46){
|
||
dstIp.setSrcIp(srcIp.getSrcIpAddress());
|
||
dstIp.setSrcIpMask("0.0.0.0");
|
||
}else if(srcIp.getIpType()==6|| srcIp.getIpType()==64){
|
||
dstIp.setSrcIp(srcIp.getSrcIpAddress());
|
||
dstIp.setSrcIpMask("::");
|
||
}
|
||
|
||
}
|
||
}else{
|
||
if(srcIp.getIpType()==4|| srcIp.getIpType()==46){
|
||
dstIp.setSrcIp(srcIp.getSrcIpAddress());
|
||
dstIp.setSrcIpMask("0.0.0.0");
|
||
}else if(srcIp.getIpType()==6|| srcIp.getIpType()==64){
|
||
dstIp.setSrcIp(srcIp.getSrcIpAddress());
|
||
dstIp.setSrcIpMask("::");
|
||
}
|
||
}
|
||
if(srcIp.getDestIpAddress()!=null){
|
||
if(srcIp.getDestIpAddress().indexOf("/")!=-1){
|
||
if(srcIp.getIpType()==4|| srcIp.getIpType()==46){
|
||
Integer dstMaskNum = Integer.parseInt(srcIp.getDestIpAddress().split("/")[1]);
|
||
dstIp.setDstIpMask(IpUtil.convertMask(dstMaskNum));
|
||
dstIp.setDstIp(srcIp.getDestIpAddress().split("/")[0]);
|
||
}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());
|
||
}
|
||
|
||
}else if(srcIp.getDestIpAddress().indexOf("-")!=-1){
|
||
if(srcIp.getIpType()==4|| srcIp.getIpType()==46){
|
||
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()==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());
|
||
}
|
||
|
||
}else{
|
||
if(srcIp.getIpType()==4|| srcIp.getIpType()==46){
|
||
dstIp.setDstIp(srcIp.getDestIpAddress());
|
||
dstIp.setDstIpMask("0.0.0.0");
|
||
}else if(srcIp.getIpType()==6|| srcIp.getIpType()==64){
|
||
dstIp.setDstIp(srcIp.getDestIpAddress());
|
||
dstIp.setDstIpMask("::");
|
||
}
|
||
|
||
}
|
||
}else{
|
||
if(srcIp.getIpType()==4|| srcIp.getIpType()==46){
|
||
dstIp.setDstIp(srcIp.getDestIpAddress());
|
||
dstIp.setDstIpMask("0.0.0.0");
|
||
}else if(srcIp.getIpType()==6|| srcIp.getIpType()==64){
|
||
dstIp.setDstIp(srcIp.getDestIpAddress());
|
||
dstIp.setDstIpMask("::");
|
||
}
|
||
}
|
||
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;
|
||
}
|
||
//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;
|
||
}
|
||
//区域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){
|
||
//不转译特殊字符
|
||
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;
|
||
}
|
||
}
|