1、修改非maat配置取消接口请求参数;

2、添加maat配置 配置存储接口中service与action对应关系验证
This commit is contained in:
zhangdongxu
2018-06-04 15:14:52 +08:00
parent 9071c087d5
commit 1219fe0bc1
9 changed files with 223 additions and 291 deletions

View File

@@ -1,64 +0,0 @@
/**
*
*/
package com.nis.domain.restful;
import java.io.Serializable;
import com.wordnik.swagger.annotations.ApiModelProperty;
/**
* @ClassName:CancleConfigSource
* @Description:TODO(这里用一句话描述这个类的作用)
* @author (zdx)
* @date 2018年6月1日 下午6:08:09
* @version V1.0
*/
public class UpdateStatConfig implements Serializable{
private static final long serialVersionUID = 6346336602908201877L;
@ApiModelProperty(value = "配置ID", required = true)
private Long cfgId;
@ApiModelProperty(value = "业务ID", required = true)
private Integer service;
@ApiModelProperty(value = "是否有效", required = true)
private Integer isValid;
/**
*
*/
public UpdateStatConfig() {
super();
// TODO Auto-generated constructor stub
}
/**
* @param cfgId
* @param service
* @param isValid
*/
public UpdateStatConfig(Long cfgId, Integer service, Integer isValid) {
super();
this.cfgId = cfgId;
this.service = service;
this.isValid = isValid;
}
public Long getCfgId() {
return cfgId;
}
public void setCfgId(Long cfgId) {
this.cfgId = cfgId;
}
public Integer getService() {
return service;
}
public void setService(Integer service) {
this.service = service;
}
public Integer getIsValid() {
return isValid;
}
public void setIsValid(Integer isValid) {
this.isValid = isValid;
}
}

View File

@@ -1,47 +0,0 @@
/**
*
*/
package com.nis.domain.restful;
import java.io.Serializable;
import java.util.List;
/**
* @ClassName:CancleConfigSource
* @Description:TODO(这里用一句话描述这个类的作用)
* @author (zdx)
* @date 2018年6月1日 下午6:08:09
* @version V1.0
*/
public class UpdateStatConfigSource implements Serializable{
/**
*
*/
private static final long serialVersionUID = 277603807201929340L;
private List<UpdateStatConfig> UpdateStatCfgList;
/**
*
*/
public UpdateStatConfigSource() {
super();
// TODO Auto-generated constructor stub
}
/**
* @param cancleConfigList
*/
public UpdateStatConfigSource(List<UpdateStatConfig> UpdateStatCfgList) {
super();
this.UpdateStatCfgList = UpdateStatCfgList;
}
public List<UpdateStatConfig> getUpdateStatCfgList() {
return UpdateStatCfgList;
}
public void setUpdateStatCfgList(List<UpdateStatConfig> updateStatCfgList) {
UpdateStatCfgList = updateStatCfgList;
}
}

View File

