From c8c5b5347677826abb900e50bade42da18986d5b Mon Sep 17 00:00:00 2001 From: PushM <584406942@qq.com> Date: Thu, 30 May 2024 02:51:14 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E9=94=99=E8=AF=AF=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=E6=94=B9=E4=B8=BA=E4=B8=AD=E6=96=87=202=E3=80=81=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1=E5=AE=A1=E6=A0=B8bug=203=E3=80=81=E6=8C=87=E4=BB=A4?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E4=B8=8D=E5=88=A4=E6=96=AD=E6=8C=87=E4=BB=A4?= =?UTF-8?q?=E6=98=AF=E5=90=A6=E8=A2=AB=E5=88=A0=E9=99=A4=204=E3=80=81bugfi?= =?UTF-8?q?x?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../entity/alert/AlertMessage.java | 2 +- .../rule/staticrule/StaticRuleObject.java | 2 +- .../entity/task/DynamicTaskInfo.java | 3 +++ .../defense/template/TemplateService.java | 4 ++-- .../protection/server/task/TaskService.java | 22 ++++++++++--------- .../server/whitelist/WhiteListService.java | 6 ++--- src/main/resources/mappers/CommandMapper.xml | 4 +++- src/main/resources/mappers/TaskMapper.xml | 3 +-- .../server/task/TaskServiceTest.java | 10 +++++---- 9 files changed, 32 insertions(+), 24 deletions(-) diff --git a/src/main/java/com/realtime/protection/configuration/entity/alert/AlertMessage.java b/src/main/java/com/realtime/protection/configuration/entity/alert/AlertMessage.java index f24d89c..89942f8 100644 --- a/src/main/java/com/realtime/protection/configuration/entity/alert/AlertMessage.java +++ b/src/main/java/com/realtime/protection/configuration/entity/alert/AlertMessage.java @@ -34,7 +34,7 @@ public class AlertMessage { private String modifyTime; @JsonProperty("alert_message_uuid") private String alertMessageUUID; - +//1代表防护对象命中告警信息里的是目的ip,0代表防护对象命中告警信息里的是源ip @JsonProperty("protect_object_is_src_dst") private int protectIsSrcOrDst; } diff --git a/src/main/java/com/realtime/protection/configuration/entity/rule/staticrule/StaticRuleObject.java b/src/main/java/com/realtime/protection/configuration/entity/rule/staticrule/StaticRuleObject.java index fd8c315..8269e66 100644 --- a/src/main/java/com/realtime/protection/configuration/entity/rule/staticrule/StaticRuleObject.java +++ b/src/main/java/com/realtime/protection/configuration/entity/rule/staticrule/StaticRuleObject.java @@ -135,7 +135,7 @@ public class StaticRuleObject { private String staticRuleURL; @JsonProperty("static_rule_priority") - @ExcelProperty("优先级") + @ExcelIgnore @Max(value = 3) @Min(value = 1) @Schema(description = "优先级,1代表高2代表中3代表低", example = "1") diff --git a/src/main/java/com/realtime/protection/configuration/entity/task/DynamicTaskInfo.java b/src/main/java/com/realtime/protection/configuration/entity/task/DynamicTaskInfo.java index 14f442b..dfad8b4 100644 --- a/src/main/java/com/realtime/protection/configuration/entity/task/DynamicTaskInfo.java +++ b/src/main/java/com/realtime/protection/configuration/entity/task/DynamicTaskInfo.java @@ -85,6 +85,9 @@ public class DynamicTaskInfo { public void parseSql() { String bwSql = this.bwSql; + if (bwSql == null) { + return; + } //解析SQL语句 SQLStatementParser parser = new MySqlStatementParser(bwSql); // 使用Parser解析生成AST,这里SQLStatement就是AST diff --git a/src/main/java/com/realtime/protection/server/defense/template/TemplateService.java b/src/main/java/com/realtime/protection/server/defense/template/TemplateService.java index a63b153..305055d 100644 --- a/src/main/java/com/realtime/protection/server/defense/template/TemplateService.java +++ b/src/main/java/com/realtime/protection/server/defense/template/TemplateService.java @@ -112,10 +112,10 @@ public class TemplateService { public Map updateAuditStatus(Integer id, Integer auditStatus) { Integer originalAuditStatus = templateMapper.queryAuditStatusById(id); if (originalAuditStatus == null) { - throw new IllegalArgumentException("cannot find audit status of static rule " + id + ", maybe static rule doesn't exist?"); + throw new IllegalArgumentException("不能找到静态规则:" + id + ", 可能静态规则不存在?"); } if (!AuditStatusValidator.setOriginal(originalAuditStatus).checkValidate(auditStatus)) { - throw new IllegalArgumentException("invalid audit status"); + throw new IllegalArgumentException("审核状态修改不合逻辑"); } Boolean success = templateMapper.updateAuditStatusById(id, auditStatus); diff --git a/src/main/java/com/realtime/protection/server/task/TaskService.java b/src/main/java/com/realtime/protection/server/task/TaskService.java index df05451..89a2548 100644 --- a/src/main/java/com/realtime/protection/server/task/TaskService.java +++ b/src/main/java/com/realtime/protection/server/task/TaskService.java @@ -88,17 +88,19 @@ public class TaskService { }); taskMapper.newTaskDynamicRuleConcat(task.getTaskId(), task.getDynamicRuleIds()); } - if (task.getTaskType() != TaskTypeEnum.STATIC.getTaskType()){ - //校验防护对象是否存在 - boolean ProtectObjIdValid = task.getProtectObjectIds().stream() - .allMatch(dynamicRuleMapper::queryProtectObjectById); - if (!ProtectObjIdValid && !task.getProtectObjectIds().isEmpty()){ - throw new IllegalArgumentException("部分防护对象不存在"); - } - //任务和防护对象多对多关联建立 - taskMapper.newTaskProtectObjectConcat(task.getTaskId(), task.getProtectObjectIds()); - } + if (task.getTaskType() != TaskTypeEnum.STATIC.getTaskType()) { + if (task.getProtectObjectIds() != null && !task.getProtectObjectIds().isEmpty()) { + //校验防护对象是否存在 + boolean ProtectObjIdValid = task.getProtectObjectIds().stream() + .allMatch(dynamicRuleMapper::queryProtectObjectById); + if (!ProtectObjIdValid) { + throw new IllegalArgumentException("部分防护对象不存在"); + } + //任务和防护对象多对多关联建立 + taskMapper.newTaskProtectObjectConcat(task.getTaskId(), task.getProtectObjectIds()); + } + } return task.getTaskId(); } diff --git a/src/main/java/com/realtime/protection/server/whitelist/WhiteListService.java b/src/main/java/com/realtime/protection/server/whitelist/WhiteListService.java index 693630c..dc7ca00 100644 --- a/src/main/java/com/realtime/protection/server/whitelist/WhiteListService.java +++ b/src/main/java/com/realtime/protection/server/whitelist/WhiteListService.java @@ -151,7 +151,7 @@ public class WhiteListService { StaticRuleObject staticRuleObject = staticRuleMapper.queryStaticRuleById(ruleId); if (staticRuleObject == null) { - throw new IllegalArgumentException("invalid rule id"); + throw new IllegalArgumentException("无效的静态规则"); } // 命中的whitelist列表:每一列包含ip port url return whiteListMapper.existWhiteListObject(staticRuleObject); @@ -192,11 +192,11 @@ public class WhiteListService { //查询目前curStatus Integer originalAuditStatus = whiteListMapper.queryWhiteListObjectAuditStuatusById(id); if (originalAuditStatus == null){ - throw new IllegalArgumentException("cannot find audit status of whitelist " + id + ", maybe whitelist doesn't exist?"); + throw new IllegalArgumentException("不能找到白名单 " + id + ", 可能该白名单不存在"); } //判断是否可以修改 if (!AuditStatusValidator.setOriginal(originalAuditStatus).checkValidate(auditStatus)) { - throw new IllegalArgumentException("invalid audit status"); + throw new IllegalArgumentException("审核状态修改违规"); } Boolean success = whiteListMapper.updateWhiteListObjectAuditStatus(id, auditStatus); diff --git a/src/main/resources/mappers/CommandMapper.xml b/src/main/resources/mappers/CommandMapper.xml index 9cef982..fee5ed7 100644 --- a/src/main/resources/mappers/CommandMapper.xml +++ b/src/main/resources/mappers/CommandMapper.xml @@ -61,6 +61,8 @@ + + @@ -107,7 +109,7 @@ FROM t_command AND TASK_ID = #{task_id} - AND IS_DELETED = FALSE +-- AND IS_DELETED = FALSE AND SRC_IP = #{src_ip} AND DST_IP = #{dst_ip} AND SRC_PORT = #{src_port} diff --git a/src/main/resources/mappers/TaskMapper.xml b/src/main/resources/mappers/TaskMapper.xml index b145dd3..f64292e 100644 --- a/src/main/resources/mappers/TaskMapper.xml +++ b/src/main/resources/mappers/TaskMapper.xml @@ -257,12 +257,11 @@ UPDATE t_task - SET task_status = #{audit_status}, + SET task_audit_status = #{audit_status}, task_modify_time = NOW(), task_audit_username = #{auditUserName}, task_audit_userid = #{auditUserId}, task_audit_depart = #{auditUserDepart} - WHERE task_id = #{task_id} diff --git a/src/test/java/com/realtime/protection/server/task/TaskServiceTest.java b/src/test/java/com/realtime/protection/server/task/TaskServiceTest.java index 9fba250..dbf3e39 100644 --- a/src/test/java/com/realtime/protection/server/task/TaskServiceTest.java +++ b/src/test/java/com/realtime/protection/server/task/TaskServiceTest.java @@ -210,9 +210,11 @@ class TaskServiceTest extends ProtectionApplicationTests { // map.put(43830, 1); // map.put(43831, 1); // map.put(43832, 1); - - // System.out.println(taskService.updateAuditStatusBatch(map)); + + System.out.println(taskService.changeTaskAuditStatus(44047L, 2, null, null, null)); + + } @Test void testGetDynamicTaskInfos(){ @@ -308,7 +310,7 @@ class TaskServiceTest extends ProtectionApplicationTests { object.setDynamicRulePriority(1); object.setDynamicRuleSourceSystem("bw"); // object.setDynamicRuleSourceSystem("bw"); - object.setBwSql("select c_src_ipv4,c_src_port,c_dest_ipv4,c_dest_port from topic_xxxxxx where c_event_id in (11113333311,222222222222) and c_netnum = 111111111 and c_flowid=22222222" ); +// object.setBwSql("select c_src_ipv4,c_src_port,c_dest_ipv4,c_dest_port from topic_xxxxxx where c_event_id in (11113333311,222222222222) and c_netnum = 111111111 and c_flowid=22222222" ); // object.setDynamicRuleRange("北京"); // object.setDynamicRuleProtectLevel(1); // object.setLogRuleId(1L); @@ -338,7 +340,7 @@ class TaskServiceTest extends ProtectionApplicationTests { task.setSourceSystem(templates.get(0).getSourceSystem()); task.setTemplateId(templates.get(0).getTemplateId()); - task.setProtectObjectIds(List.of(new Integer[]{protectObject.get(0).getProtectObjectId()})); +// task.setProtectObjectIds(List.of(new Integer[]{protectObject.get(0).getProtectObjectId()})); Long taskId = taskService.newTask(task); System.out.println(taskId);