增加ssl配置功能

This commit is contained in:
zhangwei
2018-05-31 17:07:26 +08:00
parent 6eafbf6f59
commit df4f6e68ae
16 changed files with 545 additions and 114 deletions

View File

@@ -41,7 +41,8 @@ public class CfgIndexInfo extends BaseCfg<CfgIndexInfo> {
private List<HttpResHeadCfg> httpResHdrList;
private List<HttpBodyCfg> httpReqBodyList;
private List<HttpBodyCfg> httpResBodyList;
private SslKeywordCfg sslCfg;
private List<BaseStringCfg> sslList;
public AvVoipAccountCfg getVoipAccount() {
return voipAccount;
@@ -61,6 +62,18 @@ public class CfgIndexInfo extends BaseCfg<CfgIndexInfo> {
public void setVoipIp(AvVoipIpCfg voipIp) {
this.voipIp = voipIp;
}
public SslKeywordCfg getSslCfg() {
return sslCfg;
}
public void setSslCfg(SslKeywordCfg sslCfg) {
this.sslCfg = sslCfg;
}
public List<BaseStringCfg> getSslList() {
return sslList;
}
public void setSslList(List<BaseStringCfg> sslList) {
this.sslList = sslList;
}
public void setVoipIps(List<AvVoipIpCfg> voipIps) {
this.voipIps = voipIps;
}
@@ -142,5 +155,4 @@ public class CfgIndexInfo extends BaseCfg<CfgIndexInfo> {
public static String getTablename() {
return tableName;
}
}

View File

@@ -15,8 +15,8 @@ package com.nis.domain.configuration;
* @date 2018年2月6日 上午8:59:51
* @version V1.0
*/
public class SslKeywordCfg extends ComplexkeywordCfg{
public static final String tableName="ssl_cert_cfg";
public class SslKeywordCfg extends BaseStringCfg{
public static final String tableName="ssl_keyword_cfg";
/**
* @Fields serialVersionUID:TODO用一句话描述这个变量表示什么
*
@@ -36,5 +36,9 @@ public class SslKeywordCfg extends ComplexkeywordCfg{
this.matchMethod=3;
this.isHexbin=0;
}
public static String getTablename() {
return tableName;
}
}

View File

@@ -295,6 +295,9 @@ public final class Constants {
public static final Integer INSERT_ACTION = Configurations.getIntProperty("insert_action",1);
public static final Integer UPDATE_ACTION = Configurations.getIntProperty("update_action",2);
public static final Integer DELETE_ACTION = Configurations.getIntProperty("delete_action",3);
public static final String SSL_IP_REGION = Configurations.getStringProperty("ssl_ip_region","ssl_ip");
public static final String SSL_SNI_REGION = Configurations.getStringProperty("ssl_sni_region","ssl_sni");
public static final String SSL_SAN_REGION = Configurations.getStringProperty("ssl_san_region","ssl_san");
public static final String SSL_CA_REGION = Configurations.getStringProperty("ssl_ca_region","ssl_ca");
}

View File

@@ -2,7 +2,9 @@ package com.nis.web.controller.configuration.ntc;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@@ -17,16 +19,20 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import com.nis.domain.FunctionRegionDict;
import com.nis.domain.Page;
import com.nis.domain.configuration.BaseIpCfg;
import com.nis.domain.configuration.BaseStringCfg;
import com.nis.domain.configuration.CfgIndexInfo;
import com.nis.domain.configuration.HttpBodyCfg;
import com.nis.domain.configuration.HttpReqHeadCfg;
import com.nis.domain.configuration.HttpResHeadCfg;
import com.nis.domain.configuration.HttpUrlCfg;
import com.nis.domain.configuration.IpPortCfg;
import com.nis.domain.configuration.SslKeywordCfg;
import com.nis.exceptions.MaatConvertException;
import com.nis.util.Constants;
import com.nis.util.DictUtils;
import com.nis.web.controller.BaseController;
import com.nis.web.security.UserUtils;
@@ -43,7 +49,7 @@ public class WebsiteController extends BaseController{
@RequiresPermissions(value={"website:http:config"})
public String httpList(Model model,@ModelAttribute("cfg")CfgIndexInfo cfg,HttpServletRequest request,HttpServletResponse response) {
Page<CfgIndexInfo> searchPage=new Page<CfgIndexInfo>(request,response,"a");
Page<CfgIndexInfo> page = websiteCfgService.getHttpList(searchPage, cfg);
Page<CfgIndexInfo> page = websiteCfgService.getWebsiteList(searchPage, cfg);
model.addAttribute("page", page);
initPageCondition(model,cfg);
return "/cfg/website/httpList";
@@ -57,6 +63,7 @@ public class WebsiteController extends BaseController{
initPageCondition(model,cfg);
return "/cfg/website/dnsList";
}
@RequestMapping(value = {"httpForm"})
@RequiresPermissions(value={"website:http:config"})
public String httpForm(Model model,String ids,CfgIndexInfo entity) {
@@ -146,6 +153,7 @@ public class WebsiteController extends BaseController{
model.addAttribute("_cfg", entity);
return "/cfg/website/httpForm";
}
@RequestMapping(value = {"saveHttpCfg"})
@RequiresPermissions(value={"website:http:config"})
public String saveHttpCfg(Model model,HttpServletRequest request,HttpServletResponse response,String ids,CfgIndexInfo entity) {
@@ -187,4 +195,87 @@ public class WebsiteController extends BaseController{
}
return "redirect:" + adminPath +"/ntc/website/httpList?functionId="+functionId;
}
@RequestMapping(value = {"sslList"})
@RequiresPermissions(value={"website:ssl:config"})
public String sslList(Model model,@ModelAttribute("cfg")CfgIndexInfo cfg,HttpServletRequest request,HttpServletResponse response) {
Page<CfgIndexInfo> searchPage=new Page<CfgIndexInfo>(request,response,"a");
Page<CfgIndexInfo> page = websiteCfgService.getWebsiteList(searchPage, cfg);
model.addAttribute("page", page);
initPageCondition(model,cfg);
return "/cfg/website/sslList";
}
@RequestMapping(value = {"sslForm"})
@RequiresPermissions(value={"website:ssl:config"})
public String sslForm(Model model,String ids,CfgIndexInfo entity) {
if(StringUtils.isNotBlank(ids)){
entity = websiteCfgService.getSslCfg(Long.parseLong(ids));
model.addAttribute("areaCfgs", entity.getAreaCfg());
}
initFormCondition(model,entity);
model.addAttribute("_cfg", entity);
return "/cfg/website/sslForm";
}
@RequestMapping(value = {"saveSslCfg"})
@RequiresPermissions(value={"website:ssl:config"})
public String saveSslCfg(Model model,HttpServletRequest request,HttpServletResponse response,String ids,CfgIndexInfo entity) {
websiteCfgService.saveSslCfg(entity);
return "redirect:" + adminPath +"/ntc/website/sslList?functionId="+entity.getFunctionId();
}
@RequestMapping(value = {"ajaxSslSubList"})
public String ajaxSslSubList(Model model,Long cfgId,Integer index) {
CfgIndexInfo cfg = websiteCfgService.getSslCfg(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.getSslList()!=null){
String cfgType = null;
for(BaseStringCfg keyword:cfg.getSslList()){
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/website/sslSubList";
}
@RequestMapping(value = {"updateSslCfgValid"})
@RequiresPermissions(value={"website:ssl:config"})
public String updateSslCfgValid(Integer isValid,String ids,Integer functionId) {
websiteCfgService.updateSslCfgValid(isValid,ids,functionId);
return "redirect:" + adminPath +"/ntc/website/sslList?functionId="+functionId;
}
@RequestMapping(value = {"auditSslCfg"})
@RequiresPermissions(value={"website:ssl:audit"})
public String auditSslCfg(Integer isAudit,Integer isValid,String ids,Integer functionId, RedirectAttributes redirectAttributes) {
CfgIndexInfo entity = new CfgIndexInfo();
String[] idArray = ids.split(",");
for(String id :idArray){
entity = websiteCfgService.getHttpCfg(Long.parseLong(id));
entity.setIsAudit(isAudit);
entity.setIsValid(isValid);
entity.setAuditorId(UserUtils.getUser().getId());
entity.setAuditTime(new Date());
entity.setFunctionId(functionId);
try {
websiteCfgService.auditSslCfg(entity,isAudit);
} catch (MaatConvertException e) {
e.printStackTrace();
logger.info("ssl配置下发失败"+e.getMessage());
addMessage(redirectAttributes, e.getMessage());
}
}
return "redirect:" + adminPath +"/ntc/website/sslList?functionId="+functionId;
}
}

View File

@@ -5,6 +5,7 @@ import java.util.List;
import com.nis.domain.configuration.AvFileSampleCfg;
import com.nis.domain.configuration.AvSignSampleCfg;
import com.nis.domain.configuration.BaseCfg;
import com.nis.domain.configuration.BaseStringCfg;
import com.nis.domain.configuration.CfgIndexInfo;
import com.nis.domain.configuration.DnsDomainCfg;
import com.nis.domain.configuration.DnsIpCfg;
@@ -13,6 +14,7 @@ import com.nis.domain.configuration.HttpReqHeadCfg;
import com.nis.domain.configuration.HttpResHeadCfg;
import com.nis.domain.configuration.HttpUrlCfg;
import com.nis.domain.configuration.IpPortCfg;
import com.nis.domain.configuration.SslKeywordCfg;
import com.nis.web.dao.CrudDao;
import com.nis.web.dao.MyBatisDao;
@@ -26,7 +28,7 @@ import com.nis.web.dao.MyBatisDao;
public interface WebsiteCfgDao extends CrudDao<CfgIndexInfo>{
public CfgIndexInfo getCfgIndexInfo(Long id);
public List<CfgIndexInfo> getHttpList(CfgIndexInfo entity);
public List<CfgIndexInfo> getWebsiteList(CfgIndexInfo entity);
public List<IpPortCfg> getIpPortList(CfgIndexInfo entity);
public List<HttpUrlCfg> getHttpUrlList(CfgIndexInfo entity);
public List<HttpResHeadCfg> getHttpResHdrList(CfgIndexInfo entity);
@@ -34,7 +36,7 @@ public interface WebsiteCfgDao extends CrudDao<CfgIndexInfo>{
public List<HttpReqHeadCfg> getHttpReqHdrList(CfgIndexInfo entity);
public List<HttpBodyCfg> getHttpReqBodyList(CfgIndexInfo entity);
public void saveCfgIndex(CfgIndexInfo entity);
public void saveHttpIpCfg(IpPortCfg entity);
public void saveIpPortCfg(IpPortCfg entity);
public void saveHttpUrlCfg(HttpUrlCfg entity);
public void saveHttpReqHdrCfg(HttpReqHeadCfg entity);
public void saveHttpResHdrCfg(HttpResHeadCfg entity);
@@ -57,4 +59,9 @@ public interface WebsiteCfgDao extends CrudDao<CfgIndexInfo>{
public void deleteDnsIpCfg(CfgIndexInfo entity);
public void deleteDnsDomainCfg(CfgIndexInfo entity);
public List<BaseStringCfg> getSslKewordList(CfgIndexInfo entity);
public void saveSslKeywordCfg(BaseStringCfg entity);
public void deleteSslIpCfg(CfgIndexInfo entity);
public void deleteSslKeywordCfg(CfgIndexInfo entity);
}

View File

@@ -143,7 +143,7 @@
a.audit_time,a.service_id,a.request_id,a.compile_id,a.is_area_effective,a.classify,a.attribute,a.lable,
a.expr_type,a.match_method,a.is_hexbin,a.area_effective_ids,a.function_id,a.cfg_region_code
</sql>
<select id="getHttpList" resultMap="CfgIndexInfoMap" parameterType="com.nis.domain.configuration.CfgIndexInfo" >
<select id="getWebsiteList" resultMap="CfgIndexInfoMap" parameterType="com.nis.domain.configuration.CfgIndexInfo" >
SELECT
<include refid="ConfigIndex_Column" />
<trim prefix="," prefixOverrides=",">
@@ -289,6 +289,15 @@
</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>
@@ -320,7 +329,7 @@
<select id="getHttpReqBodyList" resultMap="stringCfgMap" parameterType="com.nis.domain.configuration.CfgIndexInfo">
SELECT
<include refid="StrCfg_Column" />
FROM http_body_cfg a where compile_id=#{compileId} and cfg_type='http_res_body' and function_id=#{functionId}
FROM http_body_cfg a where compile_id=#{compileId} and cfg_type='http_req_body' and function_id=#{functionId}
</select>
<select id="getHttpResBodyList" resultMap="stringCfgMap" parameterType="com.nis.domain.configuration.CfgIndexInfo">
SELECT
@@ -337,7 +346,14 @@
<include refid="ComplexCfg_Column" />
FROM http_res_head_cfg a where compile_id=#{compileId} and function_id=#{functionId}
</select>
<select id="getSslKewordList" resultMap="stringCfgMap" parameterType="com.nis.domain.configuration.CfgIndexInfo">
SELECT
<include refid="StrCfg_Column" />
FROM ssl_keyword_cfg a where compile_id=#{compileId} and function_id=#{functionId}
<if test="cfgType != null and cfgType != ''">
and a.cfg_type =#{cfgType,jdbcType=VARCHAR}
</if>
</select>
<!-- insert cfgIndexInfox -->
<insert id="saveCfgIndex" parameterType="com.nis.domain.configuration.CfgIndexInfo" >
<selectKey resultType="java.lang.Long" order="AFTER" keyProperty="cfgId">
@@ -386,7 +402,7 @@
)
</insert>
<!-- insert ip_port_cfg表信息 -->
<insert id="saveHttpIpCfg" parameterType="com.nis.domain.configuration.IpPortCfg" >
<insert id="saveIpPortCfg" parameterType="com.nis.domain.configuration.IpPortCfg" >
<selectKey resultType="java.lang.Long" order="AFTER" keyProperty="cfgId">
SELECT LAST_INSERT_ID()
</selectKey>
@@ -800,4 +816,71 @@
</trim>
</update>
<!-- insert ssl_keyword_cfg表信息 -->
<insert id="saveSslKeywordCfg" parameterType="com.nis.domain.configuration.SslKeywordCfg" >
<selectKey resultType="java.lang.Long" order="AFTER" keyProperty="cfgId">
SELECT LAST_INSERT_ID()
</selectKey>
insert into ssl_keyword_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,
cfg_keywords,
cfg_type,
cfg_region_code,
expr_type,
match_method,
is_hexbin
)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},
#{cfgKeywords,jdbcType=VARCHAR},
#{cfgType,jdbcType=VARCHAR},
#{cfgRegionCode,jdbcType=INTEGER},
#{exprType,jdbcType=INTEGER},
#{matchMethod,jdbcType=INTEGER},
#{isHexbin,jdbcType=INTEGER}
)
</insert>
<!-- 删除ssl子配置 -->
<delete id="deleteSslIpCfg" >
delete from ip_port_cfg where compile_id=#{compileId} and protocol_id=10 and function_id=#{functionId}
</delete>
<!-- 删除ssl关键字配置 -->
<delete id="deleteSslKeywordCfg">
delete from ssl_keyword_cfg where compile_id=#{compileId} and function_id=#{functionId}
</delete>
</mapper>

View File

@@ -267,13 +267,8 @@ public abstract class BaseService {
* @return
*/
public static Map<String,List> cfgConvert(List dstList,List srcList,Integer cfgType,BaseCfg baseCfg,List groupRelationList){
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);
Map<String,List> map = new HashMap();
String regionValue = null;
if(cfgType==1){
List numRegionList = new ArrayList();
Integer groupId = 0;
@@ -281,12 +276,22 @@ public abstract class BaseService {
BaseIpCfg baseIpCfg = (BaseIpCfg) srcList.get(i);
IpCfg cfg = new IpCfg();
BeanUtils.copyProperties(baseIpCfg, 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());
cfg = ipConvert(cfg,baseIpCfg);
dstList.add(cfg);
regionValue = cfg.getCfgType();
//如果protocolId非空非零需要构造数值型域配置
if(baseIpCfg.getProtocolId()!=null && baseIpCfg.getProtocolId()!=0){
if(groupId==0){//只构造一次配置分组
@@ -313,18 +318,35 @@ public abstract class BaseService {
}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);
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);
regionValue = cfg.getCfgType();
}
}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();
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());

View File

@@ -10,6 +10,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.BeansException;
import org.springframework.beans.FatalBeanException;
@@ -30,6 +31,7 @@ import com.nis.domain.configuration.HttpReqHeadCfg;
import com.nis.domain.configuration.HttpResHeadCfg;
import com.nis.domain.configuration.HttpUrlCfg;
import com.nis.domain.configuration.IpPortCfg;
import com.nis.domain.configuration.SslKeywordCfg;
import com.nis.domain.maat.MaatCfg;
import com.nis.domain.maat.MaatCfg.NumBoundaryCfg;
import com.nis.domain.maat.ToMaatBean;
@@ -80,11 +82,21 @@ public class WebsiteCfgService extends CrudService<WebsiteCfgDao,CfgIndexInfo> {
entity.setAreaCfg(areaCfg);
return entity;
}
public Page<CfgIndexInfo> getHttpList(Page<CfgIndexInfo> page, CfgIndexInfo entity){
public CfgIndexInfo getSslCfg(Long cfgId){
CfgIndexInfo entity = websiteCfgDao.getCfgIndexInfo(cfgId);
List<IpPortCfg> ipPortList = websiteCfgDao.getIpPortList(entity);
List<BaseStringCfg> sslList = websiteCfgDao.getSslKewordList(entity);
List<AreaIpCfg> areaCfg = areaIpCfgDao.getByCompileId(entity.getCompileId());
entity.setIpPortList(ipPortList);
entity.setSslList(sslList);
entity.setAreaCfg(areaCfg);
return entity;
}
public Page<CfgIndexInfo> getWebsiteList(Page<CfgIndexInfo> page, CfgIndexInfo entity){
// 生成数据权限过滤条件dsf为dataScopeFilter的简写在xml中使用 ${sqlMap.dsf}调用权限SQL
entity.getSqlMap().put("dsf", configScopeFilter(entity.getCurrentUser(),"a"));
entity.setPage(page);
List<CfgIndexInfo> list = websiteCfgDao.getHttpList(entity);
List<CfgIndexInfo> list = websiteCfgDao.getWebsiteList(entity);
page.setList(list);
return page;
}
@@ -96,24 +108,6 @@ public class WebsiteCfgService extends CrudService<WebsiteCfgDao,CfgIndexInfo> {
page.setList(list);
return page;
}
public List<IpPortCfg> getHttpIpList(IpPortCfg entity){
return null;
}
public List<HttpUrlCfg> getHttpUrlList(HttpUrlCfg entity){
return null;
}
public List<HttpResHeadCfg> getHttpResHdrList(HttpResHeadCfg entity){
return null;
}
public List<HttpBodyCfg> getHttpResBodyList(HttpBodyCfg entity){
return null;
}
public List<HttpReqHeadCfg> getHttpReqHdrList(HttpReqHeadCfg entity){
return null;
}
public List<HttpBodyCfg> getHttpReqBodyList(HttpBodyCfg entity){
return null;
}
public void saveHttpCfg(CfgIndexInfo entity){
if(entity.getCfgId()==null){
Integer compileId = 0;
@@ -129,7 +123,7 @@ public class WebsiteCfgService extends CrudService<WebsiteCfgDao,CfgIndexInfo> {
if(entity.getIpPortList()!=null){
for(IpPortCfg cfg:entity.getIpPortList()){
BeanUtils.copyProperties(entity, cfg,new String[]{"cfgRegionCode","cfgType"});
websiteCfgDao.saveHttpIpCfg(cfg);
websiteCfgDao.saveIpPortCfg(cfg);
}
}
if(entity.getHttpUrlList()!=null){
@@ -178,7 +172,6 @@ public class WebsiteCfgService extends CrudService<WebsiteCfgDao,CfgIndexInfo> {
}else{
websiteCfgDao.updateCfgIndex(entity);
// entity = websiteCfgDao.getCfgIndexInfo(entity.getCfgId());
//无效子配置后,再新增子配置
websiteCfgDao.deleteHttpIpCfg(entity);
websiteCfgDao.deleteHttpUrlCfg(entity);
@@ -194,7 +187,7 @@ public class WebsiteCfgService extends CrudService<WebsiteCfgDao,CfgIndexInfo> {
if(entity.getIpPortList()!=null){
for(IpPortCfg cfg:entity.getIpPortList()){
BeanUtils.copyProperties(entity, cfg,new String[]{"cfgRegionCode","cfgType"});
websiteCfgDao.saveHttpIpCfg(cfg);
websiteCfgDao.saveIpPortCfg(cfg);
}
}
if(entity.getHttpUrlList()!=null){
@@ -433,4 +426,216 @@ public class WebsiteCfgService extends CrudService<WebsiteCfgDao,CfgIndexInfo> {
logger.info("http配置取消配置响应信息"+result.getMsg());
}
}
public void saveSslCfg(CfgIndexInfo entity){
if(entity.getCfgId()==null){
Integer compileId = 0;
try {
List<Integer> idList = ConfigServiceUtil.getId(1, 1);
if(idList!=null && idList.size()>0){
compileId = idList.get(0);
}
entity.setCompileId(compileId);
entity.setCreateTime(new Date());
entity.setCreatorId(entity.getCurrentUser().getId());
websiteCfgDao.saveCfgIndex(entity);
if(entity.getIpPortList()!=null){
for(IpPortCfg cfg:entity.getIpPortList()){
BeanUtils.copyProperties(entity, cfg,new String[]{"cfgRegionCode","cfgType"});
websiteCfgDao.saveIpPortCfg(cfg);
}
}
if(entity.getSslList()!=null){
for(BaseStringCfg cfg:entity.getSslList()){
if(StringUtils.isNotBlank(cfg.getCfgKeywords())){
BeanUtils.copyProperties(entity, cfg,new String[]{"cfgRegionCode","cfgType"});
websiteCfgDao.saveSslKeywordCfg(cfg);
}
}
}
//保存区域IP信息
if(entity.getAreaCfg()!=null){
for(AreaIpCfg cfg:entity.getAreaCfg()){
cfg.initDefaultValue();
BeanUtils.copyProperties(entity, cfg,new String[]{"cfgRegionCode","cfgType"});
areaIpCfgDao.saveAreaIpCfg(cfg);
}
}
} catch (Exception e) {
e.printStackTrace();
logger.info("获取编译ID出错");
throw new MaatConvertException("<spring:message code=\"request_service_failed\"/>:"+e.getMessage());
}
}else{
websiteCfgDao.updateCfgIndex(entity);
//无效子配置后,再新增子配置
websiteCfgDao.deleteSslIpCfg(entity);
websiteCfgDao.deleteSslKeywordCfg(entity);
AreaIpCfg area = new AreaIpCfg();
area.setCompileId(entity.getCompileId());
area.setFunctionId(entity.getFunctionId());
areaIpCfgDao.deleteAreaIpCfg(area);
entity.setCreateTime(new Date());
entity.setCreatorId(entity.getCurrentUser().getId());
if(entity.getIpPortList()!=null){
for(IpPortCfg cfg:entity.getIpPortList()){
BeanUtils.copyProperties(entity, cfg,new String[]{"cfgRegionCode","cfgType"});
websiteCfgDao.saveIpPortCfg(cfg);
}
}
if(entity.getSslList()!=null){
for(BaseStringCfg cfg:entity.getSslList()){
if(StringUtils.isNotBlank(cfg.getCfgKeywords())){
BeanUtils.copyProperties(entity, cfg,new String[]{"cfgRegionCode","cfgType"});
websiteCfgDao.saveSslKeywordCfg(cfg);
}
}
}
//保存区域IP信息
if(entity.getAreaCfg()!=null){
for(AreaIpCfg cfg:entity.getAreaCfg()){
cfg.initDefaultValue();
BeanUtils.copyProperties(entity, cfg,new String[]{"cfgDesc","cfgRegionCode","cfgType"});
areaIpCfgDao.saveAreaIpCfg(cfg);
}
}
}
}
public void updateSslCfgValid(Integer isValid,String ids,Integer functionId){
CfgIndexInfo entity = new CfgIndexInfo();
String[] idArray = ids.split(",");
for(String id :idArray){
entity.setCfgId(Long.parseLong(id));
entity.setIsValid(isValid);
entity.setEditorId(UserUtils.getUser().getId());
entity.setEditTime(new Date());
entity.setTableName(CfgIndexInfo.getTablename());
entity.setFunctionId(functionId);
websiteCfgDao.updateCfgValid(entity);
//查询子配置
entity = this.getSslCfg(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());
websiteCfgDao.updateCfgValid(cfg);
}
if(entity.getSslList()!=null && entity.getSslList().size()>0)
{
SslKeywordCfg cfg = new SslKeywordCfg();
BeanUtils.copyProperties(entity, cfg, new String[]{"cfgId"});
cfg.setTableName(SslKeywordCfg.getTablename());
websiteCfgDao.updateCfgValid(cfg);
}
//保存区域IP信息
if(entity.getAreaCfg()!=null && entity.getAreaCfg().size()>0){
AreaIpCfg cfg = new AreaIpCfg();
BeanUtils.copyProperties(entity, cfg, new String[]{"cfgId"});
cfg.setTableName(AreaIpCfg.getTablename());
websiteCfgDao.updateCfgValid(cfg);
}
}
}
public void auditSslCfg(CfgIndexInfo entity,Integer isAudit) throws MaatConvertException{
//修改数据库审核状态信息
entity.setTableName(CfgIndexInfo.getTablename());
websiteCfgDao.auditCfg(entity);
ToMaatBean maatBean = new ToMaatBean();
MaatCfg maatCfg = new MaatCfg();
List<MaatCfg> configCompileList = new ArrayList();
List<GroupCfg> groupRelationList = new ArrayList();
List<IpCfg> ipRegionList = new ArrayList();
List<StringCfg> strRegionList = new ArrayList();
List<NumBoundaryCfg> numRegionList = new ArrayList();
List<DigestCfg> digestRegionList = new ArrayList();
List<IpCfg> areaIpRegionList = new ArrayList();
//查询子配置并修改审核状态
entity = this.getSslCfg(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());
websiteCfgDao.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"));
}
}
}
if(entity.getSslList()!=null && entity.getSslList().size()>0){
SslKeywordCfg cfg = new SslKeywordCfg();
BeanUtils.copyProperties(entity, cfg, new String[]{"cfgId"});
cfg.setTableName(SslKeywordCfg.getTablename());
websiteCfgDao.auditCfg(cfg);
if(isAudit==1){
Map<String,List> map = cfgConvert(strRegionList,entity.getSslList(),2,entity,groupRelationList);
groupRelationList=map.get("groupList");
strRegionList=map.get("dstList");
}
}
//保存区域IP信息
if(entity.getAreaCfg()!=null && entity.getAreaCfg().size()>0){
AreaIpCfg cfg = new AreaIpCfg();
BeanUtils.copyProperties(entity, cfg, new String[]{"cfgId"});
cfg.setTableName(AreaIpCfg.getTablename());
websiteCfgDao.auditCfg(cfg);
if(isAudit==1){
Map<String,List> map = cfgConvert(areaIpRegionList,entity.getAreaCfg(),1,entity,groupRelationList);
groupRelationList=map.get("groupList");
areaIpRegionList=map.get("dstList");
}
}
//构造提交综合服务参数格式,一条配置提交一次综合服务
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("ssl配置下发配置参数"+json);
//调用服务接口下发配置
ToMaatResult result = ConfigServiceUtil.postCallbackCfg(json);
logger.info("ssl配置下发响应信息"+result.getMsg());
}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("ssl配置下发配置参数"+json);
//调用服务接口下发配置
ToMaatResult result = ConfigServiceUtil.put(json,1);
logger.info("ssl配置取消配置响应信息"+result.getMsg());
}
}
}