ip地址添加NTC_SUBSCRIBE_ID,丢弃和回流不加NTC_SUBSCRIBE_ID配置,不记录日志

This commit is contained in:
wangxin
2018-08-25 11:42:24 +08:00
parent 13ad6d7199
commit c8a6dd4055
10 changed files with 1206 additions and 344 deletions

View File

@@ -1,10 +1,13 @@
package com.nis.web.controller.configuration.ntc;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
@@ -15,15 +18,18 @@ import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import com.nis.domain.Page;
import com.nis.domain.SysDataDictionaryItem;
import com.nis.domain.configuration.BaseIpCfg;
import com.nis.domain.configuration.CfgIndexInfo;
import com.nis.domain.configuration.IpPortCfg;
import com.nis.domain.configuration.NtcSubscribeIdCfg;
import com.nis.domain.configuration.template.IpAddrTemplate;
import com.nis.domain.configuration.template.IpsecTemplate;
import com.nis.domain.configuration.template.TunnelIpTemplate;
import com.nis.util.Constants;
import com.nis.exceptions.MaatConvertException;
import com.nis.util.DictUtils;
import com.nis.web.controller.configuration.CommonController;
import com.nis.web.security.UserUtils;
/**
* IP相关配置控制类
@@ -35,54 +41,87 @@ import com.nis.web.controller.configuration.CommonController;
public class IpController extends CommonController{
@RequestMapping(value = {"list"})
// @RequiresPermissions(value={"iplist:config","iplist:confirm"},logical=Logical.OR)
public String list(String cfgName,Model model,@ModelAttribute("cfg")IpPortCfg cfg,HttpServletRequest request,HttpServletResponse response) {
this._ipList(cfgName, model, cfg, request, response);
model.addAttribute("urlPrefix","/ntc/iplist");
model.addAttribute("requiresPermissionPrefix","iplist");
return "/cfg/common/ipList";
public String list(Model model,@ModelAttribute("cfg")CfgIndexInfo cfg,HttpServletRequest request,HttpServletResponse response) {
Page<CfgIndexInfo> searchPage=new Page<CfgIndexInfo>(request,response,"a");
Page<CfgIndexInfo> page = ipCfgService.getIpCfgList(searchPage, cfg);
model.addAttribute("page", page);
initPageCondition(model,cfg);
return "/cfg/ipaddr/ipList";
}
@RequestMapping(value = {"form"})
@RequiresPermissions(value={"iplist:config"})
public String form(String cfgName,Model model,String ids,Integer functionId,BaseIpCfg entity) {
this._ipForm(cfgName, model, ids, functionId, entity);
List<SysDataDictionaryItem> specialFunctionIdList = DictUtils.getDictList("SPECIAL_FUNCTION_ID");
String specialFunctionId=null;
for(SysDataDictionaryItem item:specialFunctionIdList) {
if(Integer.parseInt(item.getItemCode())==entity.getFunctionId().intValue()) {
specialFunctionId= item.getItemValue();
break;
}
public String form(Model model,String ids,CfgIndexInfo entity) {
if(StringUtils.isNotBlank(ids)){
entity = ipCfgService.getIpPortCfg(Long.parseLong(ids));
initUpdateFormCondition(model,entity);
}else{
initFormCondition(model,entity);
}
model.addAttribute("dropAction",Constants.DROP_ACTION);
model.addAttribute("urlPrefix","/ntc/iplist");
model.addAttribute("requiresPermissionPrefix","iplist");
// if(specialFunctionId!=null && "ipsec".equals(specialFunctionId)) {
// return "/cfg/ipsec/ipForm";
// }else if(specialFunctionId!=null && "ipaddr".equals(specialFunctionId)) {
// return "/cfg/ipaddr/ipForm";
// }
return "/cfg/common/ipForm";
model.addAttribute("_cfg", entity);
return "/cfg/ipaddr/ipForm";
}
@RequestMapping(value = {"saveOrUpdate"})
public String saveOrUpdate(String cfgName,RedirectAttributes model, IpPortCfg cfg) {
this._saveOrUpdateIp(cfgName, model, cfg);
return "redirect:" + adminPath +"/ntc/iplist/list?functionId="+cfg.getFunctionId();
public String saveOrUpdate(RedirectAttributes model,HttpServletRequest request,HttpServletResponse response,String ids,CfgIndexInfo entity) {
ipCfgService.saveIpCfg(entity);
return "redirect:" + adminPath +"/ntc/iplist/list?functionId="+entity.getFunctionId();
}
@RequestMapping(value = {"delete"})
@RequestMapping(value = {"ajaxSubList"})
public String ajaxIpPortSubList(Model model,Long cfgId,Integer index) {
CfgIndexInfo cfg = ipCfgService.getIpPortCfg(cfgId);
/*List<FunctionRegionDict> regionList = DictUtils.getFunctionRegionDictList(cfg.getFunctionId());
model.addAttribute("regionList", regionList);*/
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();
}
}
}
if(cfg.getNtcSubscribeIdCfgList()!=null){
String cfgType = null;
for(NtcSubscribeIdCfg keyword:cfg.getNtcSubscribeIdCfgList()){
if(!keyword.getCfgType().equals(cfgType)){
tabList.add(new String[]{"2",keyword.getCfgType()});
cfgType = keyword.getCfgType();
}
}
}
model.addAttribute("_cfg", cfg);
model.addAttribute("index", index);
model.addAttribute("tabList", tabList);
return "/cfg/ipaddr/ipSubList";
}
@RequestMapping(value = {"updateValid"})
@RequiresPermissions("iplist:config")
public String delete(String cfgName,String ids,String compileIds,Integer functionId,RedirectAttributes model) {
this._deleteIp(cfgName, ids, compileIds, functionId, model);
model.addAttribute("urlPrefix","/ntc/iplist");
model.addAttribute("requiresPermissionPrefix","iplist");
public String updateIpPortCfgValid(Integer isValid,String ids,Integer functionId) {
ipCfgService.updateIpCfgValid(isValid, ids, functionId);
return "redirect:" + adminPath +"/ntc/iplist/list?functionId="+functionId;
}
@RequestMapping(value = {"audit"})
@RequiresPermissions("iplist:confirm")
public String audit(String cfgName,String ids,IpPortCfg cfg,RedirectAttributes redirectAttributes) {
this._auditIp(cfgName, ids, cfg, redirectAttributes);
redirectAttributes.addAttribute("urlPrefix","/ntc/iplist");
redirectAttributes.addAttribute("requiresPermissionPrefix","iplist");
return "redirect:" + adminPath +"/ntc/iplist/list?functionId="+cfg.getFunctionId();
public String audit(Integer isAudit,Integer isValid,String ids,Integer functionId, RedirectAttributes redirectAttributes) {
CfgIndexInfo entity = new CfgIndexInfo();
String[] idArray = ids.split(",");
for(String id :idArray){
entity = ipCfgService.getIpPortCfg(Long.parseLong(id));
entity.setIsAudit(isAudit);
entity.setIsValid(isValid);
entity.setAuditorId(UserUtils.getUser().getId());
entity.setAuditTime(new Date());
entity.setFunctionId(functionId);
try {
ipCfgService.auditIpCfg(entity,isAudit);
} catch (MaatConvertException e) {
e.printStackTrace();
logger.info("ssl配置下发失败"+e.getMessage());
addMessage(redirectAttributes, e.getMessage());
}
}
return "redirect:" + adminPath +"/ntc/iplist/list?functionId="+functionId;
}
//ip配置导入
@RequestMapping(value = "import", method=RequestMethod.POST)

View File

@@ -41,7 +41,7 @@ public class WhiteListController extends CommonController{
//@RequiresPermissions(value={"whitelist:ip:config","whitelist:ip:confirm","whitelist:ip:aduit"},logical=Logical.OR)
public String ipList(Model model,@ModelAttribute("cfg")CfgIndexInfo cfg,HttpServletRequest request,HttpServletResponse response) {
Page<CfgIndexInfo> searchPage=new Page<CfgIndexInfo>(request,response,"a");
Page<CfgIndexInfo> page = ipCfgService.getWhiteIpList(searchPage, cfg);
Page<CfgIndexInfo> page = ipCfgService.getIpCfgList(searchPage, cfg);
model.addAttribute("page", page);
initPageCondition(model,cfg);
return "/cfg/whitelist/ipList";

View File

@@ -44,6 +44,6 @@ public interface IpCfgDao extends CrudDao<BaseIpCfg>{
public void deleteIpCfg(CfgIndexInfo entity);
public void updateCfgValid(BaseCfg entity);
public void auditCfg(BaseCfg entity);
public List<CfgIndexInfo> getWhiteIpList(CfgIndexInfo entity);
public List<CfgIndexInfo> getIpCfgList(CfgIndexInfo entity);
}

View File

@@ -1001,7 +1001,7 @@
and function_id=#{functionId,jdbcType=INTEGER}
</trim>
</update>
<select id="getWhiteIpList" resultMap="CfgIndexInfoMap" parameterType="com.nis.domain.configuration.CfgIndexInfo" >
<select id="getIpCfgList" resultMap="CfgIndexInfoMap" parameterType="com.nis.domain.configuration.CfgIndexInfo" >
SELECT
<include refid="ConfigIndex_Column" />
<trim prefix="," prefixOverrides=",">
@@ -1073,92 +1073,6 @@
<if test="functionId != null">
AND a.function_id=#{functionId,jdbcType=INTEGER}
</if>
<if test="ipPort!=null">
AND a.compile_id in (select t.compile_id from ip_port_cfg t
<where>
<if test="functionId != null">
AND t.function_id=#{functionId,jdbcType=INTEGER}
</if>
<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>
<if test="httpUrl!=null">
AND a.compile_id in (select f.compile_id from http_url_cfg f
<where>
<if test="httpUrl.cfgKeywords != null and httpUrl.cfgKeywords != ''">
and f.cfg_keywords like concat(concat('%',#{httpUrl.cfgKeywords,jdbcType=VARCHAR}),'%')
</if>
</where>
)
</if>
<if test="httpReqBody!=null">
AND a.compile_id in (select f.compile_id from http_body_cfg f
<where>
and cfg_type='http_req_body'
<if test="httpReqBody.cfgKeywords != null and httpReqBody.cfgKeywords != ''">
and f.cfg_keywords like concat(concat('%',#{httpReqBody.cfgKeywords,jdbcType=VARCHAR}),'%')
</if>
</where>
)
</if>
<if test="httpResBody!=null">
AND a.compile_id in (select f.compile_id from http_body_cfg f
<where>
and cfg_type='http_res_body'
<if test="httpResBody.cfgKeywords != null and httpResBody.cfgKeywords != ''">
and f.cfg_keywords like concat(concat('%',#{httpResBody.cfgKeywords,jdbcType=VARCHAR}),'%')
</if>
</where>
)
</if>
<if test="httpReqHdr!=null">
AND a.compile_id in (select f.compile_id from http_req_head_cfg f
<where>
<if test="httpReqHdr.cfgKeywords != null and httpReqHdr.cfgKeywords != ''">
and f.cfg_keywords like concat(concat('%',#{httpReqHdr.cfgKeywords,jdbcType=VARCHAR}),'%')
</if>
<if test="httpReqHdr.district != null and httpReqHdr.district != ''">
and f.district like concat(concat('%',#{httpReqHdr.district,jdbcType=VARCHAR}),'%')
</if>
</where>
)
</if>
<if test="httpResHdr!=null">
AND a.compile_id in (select f.compile_id from http_res_head_cfg f
<where>
<if test="httpResHdr.cfgKeywords != null and httpResHdr.cfgKeywords != ''">
and f.cfg_keywords like concat(concat('%',#{httpResHdr.cfgKeywords,jdbcType=VARCHAR}),'%')
</if>
<if test="httpResHdr.district != null and httpResHdr.district != ''">
and f.district like concat(concat('%',#{httpResHdr.district,jdbcType=VARCHAR}),'%')
</if>
</where>
)
</if>
<!-- <if test="sslCfg!=null">
AND a.compile_id in (select f.compile_id from ssl_keyword_cfg f
<where>
<if test="sslCfg.cfgKeywords != null and sslCfg.cfgKeywords != ''">
and f.cfg_keywords like concat(concat('%',#{sslCfg.cfgKeywords,jdbcType=VARCHAR}),'%')
</if>
</where>
)
</if> -->
<!-- 数据范围过滤 -->
${sqlMap.dsf}
</trim>

View File

@@ -495,10 +495,10 @@ public class IpCfgService extends CrudService<IpCfgDao,BaseIpCfg> {
}
}
public void auditIpCfg(CfgIndexInfo entity,Integer isAudit) throws MaatConvertException{
Properties props=this.getMsgProp();
//修改数据库审核状态信息
entity.setTableName(CfgIndexInfo.getTablename());
ipCfgDao.auditCfg(entity);
ToMaatBean maatBean = new ToMaatBean();
MaatCfg maatCfg = new MaatCfg();
List<MaatCfg> configCompileList = new ArrayList();
@@ -508,10 +508,22 @@ public class IpCfgService extends CrudService<IpCfgDao,BaseIpCfg> {
List<NumBoundaryCfg> numRegionList = new ArrayList();
List<DigestCfg> digestRegionList = new ArrayList();
List<IpCfg> areaIpRegionList = new ArrayList();
//获取region
List<FunctionRegionDict> dictList = DictUtils.getFunctionRegionDictList(entity.getFunctionId());
int maatType=0;
//查询子配置并修改审核状态
entity = this.getIpPortCfg(entity.getCfgId());
if(entity.getIpPortList()!=null && entity.getIpPortList().size()>0){
//判断下发类型是走maat还是callback
String regionValue=entity.getIpPortList().get(0).getCfgType();
if(regionValue!=null) {
for(FunctionRegionDict region:dictList) {
if(regionValue.equals(region.getConfigRegionValue())) {
maatType=region.getIsMaat();
break;
}
}
}
IpPortCfg cfg = new IpPortCfg();
BeanUtils.copyProperties(entity, cfg, new String[]{"cfgId"});
cfg.setTableName(IpPortCfg.getTablename());
@@ -551,48 +563,95 @@ public class IpCfgService extends CrudService<IpCfgDao,BaseIpCfg> {
}
//构造提交综合服务参数格式,一条配置提交一次综合服务
if(isAudit==1){
maatCfg.initDefaultValue();
BeanUtils.copyProperties(entity, maatCfg);
maatCfg.setAction(entity.getAction());
maatCfg.setAuditTime(entity.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(entity.getIsValid());
configCompileList.add(maatCfg);
maatBean.setConfigCompileList(configCompileList);
maatBean.setAuditTime(entity.getAuditTime());
maatBean.setCreatorName(entity.getCurrentUser().getName());
maatBean.setVersion(Constants.MAAT_VERSION);
maatBean.setOpAction(Constants.INSERT_ACTION);
//调用服务接口下发配置数据
String json=gsonToJson(maatBean);
logger.info("ip配置下发配置参数"+json);
//调用服务接口下发配置
ToMaatResult result = ConfigServiceUtil.postMaatCfg(json);
logger.info("ip配置下发响应信息"+result.getMsg());
if(maatType==Constants.CALLBACK_TYPE){
List<InlineIp> ipList=new ArrayList<>();
for(IpPortCfg cfg :entity.getIpPortList()) {
BeanUtils.copyProperties(entity, cfg, new String[]{"cfgId"});
InlineIp ip=convertCallBackIp(cfg,null);
ipList.add(ip);
}
//调用服务接口下发配置数据
String json=gsonToJson(ipList);
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;
}
}else if(maatType==Constants.MAAT_TYPE){
maatCfg.initDefaultValue();
BeanUtils.copyProperties(entity, maatCfg);
maatCfg.setAction(entity.getAction());
maatCfg.setAuditTime(entity.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(entity.getIsValid());
configCompileList.add(maatCfg);
maatBean.setConfigCompileList(configCompileList);
maatBean.setAuditTime(entity.getAuditTime());
maatBean.setCreatorName(entity.getCurrentUser().getName());
maatBean.setVersion(Constants.MAAT_VERSION);
maatBean.setOpAction(Constants.INSERT_ACTION);
//调用服务接口下发配置数据
String json=gsonToJson(maatBean);
logger.info("ip配置下发配置参数"+json);
//调用服务接口下发配置
ToMaatResult result = ConfigServiceUtil.postMaatCfg(json);
logger.info("ip配置下发响应信息"+result.getMsg());
}else {
throw new RuntimeException("<spring:message code=\"request_service_failed\"/>:"+props.getProperty("unknown_cfg_type"));
}
}else if(isAudit==3){
maatCfg.setCompileId(entity.getCompileId());
maatCfg.setServiceId(entity.getServiceId());
maatCfg.setIsValid(0);//无效
configCompileList.add(maatCfg);
maatBean.setConfigCompileList(configCompileList);
maatBean.setAuditTime(entity.getAuditTime());
maatBean.setCreatorName(entity.getCurrentUser().getName());
maatBean.setVersion(Constants.MAAT_VERSION);
maatBean.setOpAction(Constants.UPDATE_ACTION);
//调用服务接口取消配置
String json=gsonToJson(maatBean);
logger.info("ip配置下发配置参数"+json);
//调用服务接口下发配置
ToMaatResult result = ConfigServiceUtil.put(json,1);
logger.info("ip配置取消配置响应信息:"+result.getMsg());
if(maatType==Constants.CALLBACK_TYPE){
List<InlineIp> ipList=new ArrayList<>();
for(IpPortCfg cfg :entity.getIpPortList()) {
BeanUtils.copyProperties(entity, cfg, new String[]{"cfgId"});
InlineIp ip=convertCallBackIp(cfg,null);
ipList.add(ip);
}
//调用服务接口下发配置数据
String json=gsonToJson(ipList);
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;
}
}else if(maatType==Constants.MAAT_TYPE){
maatCfg.setCompileId(entity.getCompileId());
maatCfg.setServiceId(entity.getServiceId());
maatCfg.setIsValid(0);//无效
configCompileList.add(maatCfg);
maatBean.setConfigCompileList(configCompileList);
maatBean.setAuditTime(entity.getAuditTime());
maatBean.setCreatorName(entity.getCurrentUser().getName());
maatBean.setVersion(Constants.MAAT_VERSION);
maatBean.setOpAction(Constants.UPDATE_ACTION);
//调用服务接口取消配置
String json=gsonToJson(maatBean);
logger.info("ip配置下发配置参数"+json);
//调用服务接口下发配置
ToMaatResult result = ConfigServiceUtil.put(json,1);
logger.info("ip配置取消配置响应信息"+result.getMsg());
}else {
throw new RuntimeException("<spring:message code=\"request_service_failed\"/>:"+props.getProperty("unknown_cfg_type"));
}
}
}
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)
@@ -740,10 +799,10 @@ public class IpCfgService extends CrudService<IpCfgDao,BaseIpCfg> {
}
return msgProp;
}
public Page<CfgIndexInfo> getWhiteIpList(Page<CfgIndexInfo> page, CfgIndexInfo entity) {
public Page<CfgIndexInfo> getIpCfgList(Page<CfgIndexInfo> page, CfgIndexInfo entity) {
entity.getSqlMap().put("dsf", configScopeFilter(entity.getCurrentUser(),"a"));
entity.setPage(page);
List<CfgIndexInfo> list = ipCfgDao.getWhiteIpList(entity);
List<CfgIndexInfo> list = ipCfgDao.getIpCfgList(entity);
page.setList(list);
return page;
}