增加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

@@ -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());
}
}
}