Merge remote-tracking branch 'origin/master' into haskafka
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package com.realtime.protection.configuration.entity.defense.template;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.realtime.protection.configuration.utils.NonEmptyFieldFetcher;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
@@ -40,6 +41,18 @@ public class Template {
|
||||
@Schema(description = "防御策略模板紧急态字段提取选项")
|
||||
private ProtectLevel protectLevelHigh;
|
||||
|
||||
@JsonProperty("has_protect_level_low")
|
||||
@Schema(description = "日常态字段是否不空", accessMode = Schema.AccessMode.READ_ONLY)
|
||||
private Boolean hasProtectLevelLow;
|
||||
|
||||
@JsonProperty("has_protect_level_medium")
|
||||
@Schema(description = "应急态字段是否不空", accessMode = Schema.AccessMode.READ_ONLY)
|
||||
private Boolean hasProtectLevelMedium;
|
||||
|
||||
@JsonProperty("has_protect_level_high")
|
||||
@Schema(description = "紧急态字段是否不空", accessMode = Schema.AccessMode.READ_ONLY)
|
||||
private Boolean hasProtectLevelHigh;
|
||||
|
||||
@JsonProperty("template_used_times")
|
||||
@Schema(description = "防御策略模板使用次数", example = "20", accessMode = Schema.AccessMode.READ_ONLY)
|
||||
private Integer usedTimes;
|
||||
@@ -59,4 +72,43 @@ public class Template {
|
||||
@JsonProperty("create_user_depart")
|
||||
@Schema(description = "防御策略模板创建人处室", example = "xxx", accessMode = Schema.AccessMode.READ_ONLY)
|
||||
private String createDepart;
|
||||
|
||||
/**
|
||||
* 设置是否含有日常/应急/紧急防护等级态字段的字段
|
||||
*/
|
||||
public void setHasProtectLevel() throws IllegalAccessException {
|
||||
this.hasProtectLevelHigh = hasProtectLevelFields(this.protectLevelHigh);
|
||||
this.hasProtectLevelMedium = hasProtectLevelFields(this.protectLevelMedium);
|
||||
this.hasProtectLevelLow = hasProtectLevelFields(this.protectLevelLow);
|
||||
}
|
||||
|
||||
/**
|
||||
*仅保留是否含有日常/应急/紧急防护等级态字段以及策略模板名称和ID
|
||||
*/
|
||||
public void shortenTemplate() {
|
||||
this.sourceSystem = null;
|
||||
this.description = null;
|
||||
this.protectLevelLow = null;
|
||||
this.protectLevelMedium = null;
|
||||
this.protectLevelHigh = null;
|
||||
this.usedTimes = null;
|
||||
this.runningTasks = null;
|
||||
this.createUserId = null;
|
||||
this.createUsername = null;
|
||||
this.createDepart = null;
|
||||
}
|
||||
|
||||
private Boolean hasProtectLevelFields(ProtectLevel protectLevel) throws IllegalAccessException {
|
||||
return NonEmptyFieldFetcher
|
||||
.getNonEmptyFields(protectLevel) // 获取所有非空字段
|
||||
.stream() // 流式处理
|
||||
.filter(field -> field.getType().getName().contains("Boolean")) // 获取所有类型为Boolean的字段
|
||||
.anyMatch(field -> {
|
||||
try {
|
||||
return (Boolean) field.get(protectLevel); // 返回值为true的字段
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,4 +90,26 @@ public class FiveTupleWithMask {
|
||||
assert protocol != null;
|
||||
this.protocolNum = protocol.getNumber();
|
||||
}
|
||||
|
||||
public void setMask() {
|
||||
if (this.sourceIP != null && this.maskSourceIP == null) {
|
||||
this.maskSourceIP = "255.255.255.255";
|
||||
}
|
||||
|
||||
if (this.sourcePort != null && this.maskSourcePort == null) {
|
||||
this.maskSourcePort = "65535";
|
||||
}
|
||||
|
||||
if (this.destinationIP != null && this.maskDestinationIP == null) {
|
||||
this.maskDestinationIP = "255.255.255.255";
|
||||
}
|
||||
|
||||
if (this.destinationPort != null && this.maskDestinationPort == null) {
|
||||
this.maskDestinationPort = "65535";
|
||||
}
|
||||
|
||||
if (this.protocol != null && this.maskProtocol == null) {
|
||||
this.maskProtocol = "255"; // 协议掩码这里填写255以确保覆盖大部分协议
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ public class TaskCommandInfo {
|
||||
@JsonProperty("task_create_username")
|
||||
private String taskCreateUsername;
|
||||
|
||||
@Schema(description = "任务创建人处室", accessMode = Schema.AccessMode.READ_ONLY)
|
||||
@Schema(description = "任务创建人处室", example = "XXX")
|
||||
@JsonProperty("task_create_depart")
|
||||
private String taskCreateDepart;
|
||||
|
||||
@@ -48,6 +48,14 @@ public class TaskCommandInfo {
|
||||
@JsonProperty("task_act")
|
||||
private String taskAct;
|
||||
|
||||
@Schema(description = "局点", example = "123456")
|
||||
@JsonProperty("distribute_point")
|
||||
private String distributePoint;
|
||||
|
||||
@Schema(description = "事件类型(策略模板名称)", example = "DDOS")
|
||||
@JsonProperty("event_type")
|
||||
private String eventType;
|
||||
|
||||
@Schema(description = "指令下发频率", example = "30")
|
||||
@NotNull(message = "指令下发频率不能为空。")
|
||||
@JsonProperty("frequency")
|
||||
@@ -114,6 +122,8 @@ public class TaskCommandInfo {
|
||||
this.taskName = original.taskName;
|
||||
this.taskType = original.taskType;
|
||||
this.taskAct = original.taskAct;
|
||||
this.distributePoint = original.distributePoint;
|
||||
this.eventType = original.eventType;
|
||||
this.frequency = original.frequency;
|
||||
this.startTime = original.startTime;
|
||||
this.endTime = original.endTime;
|
||||
@@ -132,4 +142,8 @@ public class TaskCommandInfo {
|
||||
public void setProtocolNum() {
|
||||
this.fiveTupleWithMask.setProtocolNum();
|
||||
}
|
||||
|
||||
public void setMask() {
|
||||
this.fiveTupleWithMask.setMask();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ public class GlobalExceptionHandler {
|
||||
@Order(3)
|
||||
@ExceptionHandler(value = {Exception.class})
|
||||
public ResponseResult handleGlobalException(Exception e) {
|
||||
log.error("遭遇全局异常:" + e.getCause());
|
||||
log.error("遭遇全局异常:{}", e.getMessage());
|
||||
return ResponseResult.error().setMessage(e.getMessage());
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ public class GlobalExceptionHandler {
|
||||
SQLIntegrityConstraintViolationException.class
|
||||
})
|
||||
public ResponseResult handleSQLException(Exception e) {
|
||||
log.info("遭遇数据库异常:" + e.getMessage());
|
||||
log.info("遭遇数据库异常:{}", e.getMessage());
|
||||
return ResponseResult.invalid().setMessage(
|
||||
"请检查json字段的完整性,确保json字段按照文档中要求填写。");
|
||||
}
|
||||
@@ -74,14 +74,14 @@ public class GlobalExceptionHandler {
|
||||
IllegalStateException.class
|
||||
})
|
||||
public ResponseResult handleHandlerMethodValidationException(Exception e) {
|
||||
log.debug("遭遇非法参数异常:" + e.getMessage());
|
||||
log.debug("遭遇非法参数异常:{}", e.getMessage());
|
||||
return ResponseResult.invalid().setMessage(e.getMessage());
|
||||
}
|
||||
|
||||
@Order(2)
|
||||
@ExceptionHandler(value = NotLoginException.class)
|
||||
public ResponseResult handleNotLoginException(NotLoginException e) {
|
||||
log.debug("遭遇Sa-Token登录异常,登录类型为:" + e.getLoginType());
|
||||
log.debug("遭遇Sa-Token登录异常,登录类型为:{}", e.getLoginType());
|
||||
return new ResponseResult(
|
||||
401,
|
||||
e.getMessage()
|
||||
@@ -91,14 +91,14 @@ public class GlobalExceptionHandler {
|
||||
@Order(2)
|
||||
@ExceptionHandler(value = SaTokenException.class)
|
||||
public ResponseResult handleSaTokenException(SaTokenException e) {
|
||||
log.debug("Sa-token模块遭遇异常:" + e.getMessage());
|
||||
log.debug("Sa-token模块遭遇异常:{}", e.getMessage());
|
||||
return ResponseResult.unAuthorized().setMessage(e.getMessage());
|
||||
}
|
||||
|
||||
@Order(2)
|
||||
@ExceptionHandler(value = DorisStartException.class)
|
||||
public ResponseResult handleDorisStartException(DorisStartException e) {
|
||||
log.warn("Doris数据库遭遇异常:" + e.getMessage());
|
||||
log.warn("Doris数据库遭遇异常:{}", e.getMessage());
|
||||
ResponseResult responseResult = ResponseResult.error()
|
||||
.setMessage("Doris数据库指令生成遭遇异常:" + e.getMessage());
|
||||
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.realtime.protection.configuration.utils;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class NonEmptyFieldFetcher {
|
||||
public static List<Field> getNonEmptyFields(Object object) throws IllegalAccessException {
|
||||
List<Field> nonEmptyFields = new ArrayList<>();
|
||||
Class<?> clazz = object.getClass();
|
||||
|
||||
// 获取类中所有的字段,包括继承的字段
|
||||
Field[] fields = clazz.getDeclaredFields();
|
||||
|
||||
for (Field field : fields) {
|
||||
// 打开字段的访问权限
|
||||
field.setAccessible(true);
|
||||
|
||||
// 获取字段的值
|
||||
Object value = field.get(object);
|
||||
|
||||
// 检查字段是否非空
|
||||
if (value != null) {
|
||||
nonEmptyFields.add(field);
|
||||
}
|
||||
}
|
||||
|
||||
return nonEmptyFields;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
package com.realtime.protection.configuration.utils.enums;
|
||||
|
||||
import com.realtime.protection.configuration.entity.rule.staticrule.StaticRuleObject;
|
||||
import com.realtime.protection.configuration.utils.NonEmptyFieldFetcher;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.*;
|
||||
|
||||
public enum RuleEnum {
|
||||
// 不带掩码规则的五元组规则类型对应表
|
||||
SIP_SPORT_DIP_PROTOCOL("SIP_SPORT_DIP_PROTOCOL"),
|
||||
SIP_DIP_DPORT_PROTOCOL("SIP_DIP_DPORT_PROTOCOL"),
|
||||
SIP_SPORT_PROTOCOL("SIP_SPORT_PROTOCOL"),
|
||||
SIP_DIP_PROTOCOL("SIP_DIP_PROTOCOL"),
|
||||
SIP_DPORT_PROTOCOL("SIP_DPORT_PROTOCOL"),
|
||||
SPORT_DIP_PROTOCOL("SPORT_DIP_PROTOCOL"),
|
||||
DIP_DPORT_PROTOCOL("DIP_DPORT_PROTOCOL"),
|
||||
SIP_DIP("SIP_DIP"),
|
||||
SIP_PROTOCOL("SIP_PROTOCOL"),
|
||||
DIP_PROTOCOL("DIP_PROTOCOL"),
|
||||
SIP("SIP"),
|
||||
DIP("DIP"),
|
||||
// 带掩码规则的五元组规则类型对应表
|
||||
DIP_MDIP("DIP_MDIP"),
|
||||
DIP_MDIP_PROTOCOL_MPROTOCOL("DIP_MDIP_PROTOCOL_MPROTOCOL"),
|
||||
DIP_MDIP_DPORT_MDPORT_PROTOCOL_MPROTOCOL("DIP_MDIP_DPORT_MDPORT_PROTOCOL_MPROTOCOL"),
|
||||
SPORT_MSPORT_DIP_MDIP_PROTOCOL_MPROTOCOL("SPORT_MSPORT_DIP_MDIP_PROTOCOL_MPROTOCOL"),
|
||||
SPORT_MSPORT_DIP_MDIP_DPORT_MDPORT_PROTOCOL_MPROTOCOL("SPORT_MSPORT_DIP_MDIP_DPORT_MDPORT_PROTOCOL_MPROTOCOL"),
|
||||
SIP_MSIP("SIP_MSIP"),
|
||||
SIP_MSIP_PROTOCOL_MPROTOCOL("SIP_MSIP_PROTOCOL_MPROTOCOL"),
|
||||
SIP_MSIP_DPORT_MDPORT_PROTOCOL_MPROTOCOL("SIP_MSIP_DPORT_MDPORT_PROTOCOL_MPROTOCOL"),
|
||||
SIP_MSIP_SPORT_MSPORT_PROTOCOL_MPROTOCOL("SIP_MSIP_SPORT_MSPORT_PROTOCOL_MPROTOCOL"),
|
||||
SIP_MSIP_SPORT_MSPORT_DPORT_MDPORT_PROTOCOL_MPROTOCOL("SIP_MSIP_SPORT_MSPORT_DPORT_MDPORT_PROTOCOL_MPROTOCOL"),
|
||||
SIP_MSIP_DIP_MDIP("SIP_MSIP_DIP_MDIP"),
|
||||
SIP_MSIP_DIP_MDIP_PROTOCOL_MPROTOCOL("SIP_MSIP_DIP_MDIP_PROTOCOL_MPROTOCOL"),
|
||||
SIP_MSIP_DIP_MDIP_DPORT_MDPORT_PROTOCOL_MPROTOCOL("SIP_MSIP_DIP_MDIP_DPORT_MDPORT_PROTOCOL_MPROTOCOL"),
|
||||
SIP_MSIP_SPORT_MSPORT_DIP_MDIP_PROTOCOL_MPROTOCOL("SIP_MSIP_SPORT_MSPORT_DIP_MDIP_PROTOCOL_MPROTOCOL"),
|
||||
SIP_MSIP_SPORT_MSPORT_DIP_MDIP_DPORT_MDPORT_PROTOCOL_MPROTOCOL("SIP_MSIP_SPORT_MSPORT_DIP_MDIP_DPORT_MDPORT_PROTOCOL_MPROTOCOL")
|
||||
;
|
||||
|
||||
private final Set<String> rule;
|
||||
private static final List<Set<String>> ruleEnumList = new ArrayList<>();
|
||||
|
||||
static {
|
||||
for (RuleEnum ruleEnum : RuleEnum.values()) {
|
||||
ruleEnumList.add(ruleEnum.rule);
|
||||
}
|
||||
}
|
||||
|
||||
RuleEnum(String ruleName) {
|
||||
this.rule = new HashSet<>(Arrays.stream(ruleName.split("_")).toList());
|
||||
}
|
||||
|
||||
public static Boolean checkValidate(StaticRuleObject staticRuleObject) throws IllegalAccessException {
|
||||
List<Field> nonEmptyFields = NonEmptyFieldFetcher.getNonEmptyFields(staticRuleObject);
|
||||
List<String> fieldNames = new java.util.ArrayList<>(List.of());
|
||||
for (Field field : nonEmptyFields) {
|
||||
String fieldName = field.getName().toUpperCase().replace("STATICRULE", "");
|
||||
// 将合理的非空字段加入fieldNames中
|
||||
// 需要去掉STATICRULE字段,仅保留后面的字段
|
||||
if (fieldName.contains("IP")
|
||||
|| fieldName.contains("PORT")
|
||||
|| fieldName.contains("PROTOCOL")) fieldNames.add(fieldName);
|
||||
}
|
||||
return ruleEnumList.stream().anyMatch(rule -> rule.equals(new HashSet<>(fieldNames)));
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.realtime.protection.configuration.utils.enums;
|
||||
|
||||
import com.realtime.protection.configuration.utils.status.State;
|
||||
import com.realtime.protection.server.task.status.states.*;
|
||||
import lombok.Getter;
|
||||
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
package com.realtime.protection.configuration.utils.enums.audit;
|
||||
|
||||
import com.realtime.protection.configuration.utils.enums.audit.states.*;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Getter
|
||||
public enum AuditStatusEnum {
|
||||
PENDING(0, new PendingState()), // 未审核状态
|
||||
RETURNED(1, new ReturnedState()), // 退回状态
|
||||
AUDITED(2, new AuditedState()), // 已审核状态
|
||||
USING(3, new UsingState()); // 使用中状态
|
||||
|
||||
private final Integer num;
|
||||
private final State state;
|
||||
private static final Map<Integer, State> NumToStateMap = new HashMap<>();
|
||||
private static final Map<State, Integer> StateToNumMap = new HashMap<>();
|
||||
private static final Map<State, AuditStatusEnum> StateToAuditStatusEnumMap = new HashMap<>();
|
||||
|
||||
static {
|
||||
for (AuditStatusEnum status : AuditStatusEnum.values()) {
|
||||
NumToStateMap.put(status.getNum(), status.getState());
|
||||
StateToNumMap.put(status.getState(), status.getNum());
|
||||
StateToAuditStatusEnumMap.put(status.getState(), status);
|
||||
}
|
||||
}
|
||||
|
||||
AuditStatusEnum(int auditStatus, State state) {
|
||||
this.num = auditStatus;
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
public static State getStateByNum(Integer auditStatusNum) {
|
||||
if (auditStatusNum == null) {
|
||||
return null;
|
||||
}
|
||||
return NumToStateMap.get(auditStatusNum);
|
||||
}
|
||||
|
||||
public static Integer getNumByState(State state) {
|
||||
if (state == null) {
|
||||
return null;
|
||||
}
|
||||
return StateToNumMap.get(state);
|
||||
}
|
||||
|
||||
public static AuditStatusEnum getAuditStatusEnumByState(State state) {
|
||||
if (state == null) {
|
||||
return null;
|
||||
}
|
||||
return StateToAuditStatusEnumMap.get(state);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.realtime.protection.configuration.utils.enums.audit;
|
||||
|
||||
import com.realtime.protection.configuration.utils.enums.audit.states.State;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@Slf4j
|
||||
public class AuditStatusValidator {
|
||||
|
||||
private final State auditStatusOriginal;
|
||||
|
||||
public AuditStatusValidator(Integer auditStatusOriginal) {
|
||||
this.auditStatusOriginal = AuditStatusEnum.getStateByNum(auditStatusOriginal);
|
||||
}
|
||||
|
||||
public static AuditStatusValidator setOriginal(Integer auditStatusOriginal) {
|
||||
return new AuditStatusValidator(auditStatusOriginal);
|
||||
}
|
||||
|
||||
public Boolean checkValidate(Integer newAuditStatus) {
|
||||
State newState = AuditStatusEnum.getStateByNum(newAuditStatus);
|
||||
if (newState == null) {
|
||||
return false;
|
||||
}
|
||||
return auditStatusOriginal.checkValidate(newState);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.realtime.protection.configuration.utils.enums.audit.states;
|
||||
|
||||
import com.realtime.protection.configuration.utils.enums.audit.AuditStatusEnum;
|
||||
|
||||
public class AuditedState implements State {
|
||||
@Override
|
||||
public Boolean checkValidate(State newState) {
|
||||
return switch (AuditStatusEnum.getAuditStatusEnumByState(newState)) {
|
||||
case RETURNED -> false;
|
||||
case PENDING, USING, AUDITED -> true;
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.realtime.protection.configuration.utils.enums.audit.states;
|
||||
|
||||
import com.realtime.protection.configuration.utils.enums.audit.AuditStatusEnum;
|
||||
|
||||
public class PendingState implements State {
|
||||
@Override
|
||||
public Boolean checkValidate(State newState) {
|
||||
return switch (AuditStatusEnum.getAuditStatusEnumByState(newState)) {
|
||||
case USING -> false;
|
||||
case PENDING, RETURNED, AUDITED -> true;
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.realtime.protection.configuration.utils.enums.audit.states;
|
||||
|
||||
import com.realtime.protection.configuration.utils.enums.audit.AuditStatusEnum;
|
||||
|
||||
public class ReturnedState implements State {
|
||||
@Override
|
||||
public Boolean checkValidate(State newState) {
|
||||
return switch (AuditStatusEnum.getAuditStatusEnumByState(newState)) {
|
||||
case PENDING, RETURNED -> true;
|
||||
case AUDITED, USING -> false;
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package com.realtime.protection.configuration.utils.enums.audit.states;
|
||||
|
||||
public interface State {
|
||||
Boolean checkValidate(State newState);
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.realtime.protection.configuration.utils.enums.audit.states;
|
||||
|
||||
import com.realtime.protection.configuration.utils.enums.audit.AuditStatusEnum;
|
||||
|
||||
public class UsingState implements State {
|
||||
@Override
|
||||
public Boolean checkValidate(State newState) {
|
||||
return switch (AuditStatusEnum.getAuditStatusEnumByState(newState)) {
|
||||
case AUDITED, USING -> true;
|
||||
case PENDING, RETURNED -> false;
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
package com.realtime.protection.configuration.utils.status;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
public enum AuditStatus {
|
||||
PENDING(0),
|
||||
UNAUDITED(1),
|
||||
AUDITED(2);
|
||||
|
||||
private final int auditStatus;
|
||||
|
||||
AuditStatus(int auditStatus) {
|
||||
this.auditStatus = auditStatus;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
package com.realtime.protection.configuration.utils.status;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@Slf4j
|
||||
public class AuditStatusValidator {
|
||||
|
||||
private final Integer auditStatusOriginal;
|
||||
|
||||
public AuditStatusValidator(Integer auditStatusOriginal) {
|
||||
this.auditStatusOriginal = auditStatusOriginal;
|
||||
}
|
||||
|
||||
public static AuditStatusValidator setOriginal(Integer auditStatusOriginal) {
|
||||
return new AuditStatusValidator(auditStatusOriginal);
|
||||
}
|
||||
|
||||
public Boolean checkValidate(Integer newAuditStatus) {
|
||||
switch (newAuditStatus) {
|
||||
case 0, 1 -> {
|
||||
return auditStatusOriginal != 2;
|
||||
}
|
||||
case 2 -> {
|
||||
return auditStatusOriginal != 1;
|
||||
}
|
||||
default -> {
|
||||
log.debug("欲修改的审核状态不正确,需要使用正确的审核状态,当前的审核状态:" + auditStatusOriginal);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
package com.realtime.protection.configuration.utils.status;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
public enum StateNum {
|
||||
PENDING(0),
|
||||
RUNNING(1),
|
||||
PAUSED(2),
|
||||
STOPPED(3),
|
||||
FAILED(4),
|
||||
FINISHED(5);
|
||||
|
||||
private final int stateNum;
|
||||
|
||||
StateNum(int stateNum) {
|
||||
this.stateNum = stateNum;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -32,7 +32,7 @@ public class AlertMessageService {
|
||||
public void processAlertMessage(AlertMessage alertMessage) {
|
||||
//根据告警信息——>生成指令
|
||||
List<TaskCommandInfo> dynamicTaskCommandInfoList = generateDynamicCommand(alertMessage);
|
||||
//获取任务状态,设置指令的isValid字段,且是否生成指令入库(除了RUNING\PAUSED状态,其他都不入库)。
|
||||
//获取任务状态,设置指令的isValid字段,且是否生成指令入库(除了RUNING\PAUSED状态,其他都不入command库)。
|
||||
Integer taskStatus = dynamicTaskCommandInfoList.get(0).getTaskStatus();
|
||||
//获取任务类型,设置指令的isJudged字段。
|
||||
Integer taskType = dynamicTaskCommandInfoList.get(0).getTaskType();
|
||||
@@ -89,7 +89,7 @@ public class AlertMessageService {
|
||||
alertMessage.getProtectIsSrcOrDst(), templateProtectLevel);
|
||||
|
||||
//根据fiveTuple生成动态指令信息
|
||||
List<TaskCommandInfo> dynamicCommandInfoList = new ArrayList<TaskCommandInfo>();
|
||||
List<TaskCommandInfo> dynamicCommandInfoList = new ArrayList<>();
|
||||
if (fiveTupleWithMaskNew.size() == 2){
|
||||
TaskCommandInfo dynamicCommandInfo_bi = new TaskCommandInfo();
|
||||
dynamicCommandInfo_bi.copyTaskCommandInfo(dynamicCommandInfo);
|
||||
@@ -203,7 +203,7 @@ public class AlertMessageService {
|
||||
peer.setPort(null);
|
||||
peer.setMaskPort(null);
|
||||
}
|
||||
List<FiveTupleWithMask> newFiveTupleWithMask = new ArrayList<FiveTupleWithMask>();
|
||||
List<FiveTupleWithMask> newFiveTupleWithMask = new ArrayList<>();
|
||||
//生成指令
|
||||
FiveTupleWithMask command1 = new FiveTupleWithMask();
|
||||
command1.setSourceIP(peer.getIP());
|
||||
|
||||
@@ -3,7 +3,7 @@ package com.realtime.protection.server.defense.object;
|
||||
import com.alibaba.excel.util.ListUtils;
|
||||
import com.realtime.protection.configuration.entity.defense.object.ProtectObject;
|
||||
import com.realtime.protection.configuration.utils.SqlSessionWrapper;
|
||||
import com.realtime.protection.configuration.utils.status.AuditStatusValidator;
|
||||
import com.realtime.protection.configuration.utils.enums.audit.AuditStatusValidator;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.realtime.protection.server.defense.template;
|
||||
|
||||
import com.realtime.protection.configuration.entity.defense.template.Template;
|
||||
import lombok.SneakyThrows;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@@ -44,6 +45,21 @@ public class TemplateService {
|
||||
return templateMapper.queryTemplate(templateId);
|
||||
}
|
||||
|
||||
public List<Template> queryTemplatesShort() {
|
||||
List<Template> templates = templateMapper.queryTemplates(null, null, null, 1, 10000);
|
||||
|
||||
templates.forEach(template -> {
|
||||
try {
|
||||
template.setHasProtectLevel();
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
});
|
||||
templates.forEach(Template::shortenTemplate);
|
||||
|
||||
return templates;
|
||||
}
|
||||
|
||||
public Boolean deleteTemplate(Integer templateId) {
|
||||
return templateMapper.deleteTemplate(templateId);
|
||||
}
|
||||
|
||||
@@ -14,7 +14,9 @@ import org.springframework.web.multipart.MultipartFile;
|
||||
import java.io.IOException;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
@RestController
|
||||
@@ -163,7 +165,7 @@ public class StaticRuleController implements StaticRuleControllerApi {
|
||||
public ResponseResult updateStaticRuleAuditStatus(@PathVariable Integer id, @PathVariable Integer auditStatus) {
|
||||
if (id <= 0 || auditStatus < 0 || auditStatus > 2) {
|
||||
return new ResponseResult(400, "id or status is invalid")
|
||||
.setData("whiteobj_id", id)
|
||||
.setData("staticRule_id", id)
|
||||
.setData("success", false);
|
||||
}
|
||||
return ResponseResult.ok()
|
||||
@@ -173,4 +175,29 @@ public class StaticRuleController implements StaticRuleControllerApi {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 批量修改审核状态
|
||||
*/
|
||||
@PostMapping("/auditbatch")
|
||||
public ResponseResult updateStaticRuleAuditStatusBatch(@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("staticRule_id", errorIds)
|
||||
.setData("success", false);
|
||||
}
|
||||
|
||||
return ResponseResult.ok()
|
||||
.setData("success", staticRuleService.updateAuditStatusBatch(idsWithAuditStatusMap));
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Mapper
|
||||
public interface StaticRuleMapper {
|
||||
@@ -43,4 +44,6 @@ public interface StaticRuleMapper {
|
||||
String static_rule_create_username, String ip);
|
||||
|
||||
List<StaticRuleObject> queryStaticRuleByIds(List<Integer> ids);
|
||||
|
||||
void updateAuditStatusByIdBatch(@Param("idWithAuditStatusBatch")Map<Integer, Integer> idWithAuditStatusBatch);
|
||||
}
|
||||
|
||||
@@ -3,7 +3,10 @@ package com.realtime.protection.server.rule.staticrule;
|
||||
import com.alibaba.excel.util.ListUtils;
|
||||
import com.realtime.protection.configuration.entity.rule.staticrule.StaticRuleObject;
|
||||
import com.realtime.protection.configuration.utils.SqlSessionWrapper;
|
||||
import com.realtime.protection.configuration.utils.status.AuditStatusValidator;
|
||||
import com.realtime.protection.configuration.utils.enums.RuleEnum;
|
||||
import com.realtime.protection.configuration.utils.enums.audit.AuditStatusEnum;
|
||||
import com.realtime.protection.configuration.utils.enums.audit.AuditStatusValidator;
|
||||
import lombok.SneakyThrows;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@@ -14,6 +17,7 @@ import java.time.LocalDateTime;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.function.Function;
|
||||
|
||||
@Service
|
||||
@@ -49,6 +53,7 @@ public class StaticRuleService {
|
||||
/*
|
||||
新建静态规则
|
||||
*/
|
||||
@SneakyThrows
|
||||
public Integer newStaticRuleObject(StaticRuleObject object) {
|
||||
|
||||
object.setStaticRuleCreateTime(LocalDateTime.now());
|
||||
@@ -61,6 +66,9 @@ public class StaticRuleService {
|
||||
){
|
||||
throw new IllegalArgumentException("IP和IP掩码不匹配");
|
||||
}
|
||||
if (!RuleEnum.checkValidate(object)) {
|
||||
throw new IllegalArgumentException("静态规则不符合指定的配置方法,请参考规则模板以配置静态规则");
|
||||
}
|
||||
staticRuleMapper.newStaticRuleObject(object);
|
||||
|
||||
return object.getStaticRuleId();
|
||||
@@ -98,7 +106,22 @@ public class StaticRuleService {
|
||||
return sqlSessionWrapper.startBatchSession(StaticRuleMapper.class, deleteStaticRulesFunction, staticRuleIds);
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
@Transactional
|
||||
public Boolean updateStaticRule(Integer id, StaticRuleObject object) {
|
||||
StaticRuleObject staticRuleObject = staticRuleMapper.queryStaticRuleById(id);
|
||||
if (staticRuleObject == null) {
|
||||
throw new IllegalArgumentException("未知的静态规则ID");
|
||||
}
|
||||
|
||||
if (Objects.equals(staticRuleObject.getStaticRuleAuditStatus(), AuditStatusEnum.USING.getNum())) {
|
||||
throw new IllegalArgumentException("静态规则当前正在使用,无法更新");
|
||||
}
|
||||
|
||||
if (!RuleEnum.checkValidate(object)) {
|
||||
throw new IllegalArgumentException("静态规则不符合指定的配置方法,请参考规则模板以配置静态规则");
|
||||
}
|
||||
|
||||
//判断当前静态规则是否能够修改---是否存在任务选择的静态规则??
|
||||
//按id查询该静态规则的used_task_id字段,如果不为空,则不能修改
|
||||
object.setStaticRuleModifyTime(LocalDateTime.now());
|
||||
@@ -131,7 +154,7 @@ public class StaticRuleService {
|
||||
}
|
||||
|
||||
List<StaticRuleObject> StaticRuleBatch = ListUtils.newArrayListWithExpectedSize(100);
|
||||
for (StaticRuleObject staticRule : staticRuleList) {
|
||||
for (StaticRuleObject staticRule : list) {
|
||||
staticRule.setStaticRuleCreateTime(LocalDateTime.now());
|
||||
StaticRuleBatch.add(staticRule);
|
||||
if (StaticRuleBatch.size() < 100) {
|
||||
@@ -169,7 +192,16 @@ public class StaticRuleService {
|
||||
return resultMap;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void deleteStaticRuleById(Integer id) {
|
||||
StaticRuleObject staticRuleObject = staticRuleMapper.queryStaticRuleById(id);
|
||||
if (staticRuleObject == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (Objects.equals(staticRuleObject.getStaticRuleAuditStatus(), AuditStatusEnum.USING.getNum())) {
|
||||
throw new IllegalArgumentException("当前静态规则正在使用,无法删除");
|
||||
}
|
||||
staticRuleMapper.deleteStaticRuleById(id);
|
||||
}
|
||||
|
||||
@@ -182,4 +214,31 @@ public class StaticRuleService {
|
||||
public List<StaticRuleObject> queryStaticRuleByIds(List<Integer> ids) {
|
||||
return staticRuleMapper.queryStaticRuleByIds(ids);
|
||||
}
|
||||
|
||||
public Object updateAuditStatusBatch(Map<Integer, Integer> idsWithAuditStatusMap) {
|
||||
|
||||
Function<StaticRuleMapper, Function<Map<Integer, Integer>, Boolean>> updateStaticRuleAuditStatusFunction =
|
||||
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(StaticRuleMapper.class, updateStaticRuleAuditStatusFunction, idsWithAuditStatusMap);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import com.realtime.protection.configuration.entity.task.DynamicTaskInfo;
|
||||
import com.realtime.protection.configuration.entity.task.Task;
|
||||
import com.realtime.protection.configuration.entity.task.TaskCommandInfo;
|
||||
import com.realtime.protection.configuration.utils.enums.StateEnum;
|
||||
import com.realtime.protection.configuration.utils.status.AuditStatusValidator;
|
||||
import com.realtime.protection.configuration.utils.enums.audit.AuditStatusValidator;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
@@ -109,7 +109,12 @@ public class TaskService {
|
||||
|
||||
public List<TaskCommandInfo> getStaticCommandInfos(Long taskId) {
|
||||
List<TaskCommandInfo> staticCommandInfos = taskMapper.getStaticCommandInfos(taskId);
|
||||
staticCommandInfos.forEach(TaskCommandInfo::setProtocolNum);
|
||||
|
||||
staticCommandInfos.forEach(taskCommandInfo -> {
|
||||
taskCommandInfo.setProtocolNum();
|
||||
taskCommandInfo.setMask();
|
||||
});
|
||||
|
||||
return staticCommandInfos;
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ package com.realtime.protection.server.task.status;
|
||||
import com.baomidou.dynamic.datasource.annotation.DSTransactional;
|
||||
import com.realtime.protection.configuration.exception.DorisStartException;
|
||||
import com.realtime.protection.configuration.utils.enums.StateEnum;
|
||||
import com.realtime.protection.configuration.utils.status.State;
|
||||
import com.realtime.protection.server.task.status.states.State;
|
||||
import com.realtime.protection.server.command.CommandService;
|
||||
import com.realtime.protection.server.task.TaskService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -98,7 +98,7 @@ public class StateChangeService {
|
||||
@Async
|
||||
protected void finishTasks() {
|
||||
List<Long> finishedTaskIds = taskService.getFinishedTasks();
|
||||
log.debug("成功扫描出所有需要变为结束状态的任务:" + finishedTaskIds);
|
||||
log.debug("成功扫描出所有需要变为结束状态的任务:{}", finishedTaskIds);
|
||||
|
||||
for (Long taskId : finishedTaskIds) {
|
||||
try {
|
||||
|
||||
@@ -5,7 +5,7 @@ import com.realtime.protection.configuration.entity.task.Task;
|
||||
import com.realtime.protection.configuration.entity.task.TaskCommandInfo;
|
||||
import com.realtime.protection.configuration.response.SimpleResponse;
|
||||
import com.realtime.protection.configuration.utils.enums.TaskTypeEnum;
|
||||
import com.realtime.protection.configuration.utils.status.AuditStatus;
|
||||
import com.realtime.protection.configuration.utils.enums.audit.AuditStatusEnum;
|
||||
import com.realtime.protection.server.command.CommandService;
|
||||
import com.realtime.protection.server.task.TaskService;
|
||||
import org.springframework.http.HttpStatus;
|
||||
@@ -36,7 +36,7 @@ public class StateHandler {
|
||||
}
|
||||
|
||||
// 如果审核状态不为已通过审核,则报错
|
||||
if (taskAuditStatus != AuditStatus.AUDITED.getAuditStatus()) {
|
||||
if (taskAuditStatus != AuditStatusEnum.AUDITED.getNum()) {
|
||||
throw new IllegalArgumentException("无效的task_id,因为未通过审核");
|
||||
}
|
||||
|
||||
@@ -75,14 +75,11 @@ public class StateHandler {
|
||||
// todo: 如果是实时任务或者研判后处置任务,那么就需要在任务启动之后,立刻向动态规则中指定的系统发送日志筛选请求。
|
||||
// 筛选完成后,系统返回日志,需要由接收端点提取字段,并且合成一条静态规则,再按照任务开始时间、结束时间和任务类型进行指令创建
|
||||
private Boolean handleJudgedTaskStart(TaskService taskService, Long taskId) {
|
||||
// return sendFilters(taskService, taskId);
|
||||
// 还没配置帅选条件发送的url,不配置会出错,所以先注释
|
||||
return true;
|
||||
return sendFilters(taskService, taskId);
|
||||
}
|
||||
|
||||
private Boolean handleDynamicTaskStart(TaskService taskService, Long taskId) {
|
||||
// return sendFilters(taskService, taskId);
|
||||
return true;
|
||||
return sendFilters(taskService, taskId);
|
||||
}
|
||||
|
||||
private Boolean handleStaticTaskStart(CommandService commandService, TaskService taskService, Long taskId) {
|
||||
@@ -106,7 +103,7 @@ public class StateHandler {
|
||||
AtomicReference<Boolean> success = new AtomicReference<>(false);
|
||||
|
||||
Mono<SimpleResponse> mono = client.post()
|
||||
.uri("") // todo: unfinished
|
||||
.uri("http://192.168.107.89:9081/api/v1/kafkasend") // todo: untested
|
||||
.bodyValue(dynamicTaskInfos)
|
||||
.exchangeToMono(res -> {
|
||||
if (res.statusCode().equals(HttpStatus.OK)) {
|
||||
|
||||
@@ -2,7 +2,6 @@ package com.realtime.protection.server.task.status.states;
|
||||
|
||||
import com.realtime.protection.configuration.exception.DorisStartException;
|
||||
import com.realtime.protection.configuration.utils.enums.StateEnum;
|
||||
import com.realtime.protection.configuration.utils.status.State;
|
||||
import com.realtime.protection.server.command.CommandService;
|
||||
import com.realtime.protection.server.task.TaskService;
|
||||
import com.realtime.protection.server.task.status.StateHandler;
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.realtime.protection.server.task.status.states;
|
||||
|
||||
import com.realtime.protection.configuration.utils.status.State;
|
||||
import com.realtime.protection.server.command.CommandService;
|
||||
import com.realtime.protection.server.task.TaskService;
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.realtime.protection.server.task.status.states;
|
||||
|
||||
import com.realtime.protection.configuration.utils.enums.StateEnum;
|
||||
import com.realtime.protection.configuration.utils.status.State;
|
||||
import com.realtime.protection.server.command.CommandService;
|
||||
import com.realtime.protection.server.task.TaskService;
|
||||
import com.realtime.protection.server.task.status.StateHandler;
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.realtime.protection.server.task.status.states;
|
||||
|
||||
import com.realtime.protection.configuration.utils.enums.StateEnum;
|
||||
import com.realtime.protection.configuration.utils.status.State;
|
||||
import com.realtime.protection.server.command.CommandService;
|
||||
import com.realtime.protection.server.task.TaskService;
|
||||
import com.realtime.protection.server.task.status.StateHandler;
|
||||
|
||||
@@ -2,7 +2,6 @@ package com.realtime.protection.server.task.status.states;
|
||||
|
||||
import com.realtime.protection.configuration.exception.DorisStartException;
|
||||
import com.realtime.protection.configuration.utils.enums.StateEnum;
|
||||
import com.realtime.protection.configuration.utils.status.State;
|
||||
import com.realtime.protection.server.command.CommandService;
|
||||
import com.realtime.protection.server.task.TaskService;
|
||||
import com.realtime.protection.server.task.status.StateHandler;
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.realtime.protection.server.task.status.states;
|
||||
|
||||
import com.realtime.protection.configuration.utils.enums.StateEnum;
|
||||
import com.realtime.protection.configuration.utils.status.State;
|
||||
import com.realtime.protection.server.command.CommandService;
|
||||
import com.realtime.protection.server.task.TaskService;
|
||||
import com.realtime.protection.server.task.status.StateHandler;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.realtime.protection.configuration.utils.status;
|
||||
package com.realtime.protection.server.task.status.states;
|
||||
|
||||
import com.realtime.protection.configuration.exception.DorisStartException;
|
||||
import com.realtime.protection.server.command.CommandService;
|
||||
@@ -2,7 +2,6 @@ package com.realtime.protection.server.task.status.states;
|
||||
|
||||
import com.realtime.protection.configuration.exception.DorisStartException;
|
||||
import com.realtime.protection.configuration.utils.enums.StateEnum;
|
||||
import com.realtime.protection.configuration.utils.status.State;
|
||||
import com.realtime.protection.server.command.CommandService;
|
||||
import com.realtime.protection.server.task.TaskService;
|
||||
import com.realtime.protection.server.task.status.StateHandler;
|
||||
|
||||
@@ -5,7 +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.whitelist.WhiteListObject;
|
||||
import com.realtime.protection.configuration.utils.SqlSessionWrapper;
|
||||
import com.realtime.protection.configuration.utils.status.AuditStatusValidator;
|
||||
import com.realtime.protection.configuration.utils.enums.audit.AuditStatusValidator;
|
||||
import com.realtime.protection.server.rule.staticrule.StaticRuleMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@@ -20,6 +20,10 @@
|
||||
<result column="task_end_time" property="endTime"/>
|
||||
|
||||
<result column="template_id" property="templateId"/>
|
||||
|
||||
<result column="dynamic_rule_range" property="distributePoint"/>
|
||||
<result column="strategy_template_name" property="eventType"/>
|
||||
|
||||
<result column="dynamic_rule_protect_level" property="protectLevel"/>
|
||||
<result column="task_status" property="taskStatus"/>
|
||||
</resultMap>
|
||||
@@ -149,12 +153,17 @@
|
||||
t_task.task_end_time,
|
||||
|
||||
t_dr.template_id,
|
||||
t_dr.dynamic_rule_range,
|
||||
t_dr.dynamic_rule_protect_level,
|
||||
t_task.task_status
|
||||
t_task.task_status,
|
||||
|
||||
t_tmplate.strategy_template_name
|
||||
|
||||
from t_task
|
||||
left join realtime_protection.t_dynamic_rule t_dr on
|
||||
(t_task.task_id = t_dr.dynamic_rule_used_task_id and t_dr.dynamic_rule_id = #{dynamicRuleId})
|
||||
left join realtime_protection.t_strategy_template t_tmplate on
|
||||
( t_dr.template_id = t_tmplate.strategy_template_id )
|
||||
where
|
||||
t_task.task_id = #{taskId}
|
||||
</select>
|
||||
|
||||
@@ -4,12 +4,13 @@
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.realtime.protection.server.command.CommandMapper">
|
||||
<insert id="createCommand" parameterType="com.realtime.protection.configuration.entity.task.TaskCommandInfo">
|
||||
insert into t_command(COMMAND_ID, TASK_ID, TASK_ACT, FREQUENCY, ADDR_TYPE, SRC_IP, SRC_PORT, DST_IP, DST_PORT,
|
||||
PROTOCOL,
|
||||
insert into t_command(COMMAND_ID, TASK_ID, TASK_ACT, TASKNAME, EVENTTYPE, DEPARTMENT, DISTRIBUTEPOINT, FREQUENCY,
|
||||
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, IS_JUDGED,
|
||||
SEND_TIMES, SUCCESS_TIMES, CREATE_TIME, LAST_UPDATE, IS_DELETED)
|
||||
values (#{info.UUID}, #{info.taskId}, #{info.taskAct}, #{info.frequency},
|
||||
values (#{info.UUID}, #{info.taskId}, #{info.taskAct}, #{info.taskName}, #{info.eventType}, #{info.taskCreateDepart}, #{info.distributePoint},
|
||||
#{info.frequency},
|
||||
DEFAULT,
|
||||
#{info.fiveTupleWithMask.sourceIP}, #{info.fiveTupleWithMask.sourcePort},
|
||||
#{info.fiveTupleWithMask.destinationIP}, #{info.fiveTupleWithMask.destinationPort},
|
||||
@@ -24,14 +25,16 @@
|
||||
</insert>
|
||||
|
||||
<insert id="createCommands" parameterType="com.realtime.protection.configuration.entity.task.TaskCommandInfo">
|
||||
insert into t_command(COMMAND_ID, TASK_ID, TASK_ACT, FREQUENCY, ADDR_TYPE, SRC_IP, SRC_PORT, DST_IP, DST_PORT,
|
||||
PROTOCOL,
|
||||
insert into t_command(
|
||||
COMMAND_ID, TASK_ID, TASK_ACT, TASK_NAME, EVENT_TYPE, DEPARTMENT, DISTRIBUTEPOINT, FREQUENCY,
|
||||
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,
|
||||
IS_JUDGED,
|
||||
SEND_TIMES, SUCCESS_TIMES, CREATE_TIME, LAST_UPDATE, IS_DELETED)
|
||||
values
|
||||
<foreach collection="command_infos" item="info" separator=",">
|
||||
(#{info.UUID}, #{info.taskId}, #{info.taskAct}, #{info.frequency},
|
||||
(#{info.UUID}, #{info.taskId}, #{info.taskAct}, #{info.taskName}, #{info.eventType}, #{info.taskCreateDepart}, #{info.distributePoint},
|
||||
#{info.frequency},
|
||||
DEFAULT,
|
||||
#{info.fiveTupleWithMask.sourceIP}, #{info.fiveTupleWithMask.sourcePort},
|
||||
#{info.fiveTupleWithMask.destinationIP}, #{info.fiveTupleWithMask.destinationPort},
|
||||
|
||||
@@ -84,6 +84,20 @@
|
||||
set static_rule_audit_status = #{auditStatus}
|
||||
where static_rule_id = #{id}
|
||||
</update>
|
||||
<update id="updateAuditStatusByIdBatch">
|
||||
update t_static_rule
|
||||
set static_rule_audit_status = CASE static_rule_id
|
||||
<foreach collection="idWithAuditStatusBatch" index="id" item="auditStatus" separator=" ">
|
||||
WHEN #{id} THEN #{auditStatus}
|
||||
</foreach>
|
||||
ELSE static_rule_audit_status
|
||||
END
|
||||
WHERE static_rule_id IN
|
||||
<foreach collection="idWithAuditStatusBatch" index="id" open="(" separator="," close=")">
|
||||
#{id}
|
||||
</foreach>
|
||||
|
||||
</update>
|
||||
<delete id="deleteStaticRules">
|
||||
delete from t_static_rule
|
||||
where static_rule_id in
|
||||
|
||||
@@ -161,6 +161,8 @@
|
||||
<result column="static_rule_id" property="ruleId"/>
|
||||
|
||||
<result column="task_act" property="taskAct"/>
|
||||
<result column="task_create_depart" property="taskCreateDepart"/>
|
||||
<result column="static_rule_range" property="distributePoint"/>
|
||||
<result column="task_type" property="taskType"/>
|
||||
<result column="static_rule_frequency" property="frequency"/>
|
||||
<result column="task_start_time" property="startTime"/>
|
||||
@@ -204,6 +206,8 @@
|
||||
|
||||
t_task.task_type,
|
||||
t_task.task_act,
|
||||
t_task.task_create_depart,
|
||||
tsr.static_rule_range,
|
||||
tsr.static_rule_frequency,
|
||||
|
||||
t_task.task_start_time,
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.realtime.protection.configuration.entity.defense.template;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class TemplateTest {
|
||||
|
||||
@Test
|
||||
public void testSetHasProtectLevel() {
|
||||
Template template = new Template();
|
||||
ProtectLevel protectLevel = new ProtectLevel();
|
||||
protectLevel.setHasDNS(true);
|
||||
|
||||
template.setProtectLevelLow(new ProtectLevel());
|
||||
template.setProtectLevelMedium(new ProtectLevel());
|
||||
template.setProtectLevelHigh(new ProtectLevel());
|
||||
|
||||
assertDoesNotThrow(() -> {
|
||||
template.setProtectLevelHigh(protectLevel);
|
||||
template.setHasProtectLevel();
|
||||
assertTrue(template.getHasProtectLevelHigh());
|
||||
assertFalse(template.getHasProtectLevelMedium());
|
||||
assertFalse(template.getHasProtectLevelLow());
|
||||
});
|
||||
|
||||
assertDoesNotThrow(() -> {
|
||||
template.setProtectLevelMedium(protectLevel);
|
||||
template.setProtectLevelHigh(new ProtectLevel());
|
||||
template.setHasProtectLevel();
|
||||
assertFalse(template.getHasProtectLevelHigh());
|
||||
assertTrue(template.getHasProtectLevelMedium());
|
||||
assertFalse(template.getHasProtectLevelLow());
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.realtime.protection.configuration.utils.enums;
|
||||
|
||||
import com.realtime.protection.configuration.entity.rule.staticrule.StaticRuleObject;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class RuleEnumTest {
|
||||
StaticRuleObject staticRuleObject;
|
||||
|
||||
public RuleEnumTest() {
|
||||
staticRuleObject = new StaticRuleObject();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRuleEnum() {
|
||||
assertDoesNotThrow(() -> {
|
||||
this.staticRuleObject.setStaticRuleDip("255.255.255.255");
|
||||
assertTrue(RuleEnum.checkValidate(staticRuleObject));
|
||||
this.staticRuleObject.setStaticRuleMsip("255.255.255.255");
|
||||
assertFalse(RuleEnum.checkValidate(staticRuleObject));
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -57,6 +57,7 @@ public class AlertMessageTest {
|
||||
object.setDynamicRulePriority(1);
|
||||
object.setDynamicRuleRange("北京");
|
||||
object.setDynamicRuleProtectLevel(1);
|
||||
object.setLogRuleId(1L);
|
||||
object.setTemplateId(templates.get(0).getTemplateId());
|
||||
object.setProtectObjectIds(List.of(new Integer[]{protectObject.get(0).getProtectObjectId()}));
|
||||
Integer dynamicRuleId = dynamicRuleService.newDynamicRuleObject(object);
|
||||
@@ -81,7 +82,7 @@ public class AlertMessageTest {
|
||||
//启动任务
|
||||
stateChangeService.changeState(2, taskId, false);
|
||||
|
||||
for (int i = 0 ; i< 10; i++) {
|
||||
for (int i = 0 ; i< 5; i++) {
|
||||
AlertMessage alert = new AlertMessage();
|
||||
FiveTupleWithMask fiveTupleWithMask = new FiveTupleWithMask();
|
||||
fiveTupleWithMask.setSourceIP("111.1.1." + i);
|
||||
|
||||
@@ -49,7 +49,7 @@ public class DynamicRuleServiceTest extends ProtectionApplicationTests {
|
||||
object.setDynamicRuleRange("北京");
|
||||
object.setDynamicRuleProtectLevel(2);
|
||||
object.setTemplateId(templates.get(0).getTemplateId());
|
||||
object.setLogRuleId(1);
|
||||
object.setLogRuleId(1L);
|
||||
object.setProtectObjectIds(List.of(new Integer[]{protectObject.get(0).getProtectObjectId()}));
|
||||
Integer dynamicRuleId = dynamicRuleService.newDynamicRuleObject(object);
|
||||
}
|
||||
|
||||
@@ -8,7 +8,9 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
@@ -101,7 +103,15 @@ public class StaticRuleServiceTest extends ProtectionApplicationTests {
|
||||
List<StaticRuleObject> staticRuleObjects = staticRuleService.queryStaticRule(null, null, null, null, 1, 10);
|
||||
System.out.println(staticRuleObjects);
|
||||
}
|
||||
@Test
|
||||
void testUpdateStaticRuleAuditStatusBatch(){
|
||||
Map<Integer, Integer> map = new HashMap<>();
|
||||
map.put(1299, 0);
|
||||
map.put(1300, 1);
|
||||
map.put(1301, 1);
|
||||
|
||||
|
||||
System.out.println(staticRuleService.updateAuditStatusBatch(map));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user