1、规则删去策略模板、防护对象。增加sdl字段

2、任务增加策略模板、防护对象
3、相应地方修改
This commit is contained in:
PushM
2024-05-28 02:21:58 +08:00
parent df19bef4fa
commit 388201a97f
22 changed files with 428 additions and 359 deletions

View File

@@ -22,8 +22,7 @@ public class AlertMessageService {
private final AlertMessageMapper alertMessageMapper;
public AlertMessageService(
CommandService commandService,
AlertMessageMapper alertMessageMapper) {
CommandService commandService, AlertMessageMapper alertMessageMapper) {
this.commandService = commandService;
this.alertMessageMapper = alertMessageMapper;
}

View File

@@ -15,14 +15,10 @@ public interface DynamicRuleMapper {
//新建动态规则
void newDynamicRule(@Param("object") DynamicRuleObject dynamicRuleObject);
//新建动态规则与保护对象关联
Boolean newDynamicRulProtectObjectConcat(long dynamicRuleId, Integer protectObjectId);
void deleteDynamicRuleObject(Integer dynamicRuleId);
DynamicRuleObject queryDynamicRuleById(Integer dynamicRuleId);
List<ProtectObject> queryProtectObjectByRuleId(Integer dynamicRuleId);
Boolean updateDynamicRuleObject(@Param("dynamicRuleId") Integer dynamicRuleId, @Param("object") DynamicRuleObject dynamicRuleObject);
@@ -36,12 +32,6 @@ public interface DynamicRuleMapper {
String auditUserName, String createDate,
Integer page, Integer pageSize);
void deleteDynamicRuleProtectObjectConcat(Integer dynamicRuleId);
TemplateNew queryTemplateByRuleId(Integer dynamicRuleId);
boolean newDynamicRulProtectObjectsConcat(Integer dynamicRuleId, List<Integer> protectObjectIds);
boolean queryProtectObjectById(Integer protectObjectId);
Integer queryDynamicRuleTotalNum(String dynamicRuleName, Integer dynamicRuleId,

View File

@@ -1,7 +1,6 @@
package com.realtime.protection.server.rule.dynamicrule;
import com.alibaba.excel.util.ListUtils;
import com.realtime.protection.configuration.entity.defense.template.TemplateNew;
import com.realtime.protection.configuration.entity.rule.dynamicrule.DynamicRuleObject;
import com.realtime.protection.configuration.utils.Counter;
import com.realtime.protection.configuration.utils.SqlSessionWrapper;
@@ -33,13 +32,6 @@ public class DynamicRuleService {
@Transactional
public Integer newDynamicRuleObject(DynamicRuleObject dynamicRule) {
//判断protectObject id是否有效
boolean ProtectObjIdValid = dynamicRule.getProtectObjectIds().stream()
.allMatch(dynamicRuleMapper::queryProtectObjectById);
if (!ProtectObjIdValid) {
throw new IllegalArgumentException("protect object id is invalid");
}
dynamicRule.setDynamicRuleDisplayId(
"DTGZ-"
+ LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMdd"))
@@ -48,11 +40,8 @@ public class DynamicRuleService {
);
dynamicRuleMapper.newDynamicRule(dynamicRule);
Integer dynamicRuleId = dynamicRule.getDynamicRuleId();
dynamicRule.getProtectObjectIds().forEach(
protectObjectId -> dynamicRuleMapper.newDynamicRulProtectObjectConcat(dynamicRuleId, protectObjectId));
return dynamicRuleId;
return dynamicRule.getDynamicRuleId();
}
//批量新建多个动态规则
@@ -117,20 +106,7 @@ public class DynamicRuleService {
//查询DynamicRule
DynamicRuleObject dynamicRuleObject = dynamicRuleMapper.queryDynamicRuleById(dynamicRuleId);
if (dynamicRuleObject == null){
throw new IllegalArgumentException("dynamic rule id is invalid");
}
//查询DynamicRule关联的ProtectObject
dynamicRuleObject.setProtectObjects(dynamicRuleMapper.queryProtectObjectByRuleId(dynamicRuleId));
//查询DynamicRule关联的template详细信息
TemplateNew template = dynamicRuleMapper.queryTemplateByRuleId(dynamicRuleId);
if (template == null){
//template在表中删除了需要重新设置template感觉这种情况不多见
dynamicRuleObject.setDynamicRuleSourceSystem(null);
dynamicRuleObject.setDynamicRuleEventType(null);
}else{
dynamicRuleObject.setDynamicRuleSourceSystem(template.getSourceSystem());
dynamicRuleObject.setDynamicRuleEventType(template.getTemplateName());
dynamicRuleObject.setDynamicRuleProtectLevel(Integer.valueOf(template.getProtectLevel()));
throw new IllegalArgumentException("动态规则不存在");
}
return dynamicRuleObject;
@@ -139,22 +115,24 @@ public class DynamicRuleService {
@Transactional
public boolean updateDynamicRuleObject(Integer dynamicRuleId, DynamicRuleObject dynamicRuleObject) {
//更新DynamicRule
dynamicRuleObject.setDynamicRuleModifyTime(LocalDateTime.now());
// dynamicRuleMapper
Boolean idValid = dynamicRuleMapper.updateDynamicRuleObject(dynamicRuleId, dynamicRuleObject);
if (!idValid) {
throw new IllegalArgumentException("dynamic rule id is invalid");
throw new IllegalArgumentException("动态规则id无效");
}
/*
//删除DynamicRule关联的ProtectObject
dynamicRuleMapper.deleteDynamicRuleProtectObjectConcat(dynamicRuleId);
//新增DynamicRule关联的ProtectObject
boolean ProtectObjIdValid = dynamicRuleObject.getProtectObjectIds().stream()
.allMatch(dynamicRuleMapper::queryProtectObjectById);
if (!ProtectObjIdValid) {
throw new IllegalArgumentException("protect object id is invalid");
throw new IllegalArgumentException("防护对象id无效");
}
return dynamicRuleMapper.newDynamicRulProtectObjectsConcat(dynamicRuleId, dynamicRuleObject.getProtectObjectIds());
*/
return idValid;
}
// 批量删除
@@ -233,11 +211,7 @@ public class DynamicRuleService {
return resultMap;
}
/**
* 用于任务状态修改时,内部批量更新任务所属动态规则的状态,不需要修改审批人信息
* @param idsWithAuditStatusMap
* @return
*/
public Object updateAuditStatusBatch(Map<Integer, Integer> idsWithAuditStatusMap) {
//校验id和status是否合法
List<Integer> originalAuditStatusList = dynamicRuleMapper.queryAuditStatusByIds(idsWithAuditStatusMap);

View File

@@ -98,6 +98,7 @@ public class TaskController implements TaskControllerApi {
@RequestParam(value = "event_type", required = false) String eventType,
@RequestParam(value = "create_time", required = false) LocalDate createTime,
@RequestParam(value = "start_time", required = false) LocalDate startTime,
@RequestParam(value = "protect_level", required = false) Integer protectLevel,
@RequestParam("page") @Min(1) Integer page,
@RequestParam("page_size") @Min(1) Integer pageSize) {
@@ -112,11 +113,11 @@ public class TaskController implements TaskControllerApi {
}
List<Task> tasks = taskService.queryTasks(taskStatus, taskType, taskName, taskCreator, auditStatus,
taskAct, taskAuditor, taskSource, ruleName,
eventType, createDateStr, startTimeStr, page, pageSize);
eventType, createDateStr, startTimeStr,protectLevel, page, pageSize);
return ResponseResult.ok()
.setData("task_list", tasks)
.setData("total_num", taskService.queryTaskTotalNum(taskStatus, taskType, taskName, taskCreator, auditStatus,
taskAct, taskAuditor, taskSource, ruleName,eventType, createDateStr, startTimeStr));
taskAct, taskAuditor, taskSource, ruleName,eventType, createDateStr, startTimeStr,protectLevel));
}
@Override
@@ -140,6 +141,8 @@ public class TaskController implements TaskControllerApi {
.setData("success", taskService.updateTask(task));
}
@Override
@GetMapping("/{taskId}/audit/{auditStatus}")
public ResponseResult changeTaskAuditStatus(@PathVariable @NotNull @Max(10) Integer auditStatus,
@@ -254,11 +257,11 @@ public class TaskController implements TaskControllerApi {
public ResponseResult statistics() {
return ResponseResult.ok()
.setData("total_num", taskService.queryTaskTotalNum(null, null, null, null, null,
null, null, null, null,null,null,null))
null, null, null, null,null,null,null,null))
.setData("running_num", taskService.queryTaskTotalNum(StateEnum.RUNNING.getStateNum(), null, null, null, null,
null, null, null, null,null,null,null))
null, null, null, null,null,null,null,null))
.setData("finished_num", taskService.queryTaskTotalNum(StateEnum.FINISHED.getStateNum(), null, null, null, null,
null, null, null, null,null,null,null))
null, null, null, null,null,null,null,null))
.setData("unaudit_num", taskService.queryAuditTaskTotalNum(
AuditStatusEnum.PENDING.getNum()
));

View File

@@ -193,6 +193,7 @@ public interface TaskControllerApi {
@Parameter(name = "task_source", description = "任务来源系统"),
@Parameter(name = "rule_name", description = "规则名称"),
@Parameter(name = "event_type", description = "事件类型"),
@Parameter(name = "protect_level", description = "防护等级"),
@Parameter(name = "create_time", description = "任务创建时间",example = "2021-01-01" ),
@Parameter(name = "start_time", description = "任务开始时间",example = "2024-04-25" ),
@@ -212,6 +213,7 @@ public interface TaskControllerApi {
@RequestParam(value = "event_type", required = false) String eventType,
@RequestParam(value = "create_time", required = false) LocalDate createTime,
@RequestParam(value = "start_time", required = false) LocalDate startTime,
@RequestParam(value = "protect_level", required = false) Integer protectLevel,
@RequestParam("page") @Min(1) Integer page,
@RequestParam("page_size") @Min(1) Integer pageSize);

View File

@@ -1,5 +1,6 @@
package com.realtime.protection.server.task;
import com.realtime.protection.configuration.entity.defense.object.ProtectObject;
import com.realtime.protection.configuration.entity.task.DynamicTaskInfo;
import com.realtime.protection.configuration.entity.task.Task;
import com.realtime.protection.configuration.entity.task.TaskCommandInfo;
@@ -31,6 +32,7 @@ public interface TaskMapper {
@Param("event_type")String eventType,
@Param("create_date") String createDateStr,
@Param("start_date")String startDateStr,
@Param("protect_level")Integer protectLevel,
@Param("page") Integer page, @Param("page_size") Integer pageSize);
Task queryTask(@Param("task_id") Long taskId);
@@ -78,7 +80,8 @@ public interface TaskMapper {
@Param("task_create_time") LocalDateTime taskCreateTime,
@Param("event_type")String eventType,
@Param("create_date")String createDate,
@Param("start_date")String startDate);
@Param("start_date")String startDate,
@Param("protect_level")Integer protectLevel);
void updateAuditStatusByIdBatch(@Param("idWithAuditStatusBatch") Map<Integer, Integer> idWithAuditStatusBatch);
@@ -94,4 +97,11 @@ public interface TaskMapper {
@Param("auditUserName")String auditUserName,
@Param("auditUserId")String auditUserId,
@Param("auditUserDepart")String auditUserDepart);
void newTaskProtectObjectConcat(@Param("taskId")Long taskId,
@Param("protectObjectIds")List<Integer> protectObjectIds);
void deleteTaskProtectObjectConcat(Long taskId);
List<ProtectObject> queryProtectObjectsByTaskId(Long id);
}

View File

@@ -2,6 +2,7 @@ package com.realtime.protection.server.task;
import com.alibaba.excel.util.MapUtils;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.realtime.protection.configuration.entity.defense.object.ProtectObject;
import com.realtime.protection.configuration.entity.rule.dynamicrule.DynamicRuleObject;
import com.realtime.protection.configuration.entity.rule.staticrule.StaticRuleObject;
import com.realtime.protection.configuration.entity.task.DynamicTaskInfo;
@@ -10,6 +11,7 @@ import com.realtime.protection.configuration.entity.task.TaskCommandInfo;
import com.realtime.protection.configuration.utils.Counter;
import com.realtime.protection.configuration.utils.SqlSessionWrapper;
import com.realtime.protection.configuration.utils.enums.StateEnum;
import com.realtime.protection.configuration.utils.enums.TaskTypeEnum;
import com.realtime.protection.configuration.utils.enums.audit.AuditStatusEnum;
import com.realtime.protection.configuration.utils.enums.audit.AuditStatusValidator;
import com.realtime.protection.server.rule.dynamicrule.DynamicRuleMapper;
@@ -54,6 +56,7 @@ public class TaskService {
// task.setTaskCreateUsername("xxx");
// task.setTaskCreateDepart("xxx");
task.setTaskDisplayId(
"RW-"
+ LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMdd"))
@@ -61,7 +64,6 @@ public class TaskService {
+ String.format("%06d", counter.generateId("task")));
taskMapper.newTask(task);
if (task.getStaticRuleIds() != null && !task.getStaticRuleIds().isEmpty()) {
staticRuleMapper.queryStaticRuleByIds(task.getStaticRuleIds()).forEach(staticRuleObject -> {
if (!staticRuleObject.getAuditStatus().equals(AuditStatusEnum.AUDITED.getNum())) {
@@ -86,6 +88,17 @@ 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) {
throw new IllegalArgumentException("部分防护对象不存在");
}
//任务和防护对象多对多关联建立
taskMapper.newTaskProtectObjectConcat(task.getTaskId(), task.getProtectObjectIds());
}
return task.getTaskId();
}
@@ -219,10 +232,11 @@ public class TaskService {
String taskAct, String taskAuditor,
String taskSource, String ruleName,
String eventType,String createDateStr, String startDateStr,
Integer protectLevel,
Integer page, Integer pageSize) {
List<Task> tasks = taskMapper.queryTasks(taskStatus, taskType, taskName, taskCreator, auditStatus,
taskAct, taskAuditor, taskSource, ruleName,eventType, createDateStr, startDateStr, page, pageSize);
taskAct, taskAuditor, taskSource, ruleName,eventType, createDateStr, startDateStr,protectLevel, page, pageSize);
for (Task task : tasks) {
if (task == null) {
continue;
@@ -243,6 +257,8 @@ public class TaskService {
if (task == null) {
return null;
}
List<ProtectObject> protectObjects = taskMapper.queryProtectObjectsByTaskId(id);
task.setProtectObjects(protectObjects);
task.setStaticRuleIds(taskMapper.queryStaticRuleIdsFromTaskId(task.getTaskId(),
List.of(AuditStatusEnum.AUDITED.getNum(), AuditStatusEnum.USING.getNum())));
@@ -260,7 +276,20 @@ public class TaskService {
task.setTaskAuditStatus(AuditStatusEnum.PENDING.getNum());
//校验防护对象是否存在
boolean ProtectObjIdValid = task.getProtectObjectIds().stream()
.allMatch(dynamicRuleMapper::queryProtectObjectById);
if (!ProtectObjIdValid) {
throw new IllegalArgumentException("部分防护对象不存在");
}
//删除task关联的protectObjects
taskMapper.deleteTaskProtectObjectConcat(task.getTaskId());
//更新task
taskMapper.updateTask(task);
//重新关联task和protectObjects
taskMapper.newTaskProtectObjectConcat(task.getTaskId(), task.getProtectObjectIds());
taskMapper.clearTaskConnectedStaticRule(task.getTaskId());
taskMapper.clearTaskConnectedDynamicRule(task.getTaskId());
@@ -354,9 +383,9 @@ public class TaskService {
public Integer queryTaskTotalNum(Integer taskStatus, Integer taskType, String taskName, String taskCreator, Integer auditStatus
,String taskAct, String taskAuditor, String taskSource, String ruleName,
String eventType, String createDate, String startDate) {
String eventType, String createDate, String startDate,Integer protectLevel) {
return taskMapper.queryTaskTotalNum(taskStatus, taskType, taskName, taskCreator, auditStatus,
taskAct, taskAuditor, taskSource, ruleName,null, eventType, createDate, startDate);
taskAct, taskAuditor, taskSource, ruleName,null, eventType, createDate, startDate, protectLevel);
}
public Boolean updateAuditStatusBatch(Map<Integer, Integer> idsWithAuditStatusMap) {