This repository has been archived on 2025-09-14. You can view files and clone it, but cannot push or open issues or pull requests.
Files
k18-ntcs-web-ntc/src/main/java/com/nis/web/controller/configuration/AppFeatureCfgController.java
2019-02-21 09:57:49 +08:00

456 lines
18 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package com.nis.web.controller.configuration;
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;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.taglibs.standard.functions.Functions;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import com.nis.domain.Page;
import com.nis.domain.configuration.AppComplexFeatureCfg;
import com.nis.domain.configuration.AppFeatureIndex;
import com.nis.domain.configuration.AppFeatureProperties;
import com.nis.domain.configuration.AppIpCfg;
import com.nis.domain.configuration.AppPolicyCfg;
import com.nis.domain.configuration.AppStringFeatureCfg;
import com.nis.domain.configuration.AppTcpCfg;
import com.nis.domain.configuration.IpPortCfg;
import com.nis.domain.specific.SpecificServiceCfg;
import com.nis.exceptions.MaatConvertException;
import com.nis.util.Constants;
import com.nis.util.StringUtil;
import com.nis.web.controller.BaseController;
import com.nis.web.security.UserUtils;
/**
* 特定协议相关配置控制类
*
* @author zhangwei
*
*/
@Controller
@RequestMapping("${adminPath}/app/feature/")
public class AppFeatureCfgController extends BaseController {
/**
* app协议复杂特征配置列表
*
* @param model
* @param cfg
* @param request
* @param response
* @return
*/
@RequestMapping(value = { "multiFeatureCfgList" })
public String multiFeatureCfgList(Model model, @ModelAttribute("cfg") AppFeatureIndex cfg,
HttpServletRequest request, HttpServletResponse response) {
Page<AppFeatureIndex> searchPage = new Page<AppFeatureIndex>(request, response, "r");
Page<AppFeatureIndex> page = appMultiFeatureCfgService.findAppFeatureIndexList(searchPage, cfg);
for (AppFeatureIndex entity : page.getList()) {
SpecificServiceCfg app = specificServiceCfgService.getBySpecServiceId(entity.getSpecServiceId());
entity.setAppName(app.getSpecServiceName());
}
model.addAttribute("page", page);
initPageCondition(model, cfg);
return "/cfg/app/appMultiFeatureCfgList";
}
/**
* 特征配置表单
*
* @param model
* @param ids
* @param entity
* @return
*/
@RequestMapping(value = { "multiFeatureCfgForm" })
public String multiFeatureCfgForm(Model model, String ids, AppFeatureIndex entity) {
if (StringUtils.isNotBlank(ids)) {
entity = appMultiFeatureCfgService.getAppFeatureIndex(Long.parseLong(ids));
entity.setIpPortList(
appMultiFeatureCfgService.getAppIpRangeCfg(entity.getCompileId(), entity.getFunctionId()));
entity.setStrList(appMultiFeatureCfgService.getAppStringFeatureCfg(entity.getCompileId(),
entity.getFunctionId(), null));
entity.setComplexList(appMultiFeatureCfgService.getAppComplexFeatureCfgNotRegionCode(entity.getCompileId(),
entity.getFunctionId(), 6));
entity.setSessionList(appMultiFeatureCfgService.getAppComplexFeatureCfg(entity.getCompileId(),
entity.getFunctionId(), 6));
entity.setNumCfgList(
appMultiFeatureCfgService.getAppTcpCfg(entity.getCompileId(), entity.getFunctionId(), null));
entity.setAppFeaturePropCfgList(appMultiFeatureCfgService.getAppFeaturePropCfg(entity.getCompileId(), entity.getFunctionId(), null));
initUpdateFormCondition(model, entity);
} else {
initFormCondition(model, entity);
}
// 获取L7 Protocol
SpecificServiceCfg specificServiceCfg = new SpecificServiceCfg();
specificServiceCfg.setCfgType(3);
List<SpecificServiceCfg> l7ProtoList = specificServiceCfgService.findAllSpecificServiceCfg(specificServiceCfg, null);
model.addAttribute("_cfg", entity);
model.addAttribute("l7ProtoList", l7ProtoList);
if(entity.getFunctionId() == 567) { // APP关联特征配置
return "/cfg/app/appCorrelationFeatureCfgForm";
}
return "/cfg/app/appMultiFeatureCfgForm";
}
/**
* 特征配置新增修改
*
* @param model
* @param request
* @param response
* @param entity
* @param redirectAttributes
* @return
*/
@RequestMapping(value = { "saveAppMultiFeatureCfg" })
public String saveAppMultiFeatureCfg(Model model, HttpServletRequest request, HttpServletResponse response,
AppFeatureIndex entity, RedirectAttributes redirectAttributes) {
try {
SpecificServiceCfg specificService = specificServiceCfgService
.getBySpecServiceId(entity.getSpecServiceId());
if (specificService != null) {
entity.setAppCode(specificService.getSpecServiceCode());
}
appMultiFeatureCfgService.saveOrUpdateAppFeatureCfg(entity);
addMessage(redirectAttributes, "success", "save_success");
} catch (Exception e) {
e.printStackTrace();
if (e instanceof MaatConvertException) {
addMessage(redirectAttributes, "error", "request_service_failed");
} else {
addMessage(redirectAttributes, "error", "save_failed");
}
}
return "redirect:" + adminPath + "/app/feature/multiFeatureCfgList?functionId=" + entity.getFunctionId();
}
/**
* 特征配置审核
*
* @param isAudit
* @param isValid
* @param ids
* @param functionId
* @param redirectAttributes
* @return
*/
@RequestMapping(value = { "auditAppFeatureCfg" })
public String auditAppFeatureCfg(Model model, @ModelAttribute("cfg") AppFeatureIndex cfg, Integer isValid,
Integer isAudit, String ids, Integer functionId, RedirectAttributes redirectAttributes,
HttpServletResponse response, HttpServletRequest request) {
if (!StringUtil.isEmpty(ids)) {
AppFeatureIndex entity = new AppFeatureIndex();
String[] idArray = ids.split(",");
for (String id : idArray) {
entity = appMultiFeatureCfgService.getAppFeatureIndex(Long.parseLong(id));
entity.setIsAudit(isAudit);
entity.setIsValid(isValid);
entity.setAuditorId(UserUtils.getUser().getId());
entity.setAuditTime(new Date());
entity.setFunctionId(functionId);
try {
appMultiFeatureCfgService.auditAppFeatureCfg(entity, isAudit);
addMessage(redirectAttributes, "success", "audit_success");
} catch (MaatConvertException e) {
e.printStackTrace();
logger.error("app 特征配置下发失败:" + e.getMessage());
addMessage(redirectAttributes, "error", "request_service_failed");
} catch (Exception e) {
e.printStackTrace();
logger.error("app 特征配置下发失败:" + e.getMessage());
addMessage(redirectAttributes, "error", "audit_failed");
}
}
} else {
Page<AppPolicyCfg> searchPage = new Page<AppPolicyCfg>(request, response, "r");
Page<AppPolicyCfg> auditPage = new Page<AppPolicyCfg>(request, response, "r");
try {
BeanUtils.copyProperties(searchPage, auditPage);
auditAll(auditPage, isValid, cfg);
addMessage(redirectAttributes, "success", "audit_success");
} catch (Exception e) {
logger.error("配置下发失败:", e);
if (e instanceof MaatConvertException) {
addMessage(redirectAttributes, "error", "request_service_failed");
} else {
addMessage(redirectAttributes, "error", "audit_failed");
}
}
return multiFeatureCfgList(model, cfg, request, response);
}
return "redirect:" + adminPath + "/app/feature/multiFeatureCfgList?functionId=" + functionId;
}
/**
* 特征配置删除
*
* @param isValid
* @param ids
* @param functionId
* @return
*/
@RequestMapping(value = { "updateAppFeatureCfgValid" })
public String updateAppFeatureCfgValid(Integer isValid, String ids, Integer functionId) {
appMultiFeatureCfgService.updateAppFeatureCfgValid(isValid, ids, functionId);
return "redirect:" + adminPath + "/app/feature/multiFeatureCfgList?functionId=" + functionId;
}
/**
* 查询特征子配置
*
* @param model
* @param cfgId
* @param index
* @return
*/
@RequestMapping(value = { "ajaxAppFeatureList" })
public String ajaxAppFeatureList(Model model, Long cfgId, Integer compileId, Integer functionId, Integer index) {
List<AppIpCfg> ipRangeList = appMultiFeatureCfgService.getAppIpRangeCfg(compileId, functionId);
AppFeatureIndex cfg = appMultiFeatureCfgService.getAppFeatureIndex(cfgId);
List<Map<String, Object>> tabList = new ArrayList();
String[] cfgRegionValue = cfg.getCfgRegionValue().split(",");
String[] cfgRegionType = cfg.getCfgRegionType().split(",");
String[] cfgRegionCode = cfg.getCfgRegionCode1().split(",");
if (cfgRegionValue.length == cfgRegionType.length && cfgRegionValue.length == cfgRegionCode.length) {
for (int i = 0; i < cfgRegionValue.length; i++) {
Map<String, Object> map = new HashMap();
map.put("regionType", cfgRegionType[i]);
map.put("regionValue", cfgRegionValue[i]);
if ("1".equals(cfgRegionType[i])) {
map.put("ipRangeList", ipRangeList);
}
if ("2".equals(cfgRegionType[i])) {
List<AppStringFeatureCfg> strList = appMultiFeatureCfgService.getAppStringFeatureCfg(compileId,
functionId, Integer.valueOf(cfgRegionCode[i]));
map.put("strList", strList);
}
if ("3".equals(cfgRegionType[i])) {
List<AppComplexFeatureCfg> complexList = appMultiFeatureCfgService
.getAppComplexFeatureCfg(compileId, functionId, Integer.valueOf(cfgRegionCode[i]));
map.put("complexList", complexList);
}
if ("4".equals(cfgRegionType[i])) {
List<AppTcpCfg> numCfgList = appMultiFeatureCfgService.getAppTcpCfg(compileId, functionId,
Integer.valueOf(cfgRegionCode[i]));
map.put("numCfgList", numCfgList);
}
if ("8".equals(cfgRegionType[i])) {
List<AppComplexFeatureCfg> sessionList = appMultiFeatureCfgService
.getAppComplexFeatureCfg(compileId, functionId, Integer.valueOf(cfgRegionCode[i]));
map.put("sessionList", sessionList);
}
if ("9".equals(cfgRegionType[i])) {
List<AppFeatureProperties> featureList = appMultiFeatureCfgService
.getAppFeaturePropCfg(compileId, functionId, null);
map.put("featureList", featureList);
}
tabList.add(map);
}
// 获取L7 Protocol
SpecificServiceCfg specificServiceCfg = new SpecificServiceCfg();
specificServiceCfg.setCfgType(3);
List<SpecificServiceCfg> l7ProtoList = specificServiceCfgService.findAllSpecificServiceCfg(specificServiceCfg, null);
model.addAttribute("l7ProtoList", l7ProtoList);
} else {
Map<String, Object> map = new HashMap();
map.put("regionType", "0");
map.put("regionValue", "query config detail error");
tabList.add(map);
}
/*
* if(ipRangeList!=null){ String cfgType = null; for(AppIpCfg
* ip:ipRangeList){ if(!ip.getCfgType().equals(cfgType)){
* tabList.add(new String[]{"1",ip.getCfgType()}); cfgType =
* ip.getCfgType(); } } } if(strList!=null){ String cfgType = null;
* for(AppStringFeatureCfg cfg:strList){
* if(!cfg.getCfgType().equals(cfgType)){ tabList.add(new
* String[]{"2",cfg.getCfgType()}); cfgType = cfg.getCfgType(); } } }
* if(complexList!=null){ String cfgType = null;
* for(AppComplexFeatureCfg cfg:complexList){
* if(!cfg.getCfgType().equals(cfgType)){ tabList.add(new
* String[]{"3",cfg.getCfgType()}); cfgType = cfg.getCfgType();0.
*
* } } }
*/
model.addAttribute("index", index);
model.addAttribute("tabList", tabList);
return "/cfg/app/appSubFeatureList";
}
// appfeature配置导出
@RequestMapping(value = "exportFeature")
public void exportFeature(Model model, HttpServletRequest request, HttpServletResponse response,
@ModelAttribute("cfg") AppFeatureIndex entity, String ids, RedirectAttributes redirectAttributes) {
try {
// export data info
List<String> titleList = new ArrayList<String>();
Map<String, Class<?>> classMap = new HashMap<String, Class<?>>();
Map<String, List> dataMap = new HashMap<String, List>();
Map<String, String> noExportMap = new HashMap<String, String>();
List<AppFeatureIndex> ipLists = new ArrayList<AppFeatureIndex>();
// 导出选中记录
if (!StringUtil.isEmpty(ids)) {
ipLists = appMultiFeatureCfgService.findAppByFeatureIndexList(ids);
} else {
Page<AppFeatureIndex> pageInfo = new Page<AppFeatureIndex>(request, response, "r");
pageInfo.setPageNo(1);
pageInfo.setPageSize(Constants.MAX_EXPORT_SIZE);
Page<AppFeatureIndex> page = appMultiFeatureCfgService.findAppFeatureIndexList(pageInfo, entity);
ipLists = page.getList();
}
for (AppFeatureIndex feature : ipLists) {
SpecificServiceCfg app = specificServiceCfgService.getBySpecServiceId(feature.getSpecServiceId());
feature.setAppName(app.getSpecServiceName());
}
String cfgIndexInfoNoExport = ",letter,whether_area_block,classification,attribute,label,do_log,block_type,client_port,ir_type,group_name,userregion1,userregion2,userregion3,userregion4,userregion5,";
String appComplexNoExport = ",do_log,block_type,config_describe,valid_identifier,is_audit,creator,creator"
+ ",config_time,editor,edit_time,auditor,audit_time"
+ ",letter,whether_area_block,classification,attribute,label"
+ ",userregion1,userregion2,userregion3,userregion4,userregion5,";
String ipPortInfoNoExport = ",do_log,block_type,config_describe,valid_identifier,is_audit,creator,creator"
+ ",config_time,editor,edit_time,auditor,audit_time"
+ ",letter,whether_area_block,classification,attribute,label"
+ ",userregion1,userregion2,userregion3,userregion4,userregion5,ir_type,group_name,";
// 时间过滤
if (entity.getSearch_create_time_start() == null && entity.getSearch_create_time_end() == null) {
cfgIndexInfoNoExport = ",config_time" + cfgIndexInfoNoExport;
}
if (entity.getSearch_edit_time_start() == null && entity.getSearch_edit_time_end() == null) {
cfgIndexInfoNoExport = ",edit_time" + cfgIndexInfoNoExport;
}
if (entity.getSearch_audit_time_start() == null && entity.getSearch_audit_time_end() == null) {
cfgIndexInfoNoExport = ",audit_time" + cfgIndexInfoNoExport;
}
if (!StringUtil.isEmpty(entity.gethColumns())) {
cfgIndexInfoNoExport = "," + entity.gethColumns() + "," + cfgIndexInfoNoExport;
}
titleList.add(entity.getMenuNameCode());
classMap.put(entity.getMenuNameCode(), AppFeatureIndex.class);
noExportMap.put(entity.getMenuNameCode(), cfgIndexInfoNoExport);
List<IpPortCfg> ipList = new ArrayList<IpPortCfg>();
List<AppComplexFeatureCfg> keywordList = new ArrayList<AppComplexFeatureCfg>();
List<AppStringFeatureCfg> strList = new ArrayList<AppStringFeatureCfg>();
for (AppFeatureIndex cfg : ipLists) {
Map<String, List> maps = appMultiFeatureCfgService.exportFeature(cfg);
if (entity.getFunctionId() != 567) {
keywordList.addAll(maps.get("APP_KEYWORDS"));
} else {
strList.addAll(maps.get("APP_DK_GL"));
}
ipList.addAll(maps.get("APP_IP_RANGE"));
}
dataMap.put(entity.getMenuNameCode(), ipLists);
if (entity.getFunctionId() != 564 && entity.getFunctionId() != 567) {
keywordList = replaceKeyList(keywordList);
titleList.add("APP_IP_RANGE");
classMap.put("APP_IP_RANGE", IpPortCfg.class);
noExportMap.put("APP_IP_RANGE", ipPortInfoNoExport);
dataMap.put("APP_IP_RANGE", ipList);
}
if (entity.getFunctionId() == 563) {
titleList.add("APP_PAYLOAD");
classMap.put("APP_PAYLOAD", AppComplexFeatureCfg.class);
noExportMap.put("APP_PAYLOAD", appComplexNoExport);
dataMap.put("APP_PAYLOAD", keywordList);
} else if (entity.getFunctionId() == 565) {
titleList.add("APP_HTTP");
classMap.put("APP_HTTP", AppComplexFeatureCfg.class);
noExportMap.put("APP_HTTP", appComplexNoExport);
dataMap.put("APP_HTTP", keywordList);
} else if (entity.getFunctionId() == 566) {
titleList.add("APP_SSL");
classMap.put("APP_SSL", AppComplexFeatureCfg.class);
noExportMap.put("APP_SSL", appComplexNoExport);
dataMap.put("APP_SSL", keywordList);
} else if (entity.getFunctionId() == 564) {
keywordList = replaceKeyList(keywordList);
titleList.add("APP_DNS");
classMap.put("APP_DNS", AppComplexFeatureCfg.class);
noExportMap.put("APP_DNS", appComplexNoExport);
dataMap.put("APP_DNS", keywordList);
} else if (entity.getFunctionId() == 567) {
strList = replaceFeatureList(strList);
appComplexNoExport = appComplexNoExport + "district,";
titleList.add("APP_DK");
classMap.put("APP_DK", AppStringFeatureCfg.class);
noExportMap.put("APP_DK", appComplexNoExport);
dataMap.put("APP_DK", strList);
}
/* } */
String timeRange = initTimeMap(entity);
noExportMap.put("timeRange", timeRange);
if ("csv".equals(entity.getExType())) {
this._exportCsv(model, request, response, redirectAttributes, entity.getMenuNameCode(), titleList,
classMap, dataMap, noExportMap);
} else {
this._export(model, request, response, redirectAttributes, entity.getMenuNameCode(), titleList,
classMap, dataMap, noExportMap);
}
} catch (Exception e) {
logger.error("Appfeature export failed", e);
addMessage(redirectAttributes, "error", "export_failed");
}
// return "redirect:" + adminPath
// +"/ntc/iplist/list?functionId="+entity.getFunctionId();
}
public static List<AppComplexFeatureCfg> replaceKeyList(List<AppComplexFeatureCfg> list) {
for (int i = 0; i < list.size(); i++) {
AppComplexFeatureCfg base = (AppComplexFeatureCfg) list.get(i);
base.setIsHex(base.getIsHexbin());
// '默认为0:大小写不敏感且非HEX;1:HEX格式二进制;2:大小写敏感且非HEX',
if(base.getIsHexbin()==2){
base.setIsCaseInsenstive(1);
}else{
base.setIsCaseInsenstive(0);
}
base.setCfgKeywords(Functions.replace(base.getCfgKeywords(), "***and***", " "));
}
return list;
}
public static List<AppStringFeatureCfg> replaceFeatureList(List<AppStringFeatureCfg> list) {
for (int i = 0; i < list.size(); i++) {
AppStringFeatureCfg base = (AppStringFeatureCfg) list.get(i);
base.setIsHex(base.getIsHexbin());
// '默认为0:大小写不敏感且非HEX;1:HEX格式二进制;2:大小写敏感且非HEX',
if(base.getIsHexbin()==2){
base.setIsCaseInsenstive(1);
}else{
base.setIsCaseInsenstive(0);
}
base.setCfgKeywords(Functions.replace(base.getCfgKeywords(), "***and***", " "));
}
return list;
}
}