Merge remote-tracking branch 'origin/master' into haskafka
This commit is contained in:
@@ -25,6 +25,7 @@ public class DynamicTaskInfo {
|
|||||||
private Integer ruleId;
|
private Integer ruleId;
|
||||||
private String sourceSystem;
|
private String sourceSystem;
|
||||||
private String eventType;
|
private String eventType;
|
||||||
|
private Long logRuleId;
|
||||||
|
|
||||||
// 从防护对象列表中获取
|
// 从防护对象列表中获取
|
||||||
private List<SimpleProtectObject> protectObjects;
|
private List<SimpleProtectObject> protectObjects;
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ public class AuditAdvice implements ResponseBodyAdvice<ResponseResult> {
|
|||||||
return null;
|
return null;
|
||||||
})
|
})
|
||||||
.doOnError(WebClientRequestException.class, err ->
|
.doOnError(WebClientRequestException.class, err ->
|
||||||
log.warn("审计服务器遭遇异常" + err.getMessage()));
|
log.warn("审计服务器遭遇异常{}", err.getMessage()));
|
||||||
|
|
||||||
mono.subscribe(AuditAdvice::handleMono);
|
mono.subscribe(AuditAdvice::handleMono);
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package com.realtime.protection.server.defense.object;
|
|||||||
import com.alibaba.excel.util.ListUtils;
|
import com.alibaba.excel.util.ListUtils;
|
||||||
import com.realtime.protection.configuration.entity.defense.object.ProtectObject;
|
import com.realtime.protection.configuration.entity.defense.object.ProtectObject;
|
||||||
import com.realtime.protection.configuration.utils.SqlSessionWrapper;
|
import com.realtime.protection.configuration.utils.SqlSessionWrapper;
|
||||||
|
import com.realtime.protection.configuration.utils.enums.audit.AuditStatusEnum;
|
||||||
import com.realtime.protection.configuration.utils.enums.audit.AuditStatusValidator;
|
import com.realtime.protection.configuration.utils.enums.audit.AuditStatusValidator;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
@@ -74,6 +75,14 @@ public class ProtectObjectService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Boolean updateProtectObject(ProtectObject protectObject) {
|
public Boolean updateProtectObject(ProtectObject protectObject) {
|
||||||
|
if (!protectObjectMapper.queryProtectObject(protectObject.getProtectObjectId())
|
||||||
|
.getProtectObjectAuditStatus()
|
||||||
|
.equals(AuditStatusEnum.AUDITED.getNum())) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
protectObject.setProtectObjectAuditStatus(AuditStatusEnum.PENDING.getNum());
|
||||||
|
|
||||||
return protectObjectMapper.updateProtectObject(protectObject);
|
return protectObjectMapper.updateProtectObject(protectObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -64,6 +64,13 @@ public class TemplateController implements TemplateControllerApi {
|
|||||||
return ResponseResult.ok().setData("template", template);
|
return ResponseResult.ok().setData("template", template);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@GetMapping("/query/level")
|
||||||
|
public ResponseResult queryTemplateProtectLevels() {
|
||||||
|
List<Template> templates = templateService.queryTemplatesShort();
|
||||||
|
return ResponseResult.ok().setData("templates", templates);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@PostMapping("/{templateId}/update")
|
@PostMapping("/{templateId}/update")
|
||||||
public ResponseResult updateTemplate(@PathVariable @Min(1) Integer templateId,
|
public ResponseResult updateTemplate(@PathVariable @Min(1) Integer templateId,
|
||||||
|
|||||||
@@ -41,7 +41,6 @@ public interface TemplateControllerApi {
|
|||||||
""",
|
""",
|
||||||
description = """
|
description = """
|
||||||
"success": 新建防御策略模板是否成功
|
"success": 新建防御策略模板是否成功
|
||||||
|
|
||||||
"template_id": 新建防御策略模板ID
|
"template_id": 新建防御策略模板ID
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
@@ -104,7 +103,8 @@ public interface TemplateControllerApi {
|
|||||||
"hasDNS": true
|
"hasDNS": true
|
||||||
},
|
},
|
||||||
"template_used_times": 0,
|
"template_used_times": 0,
|
||||||
"running_tasks": 0
|
"running_tasks": 0,
|
||||||
|
"description": "xxx"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"template_id": 24,
|
"template_id": 24,
|
||||||
@@ -140,7 +140,8 @@ public interface TemplateControllerApi {
|
|||||||
"hasDNS": true
|
"hasDNS": true
|
||||||
},
|
},
|
||||||
"template_used_times": 0,
|
"template_used_times": 0,
|
||||||
"running_tasks": 0
|
"running_tasks": 0,
|
||||||
|
"description": "xxx"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"total_num": 708
|
"total_num": 708
|
||||||
@@ -231,7 +232,8 @@ public interface TemplateControllerApi {
|
|||||||
"hasDNS": true
|
"hasDNS": true
|
||||||
},
|
},
|
||||||
"template_used_times": 0,
|
"template_used_times": 0,
|
||||||
"running_tasks": 0
|
"running_tasks": 0,
|
||||||
|
"description": "xxx"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -261,6 +263,58 @@ public interface TemplateControllerApi {
|
|||||||
)
|
)
|
||||||
ResponseResult queryTemplate(@PathVariable Integer templateId) throws IllegalAccessException;
|
ResponseResult queryTemplate(@PathVariable Integer templateId) throws IllegalAccessException;
|
||||||
|
|
||||||
|
@GetMapping("/query/level")
|
||||||
|
@Operation(
|
||||||
|
summary = "查询所有策略模板是否含有不同类型防护等级",
|
||||||
|
description = "查询所有的策略模板是否还有日常态/应急态/紧急态三种防护等级",
|
||||||
|
responses = {
|
||||||
|
@ApiResponse(
|
||||||
|
description = "返回策略模板防护等级信息",
|
||||||
|
content = @Content(
|
||||||
|
mediaType = "application/json",
|
||||||
|
schema = @Schema(implementation = ResponseResult.class),
|
||||||
|
examples = @ExampleObject(
|
||||||
|
name = "example",
|
||||||
|
value = """
|
||||||
|
{
|
||||||
|
"code": 200,
|
||||||
|
"message": "request succeed",
|
||||||
|
"data": {
|
||||||
|
"templates": [
|
||||||
|
{
|
||||||
|
"template_id": 18,
|
||||||
|
"template_name": "洪泛型DDOS攻击-2024-01-18T16:46:14.640176900",
|
||||||
|
"has_protect_level_low": false,
|
||||||
|
"has_protect_level_medium": true,
|
||||||
|
"has_protect_level_high": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"template_id": 24,
|
||||||
|
"template_name": "反射型DDOS攻击-2024-01-12T17:52:32.077477700",
|
||||||
|
"has_protect_level_low": false,
|
||||||
|
"has_protect_level_medium": true,
|
||||||
|
"has_protect_level_high": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"total_num": 708
|
||||||
|
}
|
||||||
|
}
|
||||||
|
""",
|
||||||
|
description =
|
||||||
|
"""
|
||||||
|
"has_protect_level_low": 是否包含日常态防护等级
|
||||||
|
|
||||||
|
"has_protect_level_medium": 是否包含应急态防护等级
|
||||||
|
|
||||||
|
"has_protect_level_high": 是否包含紧急态防护等级
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
ResponseResult queryTemplateProtectLevels();
|
||||||
|
|
||||||
@PostMapping("/{templateId}/update")
|
@PostMapping("/{templateId}/update")
|
||||||
@Operation(
|
@Operation(
|
||||||
summary = "更新防御策略模板信息",
|
summary = "更新防御策略模板信息",
|
||||||
|
|||||||
@@ -28,9 +28,7 @@ public class DynamicRuleService {
|
|||||||
|
|
||||||
//判断protectObject id是否有效
|
//判断protectObject id是否有效
|
||||||
boolean ProtectObjIdValid = dynamicRule.getProtectObjectIds().stream()
|
boolean ProtectObjIdValid = dynamicRule.getProtectObjectIds().stream()
|
||||||
.allMatch(
|
.allMatch(dynamicRuleMapper::queryProtectObjectById);
|
||||||
protectObjectId -> dynamicRuleMapper.queryProtectObjectById(protectObjectId)
|
|
||||||
);
|
|
||||||
if (!ProtectObjIdValid) {
|
if (!ProtectObjIdValid) {
|
||||||
throw new IllegalArgumentException("protect object id is invalid");
|
throw new IllegalArgumentException("protect object id is invalid");
|
||||||
}
|
}
|
||||||
@@ -125,9 +123,7 @@ public class DynamicRuleService {
|
|||||||
dynamicRuleMapper.deleteDynamicRuleProtectObjectConcat(dynamicRuleId);
|
dynamicRuleMapper.deleteDynamicRuleProtectObjectConcat(dynamicRuleId);
|
||||||
//新增DynamicRule关联的ProtectObject
|
//新增DynamicRule关联的ProtectObject
|
||||||
boolean ProtectObjIdValid = dynamicRuleObject.getProtectObjectIds().stream()
|
boolean ProtectObjIdValid = dynamicRuleObject.getProtectObjectIds().stream()
|
||||||
.allMatch(
|
.allMatch(dynamicRuleMapper::queryProtectObjectById);
|
||||||
protectObjectId -> dynamicRuleMapper.queryProtectObjectById(protectObjectId)
|
|
||||||
);
|
|
||||||
if (!ProtectObjIdValid) {
|
if (!ProtectObjIdValid) {
|
||||||
throw new IllegalArgumentException("protect object id is invalid");
|
throw new IllegalArgumentException("protect object id is invalid");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -114,8 +114,8 @@ public class StaticRuleService {
|
|||||||
throw new IllegalArgumentException("未知的静态规则ID");
|
throw new IllegalArgumentException("未知的静态规则ID");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Objects.equals(staticRuleObject.getStaticRuleAuditStatus(), AuditStatusEnum.USING.getNum())) {
|
if (!staticRuleObject.getStaticRuleAuditStatus().equals(AuditStatusEnum.AUDITED.getNum())) {
|
||||||
throw new IllegalArgumentException("静态规则当前正在使用,无法更新");
|
throw new IllegalStateException("无法修改该静态规则,因为其审核状态未处于" + AuditStatusEnum.AUDITED);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!RuleEnum.checkValidate(object)) {
|
if (!RuleEnum.checkValidate(object)) {
|
||||||
@@ -125,6 +125,7 @@ public class StaticRuleService {
|
|||||||
//判断当前静态规则是否能够修改---是否存在任务选择的静态规则??
|
//判断当前静态规则是否能够修改---是否存在任务选择的静态规则??
|
||||||
//按id查询该静态规则的used_task_id字段,如果不为空,则不能修改
|
//按id查询该静态规则的used_task_id字段,如果不为空,则不能修改
|
||||||
object.setStaticRuleModifyTime(LocalDateTime.now());
|
object.setStaticRuleModifyTime(LocalDateTime.now());
|
||||||
|
object.setStaticRuleAuditStatus(AuditStatusEnum.PENDING.getNum());
|
||||||
//修改静态规则
|
//修改静态规则
|
||||||
return staticRuleMapper.updateStaticRule(id, object);
|
return staticRuleMapper.updateStaticRule(id, object);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,9 @@ import jakarta.validation.constraints.Min;
|
|||||||
import jakarta.validation.constraints.NotNull;
|
import jakarta.validation.constraints.NotNull;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/task")
|
@RequestMapping("/task")
|
||||||
@@ -70,9 +72,10 @@ public class TaskController implements TaskControllerApi {
|
|||||||
@RequestParam(value = "task_type", required = false) Integer taskType,
|
@RequestParam(value = "task_type", required = false) Integer taskType,
|
||||||
@RequestParam(value = "task_name", required = false) String taskName,
|
@RequestParam(value = "task_name", required = false) String taskName,
|
||||||
@RequestParam(value = "task_creator", required = false) String taskCreator,
|
@RequestParam(value = "task_creator", required = false) String taskCreator,
|
||||||
|
@RequestParam(value = "audit_status", required = false) Integer auditStatus,
|
||||||
@RequestParam("page") @Min(1) Integer page,
|
@RequestParam("page") @Min(1) Integer page,
|
||||||
@RequestParam("page_size") @Min(1) Integer pageSize) {
|
@RequestParam("page_size") @Min(1) Integer pageSize) {
|
||||||
List<Task> tasks = taskService.queryTasks(taskStatus, taskType, taskName, taskCreator, page, pageSize);
|
List<Task> tasks = taskService.queryTasks(taskStatus, taskType, taskName, taskCreator, auditStatus, page, pageSize);
|
||||||
return ResponseResult.ok()
|
return ResponseResult.ok()
|
||||||
.setData("task_list", tasks)
|
.setData("task_list", tasks)
|
||||||
.setData("total_num", taskService.queryTaskTotalNum(taskStatus, taskType, taskName, taskCreator));
|
.setData("total_num", taskService.queryTaskTotalNum(taskStatus, taskType, taskName, taskCreator));
|
||||||
@@ -154,4 +157,28 @@ public class TaskController implements TaskControllerApi {
|
|||||||
.setData("success", commandService.setCommandJudged(commandId, isJudged))
|
.setData("success", commandService.setCommandJudged(commandId, isJudged))
|
||||||
.setData("command_id", commandId);
|
.setData("command_id", commandId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量修改审核状态
|
||||||
|
*/
|
||||||
|
@PostMapping("/auditbatch")
|
||||||
|
public ResponseResult updateTaskAuditStatusBatch(@RequestBody Map<Integer, Integer> idsWithAuditStatusMap) {
|
||||||
|
List<Integer> errorIds = new ArrayList<>();
|
||||||
|
for (Map.Entry<Integer, Integer> entry: idsWithAuditStatusMap.entrySet()) {
|
||||||
|
Integer id = entry.getKey();
|
||||||
|
Integer auditStatus = entry.getValue();
|
||||||
|
if (id <= 0 || auditStatus < 0 || auditStatus > 2) {
|
||||||
|
errorIds.add(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!errorIds.isEmpty()){
|
||||||
|
return new ResponseResult(400, "id or status is invalid")
|
||||||
|
.setData("tasks_id", errorIds)
|
||||||
|
.setData("success", false);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ResponseResult.ok()
|
||||||
|
.setData("success", taskService.updateAuditStatusBatch(idsWithAuditStatusMap));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -181,6 +181,7 @@ public interface TaskControllerApi {
|
|||||||
@Parameter(name = "task_type", description = "任务类型(1为静态,2为实时,3为研判后)"),
|
@Parameter(name = "task_type", description = "任务类型(1为静态,2为实时,3为研判后)"),
|
||||||
@Parameter(name = "task_name", description = "任务名称"),
|
@Parameter(name = "task_name", description = "任务名称"),
|
||||||
@Parameter(name = "task_creator", description = "任务创建人"),
|
@Parameter(name = "task_creator", description = "任务创建人"),
|
||||||
|
@Parameter(name = "audit_status", description = "审批状态"),
|
||||||
@Parameter(name = "page", description = "页码", example = "1"),
|
@Parameter(name = "page", description = "页码", example = "1"),
|
||||||
@Parameter(name = "page_size", description = "每页查询个数", example = "10")
|
@Parameter(name = "page_size", description = "每页查询个数", example = "10")
|
||||||
}
|
}
|
||||||
@@ -189,6 +190,7 @@ public interface TaskControllerApi {
|
|||||||
@RequestParam(value = "task_type", required = false) Integer taskType,
|
@RequestParam(value = "task_type", required = false) Integer taskType,
|
||||||
@RequestParam(value = "task_name", required = false) String taskName,
|
@RequestParam(value = "task_name", required = false) String taskName,
|
||||||
@RequestParam(value = "task_creator", required = false) String taskCreator,
|
@RequestParam(value = "task_creator", required = false) String taskCreator,
|
||||||
|
@RequestParam(value = "audit_status", required = false) Integer auditStatus,
|
||||||
@RequestParam("page") @Min(1) Integer page,
|
@RequestParam("page") @Min(1) Integer page,
|
||||||
@RequestParam("page_size") @Min(1) Integer pageSize);
|
@RequestParam("page_size") @Min(1) Integer pageSize);
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import org.apache.ibatis.annotations.Param;
|
|||||||
import org.apache.ibatis.annotations.Select;
|
import org.apache.ibatis.annotations.Select;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
@Mapper
|
@Mapper
|
||||||
public interface TaskMapper {
|
public interface TaskMapper {
|
||||||
@@ -23,6 +24,7 @@ public interface TaskMapper {
|
|||||||
|
|
||||||
List<Task> queryTasks(@Param("task_status") Integer taskStatus, @Param("task_type") Integer task_type,
|
List<Task> queryTasks(@Param("task_status") Integer taskStatus, @Param("task_type") Integer task_type,
|
||||||
@Param("task_name") String taskName, @Param("task_creator") String taskCreator,
|
@Param("task_name") String taskName, @Param("task_creator") String taskCreator,
|
||||||
|
@Param("task_audit_status") Integer auditStatus,
|
||||||
@Param("page") Integer page, @Param("page_size") Integer pageSize);
|
@Param("page") Integer page, @Param("page_size") Integer pageSize);
|
||||||
|
|
||||||
Task queryTask(@Param("task_id") Long taskId);
|
Task queryTask(@Param("task_id") Long taskId);
|
||||||
@@ -57,4 +59,6 @@ public interface TaskMapper {
|
|||||||
|
|
||||||
Integer queryTaskTotalNum(@Param("task_status") Integer taskStatus, @Param("task_type") Integer task_type,
|
Integer queryTaskTotalNum(@Param("task_status") Integer taskStatus, @Param("task_type") Integer task_type,
|
||||||
@Param("task_name") String taskName, @Param("task_creator") String taskCreator);
|
@Param("task_name") String taskName, @Param("task_creator") String taskCreator);
|
||||||
|
|
||||||
|
void updateAuditStatusByIdBatch(@Param("idWithAuditStatusBatch") Map<Integer, Integer> idWithAuditStatusBatch);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,22 +4,30 @@ import com.baomidou.dynamic.datasource.annotation.DS;
|
|||||||
import com.realtime.protection.configuration.entity.task.DynamicTaskInfo;
|
import com.realtime.protection.configuration.entity.task.DynamicTaskInfo;
|
||||||
import com.realtime.protection.configuration.entity.task.Task;
|
import com.realtime.protection.configuration.entity.task.Task;
|
||||||
import com.realtime.protection.configuration.entity.task.TaskCommandInfo;
|
import com.realtime.protection.configuration.entity.task.TaskCommandInfo;
|
||||||
|
import com.realtime.protection.configuration.utils.SqlSessionWrapper;
|
||||||
import com.realtime.protection.configuration.utils.enums.StateEnum;
|
import com.realtime.protection.configuration.utils.enums.StateEnum;
|
||||||
|
import com.realtime.protection.configuration.utils.enums.audit.AuditStatusEnum;
|
||||||
import com.realtime.protection.configuration.utils.enums.audit.AuditStatusValidator;
|
import com.realtime.protection.configuration.utils.enums.audit.AuditStatusValidator;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@DS("mysql")
|
@DS("mysql")
|
||||||
public class TaskService {
|
public class TaskService {
|
||||||
private final TaskMapper taskMapper;
|
private final TaskMapper taskMapper;
|
||||||
|
private final SqlSessionWrapper sqlSessionWrapper;
|
||||||
|
|
||||||
public TaskService(TaskMapper taskMapper) {
|
public TaskService(TaskMapper taskMapper,SqlSessionWrapper sqlSessionWrapper) {
|
||||||
this.taskMapper = taskMapper;
|
this.taskMapper = taskMapper;
|
||||||
|
this.sqlSessionWrapper = sqlSessionWrapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
@@ -28,6 +36,8 @@ public class TaskService {
|
|||||||
task.setTaskCreateUsername("xxx");
|
task.setTaskCreateUsername("xxx");
|
||||||
task.setTaskCreateDepart("xxx");
|
task.setTaskCreateDepart("xxx");
|
||||||
|
|
||||||
|
// todo: 添加新建任务时,将动态/静态规则从“已审核”修改为“使用中”
|
||||||
|
|
||||||
taskMapper.newTask(task);
|
taskMapper.newTask(task);
|
||||||
|
|
||||||
if (task.getStaticRuleIds() != null && !task.getStaticRuleIds().isEmpty())
|
if (task.getStaticRuleIds() != null && !task.getStaticRuleIds().isEmpty())
|
||||||
@@ -42,8 +52,9 @@ public class TaskService {
|
|||||||
@Transactional
|
@Transactional
|
||||||
public List<Task> queryTasks(Integer taskStatus,
|
public List<Task> queryTasks(Integer taskStatus,
|
||||||
Integer taskType, String taskName, String taskCreator,
|
Integer taskType, String taskName, String taskCreator,
|
||||||
|
Integer auditStatus,
|
||||||
Integer page, Integer pageSize) {
|
Integer page, Integer pageSize) {
|
||||||
List<Task> tasks = taskMapper.queryTasks(taskStatus, taskType, taskName, taskCreator, page, pageSize);
|
List<Task> tasks = taskMapper.queryTasks(taskStatus, taskType, taskName, taskCreator, auditStatus, page, pageSize);
|
||||||
for (Task task : tasks) {
|
for (Task task : tasks) {
|
||||||
if (task == null) {
|
if (task == null) {
|
||||||
continue;
|
continue;
|
||||||
@@ -70,6 +81,12 @@ public class TaskService {
|
|||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public Boolean updateTask(Task task) {
|
public Boolean updateTask(Task task) {
|
||||||
|
if (!Objects.equals(taskMapper.queryTaskAuditStatus(task.getTaskId()), AuditStatusEnum.AUDITED.getNum())) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
task.setTaskAuditStatus(AuditStatusEnum.PENDING.getNum());
|
||||||
|
|
||||||
taskMapper.updateTask(task);
|
taskMapper.updateTask(task);
|
||||||
|
|
||||||
taskMapper.clearTaskConnectedStaticRule(task.getTaskId());
|
taskMapper.clearTaskConnectedStaticRule(task.getTaskId());
|
||||||
@@ -142,4 +159,32 @@ public class TaskService {
|
|||||||
public Integer queryTaskTotalNum(Integer taskStatus, Integer taskType, String taskName, String taskCreator) {
|
public Integer queryTaskTotalNum(Integer taskStatus, Integer taskType, String taskName, String taskCreator) {
|
||||||
return taskMapper.queryTaskTotalNum(taskStatus, taskType, taskName, taskCreator);
|
return taskMapper.queryTaskTotalNum(taskStatus, taskType, taskName, taskCreator);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Object updateAuditStatusBatch(Map<Integer, Integer> idsWithAuditStatusMap) {
|
||||||
|
Function<TaskMapper, Function<Map<Integer, Integer>, Boolean>> updateTaskAuditStatusFunction =
|
||||||
|
mapper -> map -> {
|
||||||
|
if (map == null || map.isEmpty()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<Integer, Integer> idWithAuditStatusBatch = new HashMap<>();
|
||||||
|
for (Map.Entry<Integer, Integer> item : map.entrySet()) {
|
||||||
|
idWithAuditStatusBatch.put(item.getKey(), item.getValue());
|
||||||
|
if (idWithAuditStatusBatch.size() < 100) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
//mapper指的就是外层函数输入的参数,也就是WhiteListMapper
|
||||||
|
mapper.updateAuditStatusByIdBatch(idWithAuditStatusBatch);
|
||||||
|
idWithAuditStatusBatch.clear();
|
||||||
|
}
|
||||||
|
if (!idWithAuditStatusBatch.isEmpty()) {
|
||||||
|
mapper.updateAuditStatusByIdBatch(idWithAuditStatusBatch);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
//实现事务操作
|
||||||
|
return sqlSessionWrapper.startBatchSession(TaskMapper.class, updateTaskAuditStatusFunction, idsWithAuditStatusMap);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import com.realtime.protection.configuration.entity.rule.staticrule.StaticRuleOb
|
|||||||
import com.realtime.protection.configuration.entity.task.TaskCommandInfo;
|
import com.realtime.protection.configuration.entity.task.TaskCommandInfo;
|
||||||
import com.realtime.protection.configuration.entity.whitelist.WhiteListObject;
|
import com.realtime.protection.configuration.entity.whitelist.WhiteListObject;
|
||||||
import com.realtime.protection.configuration.utils.SqlSessionWrapper;
|
import com.realtime.protection.configuration.utils.SqlSessionWrapper;
|
||||||
|
import com.realtime.protection.configuration.utils.enums.audit.AuditStatusEnum;
|
||||||
import com.realtime.protection.configuration.utils.enums.audit.AuditStatusValidator;
|
import com.realtime.protection.configuration.utils.enums.audit.AuditStatusValidator;
|
||||||
import com.realtime.protection.server.rule.staticrule.StaticRuleMapper;
|
import com.realtime.protection.server.rule.staticrule.StaticRuleMapper;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
@@ -102,6 +103,12 @@ public class WhiteListService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Integer updateWhiteListObject(Integer id, WhiteListObject object) {
|
public Integer updateWhiteListObject(Integer id, WhiteListObject object) {
|
||||||
|
if (!whiteListMapper.queryWhiteListObjectAuditStuatusById(id).equals(AuditStatusEnum.AUDITED.getNum())) {
|
||||||
|
throw new IllegalStateException("无法修改白名单信息,因为其并未处于" + AuditStatusEnum.AUDITED + "状态");
|
||||||
|
}
|
||||||
|
|
||||||
|
object.setWhiteListAuditStatus(AuditStatusEnum.PENDING.toString());
|
||||||
|
|
||||||
return whiteListMapper.updateWhiteListObject(id, object);
|
return whiteListMapper.updateWhiteListObject(id, object);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -26,7 +26,7 @@
|
|||||||
|
|
||||||
<insert id="createCommands" parameterType="com.realtime.protection.configuration.entity.task.TaskCommandInfo">
|
<insert id="createCommands" parameterType="com.realtime.protection.configuration.entity.task.TaskCommandInfo">
|
||||||
insert into t_command(
|
insert into t_command(
|
||||||
COMMAND_ID, TASK_ID, TASK_ACT, TASK_NAME, EVENT_TYPE, DEPARTMENT, DISTRIBUTEPOINT, FREQUENCY,
|
COMMAND_ID, TASK_ID, TASK_ACT, TASKNAME, EVENT_TYPE, DEPARTMENT, DISTRIBUTEPOINT, FREQUENCY,
|
||||||
ADDR_TYPE, SRC_IP, SRC_PORT, DST_IP, DST_PORT, PROTOCOL,
|
ADDR_TYPE, SRC_IP, SRC_PORT, DST_IP, DST_PORT, PROTOCOL,
|
||||||
MASK_SRC_IP, MASK_SRC_PORT, MASK_DST_IP, MASK_DST_PORT, MASK_PROTOCOL, VALID_TIME, INVALID_TIME, IS_VALID,
|
MASK_SRC_IP, MASK_SRC_PORT, MASK_DST_IP, MASK_DST_PORT, MASK_PROTOCOL, VALID_TIME, INVALID_TIME, IS_VALID,
|
||||||
IS_JUDGED,
|
IS_JUDGED,
|
||||||
|
|||||||
@@ -47,7 +47,8 @@
|
|||||||
|
|
||||||
<select id="queryProtectObjects" resultMap="protectObjectMap">
|
<select id="queryProtectObjects" resultMap="protectObjectMap">
|
||||||
SELECT
|
SELECT
|
||||||
protect_object_id, protect_object_name, protect_object_system_name, INET_NTOA(protect_object_ip),
|
protect_object_id, protect_object_name, protect_object_system_name,
|
||||||
|
INET_NTOA(protect_object_ip) as protect_object_ip,
|
||||||
protect_object_port, protect_object_url, protect_object_protocol, protect_object_audit_status
|
protect_object_port, protect_object_url, protect_object_protocol, protect_object_audit_status
|
||||||
FROM t_protect_object
|
FROM t_protect_object
|
||||||
<where>
|
<where>
|
||||||
|
|||||||
@@ -71,6 +71,9 @@
|
|||||||
<if test="task_creator != null">
|
<if test="task_creator != null">
|
||||||
AND task_create_username LIKE CONCAT('%', #{task_creator}, '%')
|
AND task_create_username LIKE CONCAT('%', #{task_creator}, '%')
|
||||||
</if>
|
</if>
|
||||||
|
<if test="task_audit_status != null">
|
||||||
|
AND task_audit_status = #{task_audit_status}
|
||||||
|
</if>
|
||||||
</where>
|
</where>
|
||||||
LIMIT ${(page - 1) * page_size}, #{page_size}
|
LIMIT ${(page - 1) * page_size}, #{page_size}
|
||||||
</select>
|
</select>
|
||||||
@@ -78,7 +81,7 @@
|
|||||||
<select id="queryStaticRuleIdsFromTaskId" resultType="java.lang.Integer">
|
<select id="queryStaticRuleIdsFromTaskId" resultType="java.lang.Integer">
|
||||||
SELECT static_rule_id
|
SELECT static_rule_id
|
||||||
FROM t_static_rule
|
FROM t_static_rule
|
||||||
WHERE static_rule_used_task_id = #{task_id}
|
WHERE static_rule_used_task_id = #{task_id} AND static_rule_audit_status = true
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="queryDynamicRuleIdsFromTaskId" resultType="java.lang.Integer">
|
<select id="queryDynamicRuleIdsFromTaskId" resultType="java.lang.Integer">
|
||||||
@@ -145,6 +148,21 @@
|
|||||||
WHERE task_id = #{task_id}
|
WHERE task_id = #{task_id}
|
||||||
</update>
|
</update>
|
||||||
|
|
||||||
|
<!-- 批量审核 -->
|
||||||
|
<update id="updateAuditStatusByIdBatch">
|
||||||
|
update t_task
|
||||||
|
set task_audit_status = CASE task_id
|
||||||
|
<foreach collection="idWithAuditStatusBatch" index="id" item="auditStatus" separator=" ">
|
||||||
|
WHEN #{id} THEN #{auditStatus}
|
||||||
|
</foreach>
|
||||||
|
ELSE task_audit_status
|
||||||
|
END
|
||||||
|
WHERE task_id IN
|
||||||
|
<foreach collection="idWithAuditStatusBatch" index="id" open="(" separator="," close=")">
|
||||||
|
#{id}
|
||||||
|
</foreach>
|
||||||
|
</update>
|
||||||
|
|
||||||
<delete id="deleteTask">
|
<delete id="deleteTask">
|
||||||
DELETE
|
DELETE
|
||||||
FROM t_task
|
FROM t_task
|
||||||
@@ -234,6 +252,7 @@
|
|||||||
<result column="task_start_time" property="startTime"/>
|
<result column="task_start_time" property="startTime"/>
|
||||||
<result column="task_end_time" property="endTime"/>
|
<result column="task_end_time" property="endTime"/>
|
||||||
<result column="rule_id" property="ruleId"/>
|
<result column="rule_id" property="ruleId"/>
|
||||||
|
<result column="log_rule_id" property="logRuleId"/>
|
||||||
<result column="source_system" property="sourceSystem"/>
|
<result column="source_system" property="sourceSystem"/>
|
||||||
<result column="event_type" property="eventType"/>
|
<result column="event_type" property="eventType"/>
|
||||||
<collection property="protectObjects">
|
<collection property="protectObjects">
|
||||||
@@ -252,6 +271,7 @@
|
|||||||
tdr.dynamic_rule_id as rule_id,
|
tdr.dynamic_rule_id as rule_id,
|
||||||
strategy_template_source_system as source_system,
|
strategy_template_source_system as source_system,
|
||||||
strategy_template_name as event_type,
|
strategy_template_name as event_type,
|
||||||
|
tdr.log_rule_id,
|
||||||
INET_NTOA(protect_object_ip),
|
INET_NTOA(protect_object_ip),
|
||||||
protect_object_port,
|
protect_object_port,
|
||||||
protect_object_url,
|
protect_object_url,
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
upstream server_list {
|
upstream server_list {
|
||||||
least_conn;
|
ip_hash; # todo: 暂时采用该方式保持会话连接
|
||||||
server ${SPRINGBOOT_FIRST_URL};
|
server ${SPRINGBOOT_FIRST_URL};
|
||||||
server ${SPRINGBOOT_SECOND_URL};
|
server ${SPRINGBOOT_SECOND_URL};
|
||||||
server ${SPRINGBOOT_THIRD_URL};
|
server ${SPRINGBOOT_THIRD_URL};
|
||||||
|
|||||||
@@ -16,7 +16,9 @@ import org.springframework.dao.DataIntegrityViolationException;
|
|||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
@@ -54,7 +56,7 @@ class TaskServiceTest extends ProtectionApplicationTests {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testNewTaskSuccess() {
|
void testNewTaskSuccess() {
|
||||||
for (int i = 1; i < 1000; i++) {
|
for (int i = 1; i < 10; i++) {
|
||||||
List<StaticRuleObject> staticRuleObjects = staticRuleService.queryStaticRule(
|
List<StaticRuleObject> staticRuleObjects = staticRuleService.queryStaticRule(
|
||||||
null, null, null, null, i, 2);
|
null, null, null, null, i, 2);
|
||||||
List<Integer> staticRuleIds = new ArrayList<>();
|
List<Integer> staticRuleIds = new ArrayList<>();
|
||||||
@@ -118,17 +120,17 @@ class TaskServiceTest extends ProtectionApplicationTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
List<Task> tasks = taskService.queryTasks(null, null, null, null, 1, 10);
|
List<Task> tasks = taskService.queryTasks(null, null, null, null, null, 1, 10);
|
||||||
assertEquals(10, tasks.size());
|
assertEquals(10, tasks.size());
|
||||||
|
|
||||||
tasks = taskService.queryTasks(0, null, null, null, 1, 10);
|
tasks = taskService.queryTasks(0, null, null, null, null, 1, 10);
|
||||||
assertEquals(10, tasks.size());
|
assertEquals(10, tasks.size());
|
||||||
tasks.forEach(task -> assertEquals(0, task.getTaskStatus()));
|
tasks.forEach(task -> assertEquals(0, task.getTaskStatus()));
|
||||||
|
|
||||||
tasks = taskService.queryTasks(null, 0, null, null, 1, 10);
|
tasks = taskService.queryTasks(null, 0, null, null, null, 1, 10);
|
||||||
assertEquals(0, tasks.size());
|
assertEquals(0, tasks.size());
|
||||||
|
|
||||||
tasks = taskService.queryTasks(null, null, testName, null, 1, 10);
|
tasks = taskService.queryTasks(null, null, testName, null, null, 1, 10);
|
||||||
assertEquals(10, tasks.size());
|
assertEquals(10, tasks.size());
|
||||||
tasks.forEach(task -> assertEquals(testName, task.getTaskName()));
|
tasks.forEach(task -> assertEquals(testName, task.getTaskName()));
|
||||||
}
|
}
|
||||||
@@ -136,7 +138,7 @@ class TaskServiceTest extends ProtectionApplicationTests {
|
|||||||
@Test
|
@Test
|
||||||
void testUpdateTasks() {
|
void testUpdateTasks() {
|
||||||
Task originalTask = taskService.queryTasks(
|
Task originalTask = taskService.queryTasks(
|
||||||
null, null, null, null, 1, 1)
|
null, null, null, null, null, 1, 1)
|
||||||
.get(0);
|
.get(0);
|
||||||
|
|
||||||
List<StaticRuleObject> staticRuleObjects = staticRuleService.queryStaticRule(
|
List<StaticRuleObject> staticRuleObjects = staticRuleService.queryStaticRule(
|
||||||
@@ -153,7 +155,7 @@ class TaskServiceTest extends ProtectionApplicationTests {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testDeleteTask() {
|
void testDeleteTask() {
|
||||||
long testNum = taskService.queryTasks(null, null, null, null, 1, 10)
|
long testNum = taskService.queryTasks(null, null, null, null, null, 1, 10)
|
||||||
.get(0).getTaskId();
|
.get(0).getTaskId();
|
||||||
|
|
||||||
assertTrue(taskService.deleteTask(testNum));
|
assertTrue(taskService.deleteTask(testNum));
|
||||||
@@ -162,7 +164,7 @@ class TaskServiceTest extends ProtectionApplicationTests {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testChangeAuditStatus() {
|
void testChangeAuditStatus() {
|
||||||
long testNum = taskService.queryTasks(null, null, null, null, 1, 1)
|
long testNum = taskService.queryTasks(null, null, null, null, null, 1, 1)
|
||||||
.get(0).getTaskId();
|
.get(0).getTaskId();
|
||||||
|
|
||||||
assertTrue(taskService.changeTaskAuditStatus(testNum, 2));
|
assertTrue(taskService.changeTaskAuditStatus(testNum, 2));
|
||||||
@@ -175,4 +177,16 @@ class TaskServiceTest extends ProtectionApplicationTests {
|
|||||||
List<TaskCommandInfo> taskCommandInfos = taskService.getStaticCommandInfos(38L);
|
List<TaskCommandInfo> taskCommandInfos = taskService.getStaticCommandInfos(38L);
|
||||||
assertNotNull(taskCommandInfos);
|
assertNotNull(taskCommandInfos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testUpdateTaskAuditStatusBatch(){
|
||||||
|
Map<Integer, Integer> map = new HashMap<>();
|
||||||
|
map.put(43830, 1);
|
||||||
|
map.put(43831, 1);
|
||||||
|
map.put(43832, 1);
|
||||||
|
|
||||||
|
|
||||||
|
System.out.println(taskService.updateAuditStatusBatch(map));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -36,7 +36,7 @@ class CommandServiceTest extends ProtectionApplicationTests {
|
|||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
void mockCommand() {
|
void mockCommand() {
|
||||||
Task task = taskService.queryTasks(null, null, null, null, 1, 1).get(0);
|
Task task = taskService.queryTasks(null, null, null, null, null, 1, 1).get(0);
|
||||||
FiveTupleWithMask fiveTupleWithMask = new FiveTupleWithMask();
|
FiveTupleWithMask fiveTupleWithMask = new FiveTupleWithMask();
|
||||||
fiveTupleWithMask.setMaskSourceIP("192.168.155.24");
|
fiveTupleWithMask.setMaskSourceIP("192.168.155.24");
|
||||||
|
|
||||||
@@ -66,7 +66,7 @@ class CommandServiceTest extends ProtectionApplicationTests {
|
|||||||
@Test
|
@Test
|
||||||
void createCommands() {
|
void createCommands() {
|
||||||
List<TaskCommandInfo> taskCommandInfos = ListUtils.newArrayListWithExpectedSize(100);
|
List<TaskCommandInfo> taskCommandInfos = ListUtils.newArrayListWithExpectedSize(100);
|
||||||
Task task = taskService.queryTasks(null, null, null, null, 1, 1).get(0);
|
Task task = taskService.queryTasks(null, null, null, null, null, 1, 1).get(0);
|
||||||
for (int i = 0; i < 100; i++) {
|
for (int i = 0; i < 100; i++) {
|
||||||
int port = i + 1000;
|
int port = i + 1000;
|
||||||
TaskCommandInfo taskCommandInfo = new TaskCommandInfo();
|
TaskCommandInfo taskCommandInfo = new TaskCommandInfo();
|
||||||
@@ -92,7 +92,7 @@ class CommandServiceTest extends ProtectionApplicationTests {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void queryCommandInfos() {
|
void queryCommandInfos() {
|
||||||
Task task = taskService.queryTasks(null, null, null, null, 1, 1).get(0);
|
Task task = taskService.queryTasks(null, null, null, null, null, 1, 1).get(0);
|
||||||
List<TaskCommandInfo> taskCommandInfos = commandService.queryCommandInfos(task.getTaskId(),
|
List<TaskCommandInfo> taskCommandInfos = commandService.queryCommandInfos(task.getTaskId(),
|
||||||
null, null, null, null,1, 5);
|
null, null, null, null,1, 5);
|
||||||
assertTrue(taskCommandInfos != null && !taskCommandInfos.isEmpty());
|
assertTrue(taskCommandInfos != null && !taskCommandInfos.isEmpty());
|
||||||
|
|||||||
Reference in New Issue
Block a user