Merge remote-tracking branch 'origin/master'
# Conflicts: # src/main/java/com/realtime/protection/server/rule/dynamicrule/DynamicRuleControllerApi.java # src/main/java/com/realtime/protection/server/rule/staticrule/StaticRuleControllerApi.java
This commit is contained in:
@@ -29,7 +29,7 @@ public class ProtectObject {
|
||||
private String protectObjectSystemName;
|
||||
|
||||
@JsonProperty("proobj_ip_address")
|
||||
@Pattern(regexp = "^(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})$", message = "Invalid IPv4 Address")
|
||||
@Pattern(regexp = "^(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})$", message = "无效IPv4地址")
|
||||
@ExcelProperty("IP地址")
|
||||
@Schema(description = "防护对象IPv4地址", example = "192.168.0.1")
|
||||
private String protectObjectIPAddress;
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
package com.realtime.protection.configuration.entity.task;
|
||||
|
||||
import com.realtime.protection.configuration.utils.enums.ProtocolEnum;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Data
|
||||
public class Command {
|
||||
private FiveTupleWithMask fiveTupleWithMask;
|
||||
private Long taskId;
|
||||
|
||||
private String operation;
|
||||
private LocalDateTime validTime;
|
||||
private LocalDateTime invalidTime;
|
||||
|
||||
public static Command generateCommand(TaskCommandInfo info, LocalDateTime validTime) {
|
||||
Command command = new Command();
|
||||
|
||||
FiveTupleWithMask fiveTupleWithMask = info.getFiveTupleWithMask();
|
||||
if (fiveTupleWithMask.getProtocol() != null)
|
||||
fiveTupleWithMask.setProtocolNum(ProtocolEnum.valueOf(fiveTupleWithMask.getProtocol()).getProtocolNumber());
|
||||
|
||||
command.setFiveTupleWithMask(fiveTupleWithMask);
|
||||
command.setTaskId(info.getTaskId());
|
||||
command.setOperation(info.getOperation());
|
||||
command.setValidTime(validTime);
|
||||
command.setInvalidTime(info.getEndTime());
|
||||
|
||||
return command;
|
||||
}
|
||||
}
|
||||
@@ -1,19 +1,58 @@
|
||||
package com.realtime.protection.configuration.entity.task;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.Max;
|
||||
import jakarta.validation.constraints.Min;
|
||||
import jakarta.validation.constraints.Pattern;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class FiveTupleWithMask {
|
||||
@Schema(description = "地址类型(IPv4 or IPv6)", example = "4")
|
||||
private Integer addrType;
|
||||
|
||||
@Schema(description = "源IP", example = "192.168.104.14")
|
||||
@Pattern(regexp = "^(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})$", message = "源IP:无效IPv4地址")
|
||||
private String sourceIP;
|
||||
|
||||
@Schema(description = "源端口", example = "114")
|
||||
@Max(value = 65535, message = "源端口不可大于65535")
|
||||
@Min(value = 1, message = "源端口不可小于1")
|
||||
private String sourcePort;
|
||||
|
||||
@Schema(description = "目的IP", example = "102.165.11.39")
|
||||
@Pattern(regexp = "^(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})$", message = "目的IP:无效IPv4地址")
|
||||
private String destinationIP;
|
||||
|
||||
@Schema(description = "目的端口", example = "514")
|
||||
@Max(value = 65535, message = "目的端口不可大于65535")
|
||||
@Min(value = 1, message = "目的端口不可小于1")
|
||||
private String destinationPort;
|
||||
|
||||
@Schema(description = "协议名称", example = "TCP", accessMode = Schema.AccessMode.WRITE_ONLY)
|
||||
private String protocol;
|
||||
|
||||
@Schema(description = "协议号", example = "6", accessMode = Schema.AccessMode.READ_ONLY)
|
||||
private Integer protocolNum;
|
||||
|
||||
@Schema(description = "源IP掩码", example = "255.255.255.0")
|
||||
@Pattern(regexp = "^(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})$", message = "源IP掩码:无效IPv4地址")
|
||||
private String maskSourceIP;
|
||||
|
||||
@Schema(description = "源端口掩码", example = "0")
|
||||
@Max(value = 65535, message = "源端口掩码不可大于65535")
|
||||
@Min(value = 1, message = "源端口掩码不可小于1")
|
||||
private String maskSourcePort;
|
||||
|
||||
@Schema(description = "目的IP掩码", example = "255.255.0.0")
|
||||
@Pattern(regexp = "^(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})$", message = "目的IP掩码:无效IPv4地址")
|
||||
private String maskDestinationIP;
|
||||
|
||||
@Schema(description = "目的端口掩码", example = "0")
|
||||
@Max(value = 65535, message = "目的端口掩码不可大于65535")
|
||||
@Min(value = 1, message = "目的端口掩码不可小于1")
|
||||
private String maskDestinationPort;
|
||||
|
||||
@Schema(description = "协议掩码", example = "0")
|
||||
private String maskProtocol;
|
||||
}
|
||||
|
||||
@@ -52,24 +52,24 @@ public class Task {
|
||||
private String taskAct;
|
||||
|
||||
@JsonProperty("task_create_username")
|
||||
@Schema(hidden = true)
|
||||
@Schema(description = "任务创建人名称", accessMode = Schema.AccessMode.READ_ONLY)
|
||||
private String taskCreateUsername;
|
||||
|
||||
@JsonProperty("task_create_depart")
|
||||
@Schema(hidden = true)
|
||||
@Schema(description = "任务创建人处室", accessMode = Schema.AccessMode.READ_ONLY)
|
||||
private String taskCreateDepart;
|
||||
|
||||
@JsonProperty("task_create_userid")
|
||||
@Schema(hidden = true)
|
||||
private Long taskCreateUserId;
|
||||
@Schema(description = "任务创建人ID", accessMode = Schema.AccessMode.READ_ONLY)
|
||||
private Integer taskCreateUserId;
|
||||
|
||||
@JsonProperty("static_rule_ids")
|
||||
@Schema(description = "静态规则ID列表,动态和静态至少存在1个规则", example = "[10, 12]")
|
||||
private List<Long> staticRuleIds;
|
||||
private List<Integer> staticRuleIds;
|
||||
|
||||
@JsonProperty("dynamic_rule_ids")
|
||||
@Schema(description = "动态规则ID列表,动态和静态至少存在1个规则", example = "[20, 30]")
|
||||
private List<Long> dynamicRuleIds;
|
||||
private List<Integer> dynamicRuleIds;
|
||||
|
||||
@JsonProperty("task_status")
|
||||
@Schema(description = "任务状态(0为未启动,1为生成中,2为运行中,3为暂停中,4为已停止,5为已结束,6为失败)", accessMode = Schema.AccessMode.READ_ONLY)
|
||||
|
||||
@@ -1,19 +1,68 @@
|
||||
package com.realtime.protection.configuration.entity.task;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Data
|
||||
public class TaskCommandInfo {
|
||||
private FiveTupleWithMask fiveTupleWithMask;
|
||||
@Schema(description = "指令UUID", accessMode = Schema.AccessMode.READ_ONLY)
|
||||
private String UUID;
|
||||
|
||||
@Schema(description = "任务ID", accessMode = Schema.AccessMode.READ_ONLY)
|
||||
private Long taskId;
|
||||
|
||||
@Schema(description = "规则ID", hidden = true)
|
||||
private Long ruleId;
|
||||
|
||||
// 额外字段
|
||||
private String operation;
|
||||
@Schema(description = "任务创建人名称", accessMode = Schema.AccessMode.READ_ONLY)
|
||||
private String taskCreateUsername;
|
||||
|
||||
@Schema(description = "任务创建人处室", accessMode = Schema.AccessMode.READ_ONLY)
|
||||
private String taskCreateDepart;
|
||||
|
||||
@Schema(description = "任务创建人ID", accessMode = Schema.AccessMode.READ_ONLY)
|
||||
private Integer taskCreateUserId;
|
||||
|
||||
@Schema(description = "任务名称", example = "API测试任务")
|
||||
@NotNull(message = "任务名称不能为空")
|
||||
private String taskName;
|
||||
|
||||
@Schema(description = "任务类型", example = "1")
|
||||
@NotNull(message = "任务类型不能为空")
|
||||
private Integer taskType;
|
||||
|
||||
@Schema(description = "任务操作", example = "阻断")
|
||||
@NotNull(message = "任务操作不能为空。")
|
||||
private String taskAct;
|
||||
|
||||
@Schema(description = "指令下发频率", example = "30")
|
||||
@NotNull(message = "指令下发频率不能为空。")
|
||||
private Integer frequency;
|
||||
|
||||
@Schema(description = "任务开始时间", example = "2025-10-14T10:23:33")
|
||||
@NotNull(message = "任务开始时间不能为空。")
|
||||
private LocalDateTime startTime;
|
||||
|
||||
@Schema(description = "任务结束时间", example = "2026-10-22T10:33:22")
|
||||
@NotNull(message = "指令结束时间不能为空。")
|
||||
private LocalDateTime endTime;
|
||||
|
||||
@Schema(description = "五元组信息")
|
||||
@NotNull(message = "五元组信息不能为空。")
|
||||
private FiveTupleWithMask fiveTupleWithMask;
|
||||
|
||||
@Schema(description = "指令下发次数", accessMode = Schema.AccessMode.READ_ONLY)
|
||||
private Integer commandSentTimes;
|
||||
|
||||
@Schema(description = "指令成功次数", accessMode = Schema.AccessMode.READ_ONLY)
|
||||
private Integer commandSuccessTimes;
|
||||
|
||||
@Schema(description = "首次下发时间", accessMode = Schema.AccessMode.READ_ONLY)
|
||||
private LocalDateTime earliestSendTime;
|
||||
|
||||
@Schema(description = "最新下发时间", accessMode = Schema.AccessMode.READ_ONLY)
|
||||
private LocalDateTime latestSendTime;
|
||||
}
|
||||
|
||||
@@ -15,6 +15,8 @@ import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||
import org.springframework.web.method.annotation.HandlerMethodValidationException;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.sql.SQLIntegrityConstraintViolationException;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@RestControllerAdvice
|
||||
@@ -36,7 +38,12 @@ public class GlobalExceptionHandler {
|
||||
|
||||
|
||||
@Order(2)
|
||||
@ExceptionHandler(value = {PersistenceException.class, DuplicateKeyException.class})
|
||||
@ExceptionHandler(value = {
|
||||
PersistenceException.class,
|
||||
DuplicateKeyException.class,
|
||||
SQLException.class,
|
||||
SQLIntegrityConstraintViolationException.class
|
||||
})
|
||||
public ResponseResult handleSQLException(Exception e) {
|
||||
log.info("遭遇数据库异常:" + e.getMessage());
|
||||
return ResponseResult.invalid().setMessage(
|
||||
@@ -89,7 +96,8 @@ public class GlobalExceptionHandler {
|
||||
.setMessage("Doris数据库指令生成遭遇异常:" + e.getMessage());
|
||||
|
||||
try {
|
||||
stateChangeService.changeState(StateEnum.FAILED.getStateNum(), e.taskId);
|
||||
// 内部修改状态,可以跳过一切状态检查
|
||||
stateChangeService.changeState(StateEnum.FAILED.getStateNum(), e.taskId, true);
|
||||
} catch (Exception another) {
|
||||
responseResult.setAnother(ResponseResult.error().setMessage(e.getMessage()));
|
||||
}
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package com.realtime.protection.configuration.utils.status;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@Slf4j
|
||||
public class AuditStatusValidator {
|
||||
|
||||
private final Integer auditStatusOriginal;
|
||||
@@ -12,8 +15,8 @@ public class AuditStatusValidator {
|
||||
return new AuditStatusValidator(auditStatusOriginal);
|
||||
}
|
||||
|
||||
public Boolean checkValidate(Integer auditStatusNow) {
|
||||
switch (auditStatusNow) {
|
||||
public Boolean checkValidate(Integer newAuditStatus) {
|
||||
switch (newAuditStatus) {
|
||||
case 0, 1 -> {
|
||||
return auditStatusOriginal != 2;
|
||||
}
|
||||
@@ -21,6 +24,7 @@ public class AuditStatusValidator {
|
||||
return auditStatusOriginal != 1;
|
||||
}
|
||||
default -> {
|
||||
log.debug("欲修改的审核状态不正确,需要使用正确的审核状态,当前的审核状态:" + auditStatusOriginal);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user