@@ -681,9 +681,11 @@ public class CompileVal {
public static String serviceConfigCompileVal(ConfigCompile configCompile) {
Long compileId = configCompile.getCompileId();
if (configCompile.getAction() != 1 && configCompile.getAction() != 2 && configCompile.getAction() != 5
&& configCompile.getAction() != 6 && configCompile.getAction() != 7) {
return "编译配置id为" + compileId + "的配置中action的值只能是1(阻断),2(监测),5(封堵白名单),6(监测白名单),7(封堵监测都白名单)";
Integer action = ServiceAndRDBIndexReal.getActionByService(configCompile.getService());
if (StringUtil.isEmpty(action)){
return "编译配置id为" + compileId + "的配置中service的值为"+configCompile.getService()+"时action不存在";
}else if(action.compareTo(configCompile.getAction())!=0) {
return "编译配置id为" + compileId + "的配置中service的值为"+configCompile.getService()+"时action只能为"+action;
}
if (configCompile.getDoBlacklist() != 1) {
return "编译配置id为" + compileId + "的配置中doBlacklist的值只能是1";

View File

@@ -24,13 +24,18 @@ public class ServiceAndRDBIndexReal {
* key是业务类型,value是业务类型对应的redisdbIndex
*/
private static Map<Integer, List<Integer>> serviceDBIndexmap = new HashMap<Integer, List<Integer>>();
/**
* key是业务类型,value是业务类型对应的动作(action)
*/
private static Map<Integer, Integer> serviceActionMap = new HashMap<Integer, Integer>();
static {
String service = Configurations.getStringProperty("service", "");
if (service != null && !service.trim().equals("")) {
String[] split = service.split(";");
for (String str : split) {
String type = Configurations.getStringProperty(str, "");
String[] serviceAction = str.split(":");
serviceActionMap.put(Integer.valueOf(serviceAction[0]), Integer.valueOf(serviceAction[1]));
String type = Configurations.getStringProperty(serviceAction[0], "");
if (type != null && !type.trim().equals("")) {
Map<Integer, String> typeMap = new HashMap<Integer, String>();
String[] typeArrs = type.split(";");
@@ -41,7 +46,7 @@ public class ServiceAndRDBIndexReal {
typeMap.put(Integer.parseInt(typeArr[0]), tableName.toUpperCase());
}
}
sercieNameMap.put(Integer.parseInt(str), typeMap);
sercieNameMap.put(Integer.parseInt(serviceAction[0]), typeMap);
}
}
@@ -88,6 +93,9 @@ public class ServiceAndRDBIndexReal {
}
}
public static Integer getActionByService(Integer service) {
return serviceActionMap.get(service);
}
public static Map<Integer, Map<Integer, String>> getSercieNameMap() {
return sercieNameMap;

View File

@@ -27,7 +27,6 @@ import com.nis.domain.restful.ConfigCompile;
import com.nis.domain.restful.ConfigSource;
import com.nis.domain.restful.FileDesc;
import com.nis.domain.restful.MaatConfig;
import com.nis.domain.restful.UpdateStatConfigSource;
import com.nis.restful.RestBusinessCode;
import com.nis.restful.RestServiceException;
import com.nis.util.Constants;
@@ -503,19 +502,17 @@ public class ConfigSourcesController extends BaseRestController {
@RequestMapping(value = "/cfg/v1/commonSources", method = RequestMethod.PUT)
@ApiOperation(value = "回调配置状态修改", httpMethod = "PUT", response = Map.class, notes = "回调配置状态修改服务")
@ApiParam(value = "回调配置状态修改", name = "updateStatConfigSource", required = true)
public Map updateCommonConfigSource(@RequestBody UpdateStatConfigSource updateStatConfigSource,
HttpServletRequest request, HttpServletResponse response) {
public Map updateCommonConfigSource(@RequestBody String jsonString, HttpServletRequest request,
HttpServletResponse response) {
ConfigSourcesService.setMsgList(new ArrayList<Exception>());// 清除上次记录的日志信息
long start = System.currentTimeMillis();
SaveRequestLogThread thread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_PUT, request,
updateStatConfigSource);
SaveRequestLogThread thread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_PUT, request,jsonString);
StringBuffer sb = new StringBuffer();
configSourcesService.updateCommonSources(thread, start, updateStatConfigSource.getUpdateStatCfgList(),
new Date(), sb);
configSourcesService.updateCommonSources(thread, start,jsonString, new Date(),sb);
return compileServiceResponse(thread, System.currentTimeMillis() - start, request, response, "配置状态修改成功",
Constants.IS_DEBUG ? updateStatConfigSource : null);
return compileServiceResponse(thread, System.currentTimeMillis() - start, request, response,
"配置状态修改成功" , Constants.IS_DEBUG ? jsonString : null);
}
@RequestMapping(value = "/cfg/v1/fileUploadSources", method = RequestMethod.POST)
@@ -564,8 +561,8 @@ public class ConfigSourcesController extends BaseRestController {
e.printStackTrace();
}
JSONObject jsonObj = new JSONObject();
jsonObj.put("accessUrl", filePath.substring(filePath.indexOf("group")));
// jsonObj.put("accessUrl", "filePath");
// jsonObj.put("accessUrl", filePath.substring(filePath.indexOf("group")));
jsonObj.put("accessUrl", "filePath");
return compileServiceResponse(thread, System.currentTimeMillis() - start, request, response, "文件上传成功", jsonObj);
}
@@ -606,7 +603,8 @@ public class ConfigSourcesController extends BaseRestController {
// meta_list[4] = new NameValuePair("fileMd5", md5);
logger.info("-----------------调用接口上传文件---------------");
String filePath = FileManager.upload(fdsfile, null);
resultObject.put("path", filePath.substring(filePath.indexOf("group")));
// resultObject.put("path", filePath.substring(filePath.indexOf("group")));
resultObject.put("path", filePath);
}
CommonsMultipartFile filetemp = (CommonsMultipartFile) file;

View File

@@ -18,6 +18,8 @@ import java.util.concurrent.CountDownLatch;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import net.sf.json.JSONObject;
import org.apache.ibatis.session.ExecutorType;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
@@ -38,7 +40,6 @@ import com.nis.domain.restful.IpRegion;
import com.nis.domain.restful.MaatConfig;
import com.nis.domain.restful.NumRegion;
import com.nis.domain.restful.StrRegion;
import com.nis.domain.restful.UpdateStatConfig;
import com.nis.restful.CompileJudgeCode;
import com.nis.restful.RestBusinessCode;
import com.nis.restful.RestServiceException;
@@ -61,8 +62,6 @@ import com.nis.web.service.BaseService;
import com.nis.web.service.SaveRequestLogThread;
import com.nis.web.service.SpringContextHolder;
import net.sf.json.JSONObject;
/**
* @ClassName: ControlService
* @Description: TODO(编译配置持久化)
@@ -2566,31 +2565,40 @@ public class ConfigSourcesService extends BaseService {
return "ok";
}
public String updateCommonSources(SaveRequestLogThread thread, long start, List<UpdateStatConfig> updateStatCfgList,
public String updateCommonSources(SaveRequestLogThread thread, long start,String jsonString,
Date opTime, StringBuffer sb) {
JsonArray jsonObjectList = null;
try {
jsonObjectList = new JsonParser().parse(jsonString).getAsJsonArray();
} catch (Exception e) {
// TODO: handle exception
logger1.error(e.getMessage());
thread.setExceptionInfo(e.getMessage() + sb.toString());
throw new RestServiceException(thread, System.currentTimeMillis() - start, e.getMessage() + sb.toString(),
RestBusinessCode.config_integrity_error.getValue());
}
//<service,cfgIdList>
Map<Integer, List<Long>> cfgMap = new HashMap<Integer, List<Long>>();
if (null != updateStatCfgList && updateStatCfgList.size() > 0) {
for (UpdateStatConfig config : updateStatCfgList) {
String msg = checkOptForUpdate(config);
for (int i = 0; i < jsonObjectList.size(); i++) {
JsonObject jsonObj=(JsonObject) jsonObjectList.get(i);
Map<String, Object> srcMap = JSONObject.fromObject(JSONObject.fromObject((jsonObj.toString())));
String msg = checkOptForUpdate(srcMap);
if (!msg.equals("ok")) {
thread.setExceptionInfo(msg + sb.toString());
throw new RestServiceException(thread, System.currentTimeMillis() - start, msg + sb.toString(),
RestBusinessCode.config_integrity_error.getValue());
}
if (cfgMap.containsKey(config.getService())) {
cfgMap.get(config.getService()).add(config.getCfgId());
Integer service = Integer.valueOf(srcMap.get("service").toString());
Long cfgId = Long.valueOf(srcMap.get("cfgId").toString());
if (cfgMap.containsKey(service)) {
cfgMap.get(service).add(cfgId);
} else {
List<Long> idList = new ArrayList<Long>();
idList.add(config.getCfgId());
cfgMap.put(config.getService(), idList);
idList.add(cfgId);
cfgMap.put(service, idList);
}
}
} else {
thread.setExceptionInfo("配置列表不能为空" + sb.toString());
throw new RestServiceException(thread, System.currentTimeMillis() - start, "配置列表不能为空" + sb.toString(),
RestBusinessCode.config_integrity_error.getValue());
}
Map<Integer, Map<Integer, List<Long>>> restMap = new HashMap<Integer, Map<Integer, List<Long>>>();
Iterator serviceIterator = cfgMap.keySet().iterator();
while (serviceIterator.hasNext()) {
@@ -2610,22 +2618,31 @@ public class ConfigSourcesService extends BaseService {
return "ok";
}
private String checkOptForUpdate(UpdateStatConfig config) {
if (StringUtil.isEmpty(config.getCfgId())) {
private String checkOptForUpdate(Map<String, Object> srcMap) {
String cfgId = srcMap.get("cfgId").toString();
String service = srcMap.get("service").toString();
String isValid = srcMap.get("isValid").toString();
if (StringUtil.isEmpty(cfgId)) {
return "cfgId字段不能为空";
}else if(!StringUtil.isNumeric(cfgId)){
return "cfgId字段格式不正确";
}
if (StringUtil.isEmpty(config.getService())) {
if (StringUtil.isEmpty(service)) {
return "service字段不能为空";
}else if(!StringUtil.isNumeric(service)){
return "service字段格式不正确";
}
if (StringUtil.isEmpty(config.getIsValid())) {
return "配置id为" + config.getCfgId()+"IsValid字段不能为空";
if (StringUtil.isEmpty(isValid)) {
return "配置id为" + srcMap.get("cfgId")+"isValid字段不能为空";
}else {
if(!StringUtil.isNumeric(service)){
return "isValid字段格式不正确";
}else if(!isValid.equals("0")){
return "isValid字段取值只能是0(失效)";
}
if (config.getIsValid() != 0) {
return "配置id为" + config.getCfgId() + "的配置在修改时不能为有效";
}
return "ok";
}
private boolean isIp(String ipStr){

View File

@@ -45,7 +45,7 @@
</p:expressions>
</p:maatType>
<p:maatType service="3;1;80;82;84;144;146;148">
<p:maatType service="17;1;80;82;84;144;146;148">
<p:expressions>
<p:keyExpression>EFFECTIVE_RULE;:;{compile_table_name};,;[compile_id]</p:keyExpression>
<p:valueExpression>[compile_id];\t;[service];\t;[action];\t;[do_blacklist];\t;[do_log];\t;[effective_range];\t;[user_region];\t;[is_valid];\t;[group_num];\t;[father_cfg_id];\t;[op_time]</p:valueExpression>

View File

@@ -5,11 +5,12 @@
####3:例如:80=10:MM_COMPILE;11:MM_GROUP;12:AV_CONT_IP_PORT
####4:type中10代表是编译配置,11代表是分组配置,12代表是ip类域配置,13代表是数值类配置,14代表是字符串类域配置,15代表是增强字符串类域配置,16代表是文件摘要类域配置,17代表是文本相似性域配置
#################################################################################
service=3;1;80;81;82;83;84;85;144;145;146;147;148;149
service=1:128;2:128;3:32;4:96;16:48;17:16;18:16;19:16;20:16;21:16;22:16;23:16;24:16;25:32;26:16;27:16;28:32;29:32;30:16;31:16;128:1;129:1;130:1;131:1;132:1;133:1;134:1;135:1;136:1;137:1;138:1;139:1;140:1;141:1;256:16;257:16;258:16;259:16;260:16;261:16;262:16;263:16;264:16;265:16;266:16;384:1;385:1;386:1;387:1;388:1;389:1;390:1;391:1;392:1;393:1;394:1;512:1;513:1;528:48;529:48;544:2;545:2;560:80;561:80;1024:16
3=10:NTC_COMPILE;11:NTC_GROUP;12:NTC_UNIVERSAL_IP
17=10:NTC_COMPILE;11:NTC_GROUP;12:NTC_UNIVERSAL_IP
1=10:WHITE_LIST_COMPILE;11:WHITE_LIST_GROUP;12:WHITE_LIST_IP
80=10:MM_COMPILE;11:MM_GROUP;12:MM_AV_IP
81=10:MM_COMPILE;11:MM_GROUP;14:MM_AV_URL

View File

@@ -178,9 +178,18 @@ public class RestTest {
System.out.println("2018-05-23 13:48:11"+"def:"+time+" "+date.getTime()+" 差:"+(time-date.getTime())/(60*60*1000));
System.out.println(utileDate2TimeStamp(t));
System.out.println("=====--------------------------------------------------");
Calendar calendar2 = Calendar.getInstance();
calendar2.setTimeZone(TimeZone.getTimeZone("UTC"));
calendar2.setTimeInMillis(1527229532956l);
System.out.println(calendar2.getTime());
Calendar calendar3 = Calendar.getInstance();
calendar3.setTimeZone(TimeZone.getTimeZone("UTC+8"));
calendar3.setTimeInMillis(1527229532956l);
System.out.println(calendar3.getTime());
} catch (Exception e) {
// TODO Auto-generated catch block
@@ -198,14 +207,14 @@ public class RestTest {
// calendar.setTime(df2.parse(date));
// TimeZone timeZone = TimeZone.getTimeZone("GMT+8:00");
// calendar.setTimeZone(timeZone);
//
//
// User test = new User();
// test.setId("111");
// test.setDate(calendar.getTime());
// ObjectMapper objectMapper = new ObjectMapper();
// String json = objectMapper.writeValueAsString(test);
// System.out.println(json);
//
//
// User restore = objectMapper.readValue(json, User.class);
// //System.out.print(restore.getDate().getTimeZone().getDisplayName());
// }catch (Exception e) {
@@ -213,4 +222,12 @@ public class RestTest {
// }
}
private java.sql.Timestamp utileDate2TimeStamp(java.util.Date udate) {
java.sql.Timestamp sqlDate = null;
long t = udate.getTime();
sqlDate = new java.sql.Timestamp(t);
return sqlDate;
}
}