1、APP策略配置增加IP配置;2、修改IP转换时,IPV4的IP/MASK格式时,MASK为0异常的错误。

Signed-off-by: zhangwei <zhangwei@intranet.com>
This commit is contained in:
zhangwei
2018-07-04 16:03:07 +08:00
parent d3ed5f993a
commit 2fbfedabc4
13 changed files with 588 additions and 105 deletions

View File

@@ -8,6 +8,8 @@
*/
package com.nis.domain.configuration;
import java.util.List;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
import com.nis.util.excel.ExcelField;
@@ -38,17 +40,20 @@ public class AppPolicyCfg extends BaseCfg<AppPolicyCfg> {
@Expose
@ExcelField(title="expression_type")
@SerializedName("exprType")
protected Integer exprType ;
private Integer exprType ;
@Expose
@ExcelField(title="match_method")
@SerializedName("matchMethod")
protected Integer matchMethod ;
private Integer matchMethod ;
@Expose
@ExcelField(title="whether_hexbinary")
@SerializedName("isHexbin")
protected Integer isHexbin;
private Integer isHexbin;
private List<IpPortCfg> ipPortList;
private IpPortCfg ipPort;
public Integer getExprType() {
return exprType;
@@ -134,5 +139,21 @@ public class AppPolicyCfg extends BaseCfg<AppPolicyCfg> {
public void setBehavCode(Integer behavCode) {
this.behavCode = behavCode;
}
public List<IpPortCfg> getIpPortList() {
return ipPortList;
}
public void setIpPortList(List<IpPortCfg> ipPortList) {
this.ipPortList = ipPortList;
}
public IpPortCfg getIpPort() {
return ipPort;
}
public void setIpPort(IpPortCfg ipPort) {
this.ipPort = ipPort;
}
}

View File

@@ -1,6 +1,8 @@
package com.nis.web.controller.configuration;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@@ -19,6 +21,9 @@ import com.nis.domain.configuration.AppDomainCfg;
import com.nis.domain.configuration.AppHttpCfg;
import com.nis.domain.configuration.AppIpCfg;
import com.nis.domain.configuration.AppPolicyCfg;
import com.nis.domain.configuration.BaseStringCfg;
import com.nis.domain.configuration.CfgIndexInfo;
import com.nis.domain.configuration.IpPortCfg;
import com.nis.domain.specific.SpecificServiceCfg;
import com.nis.exceptions.MaatConvertException;
import com.nis.web.controller.BaseController;
@@ -52,6 +57,31 @@ public class AppCfgController extends BaseController {
initPageCondition(model,cfg);
return "/cfg/app/appPolicyCfgList";
}
/**
* 查询APP策略IP子配置
* @param model
* @param cfgId
* @param index
* @return
*/
@RequestMapping(value = {"ajaxAppPolicyIpList"})
public String ajaxSslSubList(Model model,Long cfgId,Integer index) {
AppPolicyCfg cfg = appCfgService.getAppPolicyCfg(cfgId);
List<String[]> tabList = new ArrayList();
if(cfg.getIpPortList()!=null){
String cfgType = null;
for(IpPortCfg ip:cfg.getIpPortList()){
if(!ip.getCfgType().equals(cfgType)){
tabList.add(new String[]{"1",ip.getCfgType()});
cfgType = ip.getCfgType();
}
}
}
model.addAttribute("_cfg", cfg);
model.addAttribute("index", index);
model.addAttribute("tabList", tabList);
return "/cfg/app/appPolicyIpList";
}
/**
* 策略配置表单
* @param model

View File

@@ -18,6 +18,7 @@ import com.nis.domain.configuration.AppStringCfg;
import com.nis.domain.configuration.BaseCfg;
import com.nis.domain.configuration.BaseStringCfg;
import com.nis.domain.configuration.ComplexkeywordCfg;
import com.nis.domain.configuration.IpPortCfg;
import com.nis.web.dao.CrudDao;
import com.nis.web.dao.MyBatisDao;
@@ -32,8 +33,13 @@ public interface AppCfgDao {
//app策略配置增删改查
public List<AppPolicyCfg> findAppPolicyList(AppPolicyCfg entity) ;
public AppPolicyCfg getAppPolicyCfg(Long cfgId) ;
public IpPortCfg getAppPolicyIpCfg(AppPolicyCfg entity) ;
public List<IpPortCfg> getAppPolicyIpList(AppPolicyCfg entity);
public int insertAppPolicyCfg(AppPolicyCfg entity);
public int updateAppPolicyCfg(AppPolicyCfg entity);
public int insertAppPolicyIpCfg(IpPortCfg entity);
public int deleteAppPolicyIpCfg(AppPolicyCfg entity);
//app协议IP配置增删改查
public List<AppIpCfg> findAppIpList(AppIpCfg entity) ;
public AppIpCfg getAppIpCfg(Long cfgId) ;

View File

@@ -189,6 +189,41 @@
<result column="function_id" property="functionId" jdbcType="INTEGER" />
</resultMap>
<resultMap id="ipPortMap" type="com.nis.domain.configuration.IpPortCfg" >
<id column="cfg_id" property="cfgId" jdbcType="BIGINT" />
<result column="cfg_desc" property="cfgDesc" jdbcType="VARCHAR" />
<result column="ip_type" property="ipType" jdbcType="INTEGER" />
<result column="ip_pattern" property="ipPattern" jdbcType="INTEGER" />
<result column="dest_ip_address" property="destIpAddress" jdbcType="VARCHAR" />
<result column="src_ip_address" property="srcIpAddress" jdbcType="VARCHAR" />
<result column="dest_port" property="destPort" jdbcType="VARCHAR" />
<result column="src_port" property="srcPort" jdbcType="VARCHAR" />
<result column="port_pattern" property="portPattern" jdbcType="INTEGER" />
<result column="direction" property="direction" jdbcType="INTEGER" />
<result column="protocol" property="protocol" jdbcType="INTEGER" />
<result column="protocol_id" property="protocolId" jdbcType="INTEGER" />
<result column="action" property="action" jdbcType="INTEGER" />
<result column="is_valid" property="isValid" jdbcType="INTEGER" />
<result column="is_audit" property="isAudit" jdbcType="INTEGER" />
<result column="creator_id" property="creatorId" jdbcType="INTEGER" />
<result column="create_time" property="createTime" jdbcType="TIMESTAMP" />
<result column="editor_id" property="editorId" jdbcType="INTEGER" />
<result column="edit_time" property="editTime" jdbcType="TIMESTAMP" />
<result column="auditor_id" property="auditorId" jdbcType="INTEGER" />
<result column="audit_time" property="auditTime" jdbcType="TIMESTAMP" />
<result column="service_id" property="serviceId" jdbcType="INTEGER" />
<result column="request_id" property="requestId" jdbcType="INTEGER" />
<result column="compile_id" property="compileId" jdbcType="INTEGER" />
<result column="is_area_effective" property="isAreaEffective" jdbcType="INTEGER" />
<result column="classify" property="classify" jdbcType="VARCHAR" />
<result column="attribute" property="attribute" jdbcType="VARCHAR" />
<result column="lable" property="lable" jdbcType="VARCHAR" />
<result column="area_effective_ids" property="areaEffectiveIds" jdbcType="VARCHAR" />
<result column="function_id" property="functionId" jdbcType="INTEGER" />
<result column="cfg_region_code" property="cfgRegionCode" jdbcType="INTEGER" />
<result column="cfg_type" property="cfgType" jdbcType="VARCHAR" />
</resultMap>
<sql id="AppPolicyCfg_Column" >
r.CFG_ID, r.APP_CODE,r.BEHAV_CODE,r.SPEC_SERVICE_ID,r.CFG_DESC,r.ACTION,r.IS_VALID,r.IS_AUDIT,
r.CREATOR_ID,r.CREATE_TIME,r.EDITOR_ID,r.EDIT_TIME,r.AUDITOR_ID,r.AUDIT_TIME,
@@ -248,6 +283,15 @@
#{areaEffectiveIds,jdbcType=VARCHAR},#{ratelimit,jdbcType=INTEGER},#{functionId,jdbcType=INTEGER},
#{cfgType,jdbcType=VARCHAR},#{cfgRegionCode,jdbcType=INTEGER}
</sql>
<sql id="IpCfg_Column" >
a.cfg_id,a.cfg_desc,a.ip_type,a.src_ip_address,a.ip_pattern,a.port_pattern,a.src_port
,a.protocol,a.protocol_id,a.direction,a.cfg_type,a.action,a.dest_port,a.dest_ip_address
,a.is_valid,a.is_audit,a.creator_id,a.create_time,a.editor_id
,a.edit_time,a.auditor_id,a.audit_time,a.service_id,a.request_id,
a.compile_id,a.is_area_effective,a.classify,a.attribute,a.lable
,a.area_effective_ids,a.function_id,a.cfg_region_code
</sql>
<!-- <sql id="AppCfg_Column_List_with_id_alias" >
<choose>
<when test="page !=null and page.alias != null and page.alias != ''">
@@ -397,7 +441,25 @@
<if test="areaEffectiveIds != null and areaEffectiveIds != ''">
AND r.AREA_EFFECTIVE_IDS like concat(concat('%',#{areaEffectiveIds,jdbcType=VARCHAR}),'%')
</if>
<if test="ipPort!=null">
AND r.compile_id in (select t.compile_id from ip_port_cfg t
<where>
and t.protocol_id=21
<if test="ipPort.srcIpAddress != null and ipPort.srcIpAddress != ''">
and t.src_ip_address =#{(ipPort.srcIpAddress,jdbcType=VARCHAR}
</if>
<if test="ipPort.srcPort != null and ipPort.srcPort != ''">
and t.src_port =#{ipPort.srcPort,jdbcType=VARCHAR}
</if>
<if test="ipPort.destIpAddress != null and ipPort.destIpAddress != ''">
and t.dest_ip_address =#{(ipPort.destIpAddress,jdbcType=VARCHAR}
</if>
<if test="ipPort.destPort != null and ipPort.destPort != ''">
and t.dest_port =#{ipPort.destPort,jdbcType=VARCHAR}
</if>
</where>
)
</if>
</trim>
<choose>
<when test="page !=null and page.orderBy != null and page.orderBy != ''">
@@ -1011,6 +1073,78 @@
)
</insert>
<!-- insert ip_port_cfg表信息 -->
<insert id="insertAppPolicyIpCfg" parameterType="com.nis.domain.configuration.IpPortCfg" >
<selectKey resultType="java.lang.Long" order="AFTER" keyProperty="cfgId">
SELECT LAST_INSERT_ID()
</selectKey>
insert into ip_port_cfg (
CFG_DESC,
ACTION,
IS_VALID,
IS_AUDIT,
CREATOR_ID,
CREATE_TIME,
EDITOR_ID,
EDIT_TIME,
AUDITOR_ID,
AUDIT_TIME,
SERVICE_ID,
REQUEST_ID,
COMPILE_ID,
IS_AREA_EFFECTIVE,
CLASSIFY,
ATTRIBUTE,
LABLE,
AREA_EFFECTIVE_IDS,
function_id,
ip_type,
src_ip_address,
ip_pattern,
port_pattern,
src_port,
protocol,
protocol_id,
direction,
dest_port,
dest_ip_address,
cfg_type,
cfg_region_code
)values (
#{cfgDesc,jdbcType=VARCHAR},
#{action,jdbcType=INTEGER},
0,
0,
#{creatorId,jdbcType=INTEGER},
#{createTime,jdbcType=TIMESTAMP},
#{editorId,jdbcType=INTEGER},
#{editTime,jdbcType=TIMESTAMP},
#{auditorId,jdbcType=INTEGER},
#{auditTime,jdbcType=TIMESTAMP},
#{serviceId,jdbcType=INTEGER},
#{requestId,jdbcType=INTEGER},
#{compileId,jdbcType=INTEGER},
#{isAreaEffective,jdbcType=INTEGER},
#{classify,jdbcType=VARCHAR},
#{attribute,jdbcType=VARCHAR},
#{lable,jdbcType=VARCHAR},
#{areaEffectiveIds,jdbcType=VARCHAR},
#{functionId,jdbcType=INTEGER},
#{ipType,jdbcType=INTEGER},
#{srcIpAddress,jdbcType=VARCHAR},
#{ipPattern,jdbcType=INTEGER},
#{portPattern,jdbcType=INTEGER},
#{srcPort,jdbcType=VARCHAR},
#{protocol,jdbcType=INTEGER},
#{protocolId,jdbcType=INTEGER},
#{direction,jdbcType=INTEGER},
#{destPort,jdbcType=VARCHAR},
#{destIpAddress,jdbcType=VARCHAR},
#{cfgType,jdbcType=VARCHAR},
#{cfgRegionCode,jdbcType=INTEGER}
)
</insert>
<update id="updateAppPolicyCfg" parameterType="com.nis.domain.configuration.AppPolicyCfg" >
update app_policy_cfg
<set >
@@ -1525,4 +1659,15 @@
</trim>
</update>
<!-- 删除APP策略IP子配置 -->
<delete id="deleteAppPolicyIpCfg" >
delete from ip_port_cfg where compile_id=#{compileId} and protocol_id=21 and function_id=#{functionId}
</delete>
<!-- 查询APP策略IP子配置 -->
<select id="getAppPolicyIpList" resultMap="ipPortMap" parameterType="com.nis.domain.configuration.CfgIndexInfo">
SELECT
<include refid="IpCfg_Column" />
FROM ip_port_cfg a where compile_id=#{compileId} and function_id=#{functionId}
</select>
</mapper>

View File

@@ -390,7 +390,12 @@ public abstract class BaseService {
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]);
dstIp.setSrcIpMask(IpUtil.convertMask(srcMaskNum));
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());
@@ -413,27 +418,31 @@ public abstract class BaseService {
}else{
if(srcIp.getIpType()==4|| srcIp.getIpType()==46){//46表示源ip为ipv4目的ip为ipv6
dstIp.setSrcIp(srcIp.getSrcIpAddress());
dstIp.setSrcIpMask("0.0.0.0");
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("::");
dstIp.setSrcIpMask("FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF");
}
}
}else{
if(srcIp.getIpType()==4|| srcIp.getIpType()==46){//46表示源ip为ipv4目的ip为ipv6
dstIp.setSrcIp(srcIp.getSrcIpAddress());
dstIp.setSrcIpMask("0.0.0.0");
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("::");
dstIp.setSrcIpMask("FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF");
}
}
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]);
dstIp.setDstIpMask(IpUtil.convertMask(dstMaskNum));
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());
@@ -456,20 +465,20 @@ public abstract class BaseService {
}else{
if(srcIp.getIpType()==4|| srcIp.getIpType()==64){//64表示源ip为ipv6目的ip为ipv4
dstIp.setDstIp(srcIp.getDestIpAddress());
dstIp.setDstIpMask("0.0.0.0");
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("::");
dstIp.setDstIpMask("FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF");
}
}
}else{
if(srcIp.getIpType()==4|| srcIp.getIpType()==64){//64表示源ip为ipv6目的ip为ipv4
dstIp.setDstIp(srcIp.getDestIpAddress());
dstIp.setDstIpMask("0.0.0.0");
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("::");
dstIp.setDstIpMask("FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF");
}
}
if(srcIp.getSrcPort()!=null){
@@ -479,11 +488,11 @@ public abstract class BaseService {
dstIp.setSrcPort(srcIp.getSrcPort().split("/")[0]);
}else{
dstIp.setSrcPort(srcIp.getSrcPort());
dstIp.setSrcPortMask("0");
dstIp.setSrcPortMask("65535");
}
}else{
dstIp.setSrcPort("0");
dstIp.setSrcPortMask("0");
dstIp.setSrcPortMask("65535");
}
if(srcIp.getDestPort()!=null){
if(srcIp.getDestPort().indexOf("/")!=-1){
@@ -492,11 +501,11 @@ public abstract class BaseService {
dstIp.setDstPort(srcIp.getDestPort().split("/")[0]);
}else{
dstIp.setDstPort(srcIp.getDestPort());
dstIp.setDstPortMask("0");
dstIp.setDstPortMask("65535");
}
}else{
dstIp.setDstPort("0");
dstIp.setDstPortMask("0");
dstIp.setDstPortMask("65535");
}
return dstIp;
}

View File

@@ -17,6 +17,7 @@ import com.nis.domain.configuration.AppHttpCfg;
import com.nis.domain.configuration.AppIpCfg;
import com.nis.domain.configuration.AppPolicyCfg;
import com.nis.domain.configuration.AreaIpCfg;
import com.nis.domain.configuration.IpPortCfg;
import com.nis.domain.maat.MaatCfg;
import com.nis.domain.maat.ToMaatBean;
import com.nis.domain.maat.ToMaatResult;
@@ -84,7 +85,10 @@ public class AppCfgService extends BaseService {
return page;
}
public AppPolicyCfg getAppPolicyCfg(Long cfgId){
return appCfgDao.getAppPolicyCfg(cfgId);
AppPolicyCfg policy = appCfgDao.getAppPolicyCfg(cfgId);
List<IpPortCfg> ipPortList = appCfgDao.getAppPolicyIpList(policy);
policy.setIpPortList(ipPortList);
return policy;
}
public AppIpCfg getAppIpCfg(Long cfgId){
return appCfgDao.getAppIpCfg(cfgId);
@@ -116,6 +120,13 @@ public class AppCfgService extends BaseService {
entity.setIsValid(0);
entity.setIsAudit(0);
appCfgDao.insertAppPolicyCfg(entity);
//保存策略IP配置
if(entity.getIpPortList()!=null){
for(IpPortCfg cfg:entity.getIpPortList()){
BeanUtils.copyProperties(entity, cfg,new String[]{"cfgRegionCode","cfgType"});
appCfgDao.insertAppPolicyIpCfg(cfg);
}
}
//保存区域IP信息
if(entity.getAreaCfg()!=null){
for(AreaIpCfg cfg:entity.getAreaCfg()){
@@ -134,15 +145,25 @@ public class AppCfgService extends BaseService {
entity.setEditTime(new Date());
entity.setIsValid(0);
entity.setIsAudit(0);
appCfgDao.updateAppPolicyCfg(entity);
appCfgDao.updateAppPolicyCfg(entity);
appCfgDao.deleteAppPolicyIpCfg(entity);
//删除旧的区域IP新增新的区域IP
AreaIpCfg area = new AreaIpCfg();
area.setCompileId(entity.getCompileId());
area.setFunctionId(entity.getFunctionId());
areaIpCfgDao.deleteAreaIpCfg(area);
entity.setCreateTime(new Date());
entity.setCreatorId(entity.getCurrentUser().getId());
//保存策略IP配置
if(entity.getIpPortList()!=null){
for(IpPortCfg cfg:entity.getIpPortList()){
BeanUtils.copyProperties(entity, cfg,new String[]{"cfgRegionCode","cfgType"});
appCfgDao.insertAppPolicyIpCfg(cfg);
}
}
//保存区域IP信息
if(entity.getAreaCfg()!=null){
for(AreaIpCfg cfg:entity.getAreaCfg()){
@@ -390,19 +411,37 @@ public class AppCfgService extends BaseService {
List<IpCfg> areaIpRegionList = new ArrayList();
entity.setTableName(AppPolicyCfg.getTablename());
appCfgDao.auditCfg(entity);
if(isAudit==1){
if(entity.getBehavCode()!=null){
entity.setCfgKeywords(entity.getAppCode()+"&"+entity.getBehavCode());
}else{
entity.setCfgKeywords(entity.getAppCode()+"");
}
List<AppPolicyCfg> list = new ArrayList();
list.add(entity);
Map<String,List> map = cfgConvert(strRegionList,list,2,entity,groupRelationList);
groupRelationList=map.get("groupList");
strRegionList=map.get("dstList");
}
//查询子配置并修改审核状态
entity = this.getAppPolicyCfg(entity.getCfgId());
if(entity.getIpPortList()!=null && entity.getIpPortList().size()>0){
IpPortCfg cfg = new IpPortCfg();
BeanUtils.copyProperties(entity, cfg, new String[]{"cfgId"});
cfg.setTableName(IpPortCfg.getTablename());
appCfgDao.auditCfg(cfg);
if(isAudit==1){
Map<String,List> map = cfgConvert(ipRegionList,entity.getIpPortList(),1,entity,groupRelationList);
groupRelationList=map.get("groupList");
ipRegionList=map.get("dstList");
if(map.get("numRegionList")!=null){
numRegionList.addAll(map.get("numRegionList"));
}
}
}
//保存区域IP信息
List<AreaIpCfg> areaIpCfgList=areaIpCfgDao.getByCompileId(entity.getCompileId());
if(!StringUtil.isEmpty(areaIpCfgList)){
@@ -810,6 +849,15 @@ public class AppCfgService extends BaseService {
entity.setTableName(AppPolicyCfg.getTablename());
entity.setFunctionId(functionId);
appCfgDao.updateCfgValid(entity);
//查询子配置
entity = this.getAppPolicyCfg(Long.parseLong(id));
if(entity.getIpPortList()!=null && entity.getIpPortList().size()>0){
IpPortCfg cfg = new IpPortCfg();
BeanUtils.copyProperties(entity, cfg, new String[]{"cfgId"});
cfg.setTableName(IpPortCfg.getTablename());
appCfgDao.updateCfgValid(cfg);
}
//保存区域IP信息
if(entity.getAreaCfg()!=null && entity.getAreaCfg().size()>0){
AreaIpCfg cfg = new AreaIpCfg();