1. 修改部分逻辑
This commit is contained in:
@@ -11,7 +11,7 @@ import lombok.Data;
|
|||||||
public class FiveTupleWithMask {
|
public class FiveTupleWithMask {
|
||||||
@Schema(description = "地址类型(IPv4 or IPv6)", example = "4")
|
@Schema(description = "地址类型(IPv4 or IPv6)", example = "4")
|
||||||
@JsonProperty("addr_type")
|
@JsonProperty("addr_type")
|
||||||
private Integer addrType;
|
private Integer addrType = 4;
|
||||||
|
|
||||||
@Schema(description = "源IP", example = "192.168.104.14")
|
@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地址")
|
@Pattern(regexp = "^(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})$", message = "源IP:无效IPv4地址")
|
||||||
|
|||||||
@@ -67,6 +67,10 @@ public class TaskCommandInfo {
|
|||||||
@JsonProperty("is_valid")
|
@JsonProperty("is_valid")
|
||||||
private Boolean isValid = true;
|
private Boolean isValid = true;
|
||||||
|
|
||||||
|
@Schema(description = "指令是否已研判", example = "true")
|
||||||
|
@JsonProperty("is_judged")
|
||||||
|
private Boolean isJudged = true;
|
||||||
|
|
||||||
@Schema(description = "五元组信息")
|
@Schema(description = "五元组信息")
|
||||||
@NotNull(message = "五元组信息不能为空。")
|
@NotNull(message = "五元组信息不能为空。")
|
||||||
@JsonProperty("five_tuple_with_mask")
|
@JsonProperty("five_tuple_with_mask")
|
||||||
|
|||||||
@@ -36,7 +36,6 @@ public class CommandService {
|
|||||||
commandInfo.setUUID(UUID.randomUUID().toString());
|
commandInfo.setUUID(UUID.randomUUID().toString());
|
||||||
commandMapper.createCommand(commandInfo);
|
commandMapper.createCommand(commandInfo);
|
||||||
return commandInfo.getUUID();
|
return commandInfo.getUUID();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void createCommands(List<TaskCommandInfo> taskCommandInfos) {
|
public void createCommands(List<TaskCommandInfo> taskCommandInfos) {
|
||||||
|
|||||||
@@ -48,7 +48,6 @@ public class StateHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected Boolean handleResume(CommandService commandService, Long taskId) {
|
protected Boolean handleResume(CommandService commandService, Long taskId) {
|
||||||
|
|
||||||
commandService.startCommandsByTaskId(taskId);
|
commandService.startCommandsByTaskId(taskId);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,8 @@
|
|||||||
#{info.fiveTupleWithMask.maskSourceIP}, #{info.fiveTupleWithMask.maskSourcePort},
|
#{info.fiveTupleWithMask.maskSourceIP}, #{info.fiveTupleWithMask.maskSourcePort},
|
||||||
#{info.fiveTupleWithMask.maskDestinationIP}, #{info.fiveTupleWithMask.maskDestinationPort},
|
#{info.fiveTupleWithMask.maskDestinationIP}, #{info.fiveTupleWithMask.maskDestinationPort},
|
||||||
#{info.fiveTupleWithMask.maskProtocol},
|
#{info.fiveTupleWithMask.maskProtocol},
|
||||||
#{info.startTime}, #{info.endTime}, #{info.isValid}, #{info.isJudged},
|
#{info.startTime}, #{info.endTime}, #{info.isValid},
|
||||||
|
#{info.isJudged},
|
||||||
0, 0,
|
0, 0,
|
||||||
NOW(), NOW(), FALSE)
|
NOW(), NOW(), FALSE)
|
||||||
</insert>
|
</insert>
|
||||||
@@ -25,7 +26,8 @@
|
|||||||
<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(COMMAND_ID, TASK_ID, TASK_ACT, FREQUENCY, ADDR_TYPE, SRC_IP, SRC_PORT, DST_IP, DST_PORT,
|
insert into t_command(COMMAND_ID, TASK_ID, TASK_ACT, FREQUENCY, ADDR_TYPE, SRC_IP, SRC_PORT, DST_IP, DST_PORT,
|
||||||
PROTOCOL,
|
PROTOCOL,
|
||||||
MASK_SRC_IP, MASK_SRC_PORT, MASK_DST_IP, MASK_DST_PORT, MASK_PROTOCOL, VALID_TIME, INVALID_TIME, IS_VALID, IS_JUDGED,
|
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)
|
SEND_TIMES, SUCCESS_TIMES, CREATE_TIME, LAST_UPDATE, IS_DELETED)
|
||||||
values
|
values
|
||||||
<foreach collection="command_infos" item="info" separator=",">
|
<foreach collection="command_infos" item="info" separator=",">
|
||||||
@@ -37,7 +39,8 @@
|
|||||||
#{info.fiveTupleWithMask.maskSourceIP}, #{info.fiveTupleWithMask.maskSourcePort},
|
#{info.fiveTupleWithMask.maskSourceIP}, #{info.fiveTupleWithMask.maskSourcePort},
|
||||||
#{info.fiveTupleWithMask.maskDestinationIP}, #{info.fiveTupleWithMask.maskDestinationPort},
|
#{info.fiveTupleWithMask.maskDestinationIP}, #{info.fiveTupleWithMask.maskDestinationPort},
|
||||||
#{info.fiveTupleWithMask.maskProtocol},
|
#{info.fiveTupleWithMask.maskProtocol},
|
||||||
#{info.startTime}, #{info.endTime}, #{info.isValid}, DEFAULT,
|
#{info.startTime}, #{info.endTime}, #{info.isValid},
|
||||||
|
#{info.isJudged},
|
||||||
0, 0,
|
0, 0,
|
||||||
NOW(), NOW(), FALSE
|
NOW(), NOW(), FALSE
|
||||||
)
|
)
|
||||||
@@ -128,7 +131,7 @@
|
|||||||
|
|
||||||
<update id="setCommandJudged">
|
<update id="setCommandJudged">
|
||||||
UPDATE t_command
|
UPDATE t_command
|
||||||
SET IS_JUDGED = #{is_judged},
|
SET IS_JUDGED = #{is_judged},
|
||||||
LAST_UPDATE = NOW()
|
LAST_UPDATE = NOW()
|
||||||
WHERE COMMAND_ID = #{command_id}
|
WHERE COMMAND_ID = #{command_id}
|
||||||
AND IS_DELETED = FALSE
|
AND IS_DELETED = FALSE
|
||||||
@@ -137,7 +140,12 @@
|
|||||||
<select id="queryCommandInfo" resultType="java.lang.String">
|
<select id="queryCommandInfo" resultType="java.lang.String">
|
||||||
SELECT COMMAND_ID FROM t_command
|
SELECT COMMAND_ID FROM t_command
|
||||||
<where>
|
<where>
|
||||||
<if test="command_info.taskId != null">AND TASK_ID = #{command_info.taskId}</if>
|
<if test="command_info.taskId != null">
|
||||||
|
AND TASK_ID = #{command_info.taskId}
|
||||||
|
</if>
|
||||||
|
<if test="#{command_info.fiveTupleWithMask.addrType} != null">
|
||||||
|
AND ADDR_TYPE = #{command_info.fiveTupleWithMask.addrType}
|
||||||
|
</if>
|
||||||
<if test="command_info.fiveTupleWithMask.sourceIP != null">
|
<if test="command_info.fiveTupleWithMask.sourceIP != null">
|
||||||
AND SRC_IP = #{command_info.fiveTupleWithMask.sourceIP}
|
AND SRC_IP = #{command_info.fiveTupleWithMask.sourceIP}
|
||||||
</if>
|
</if>
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import org.springframework.boot.test.context.SpringBootTest;
|
|||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
@@ -54,8 +55,7 @@ class CommandServiceTest extends ProtectionApplicationTests {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void createCommand() {
|
void createCommand() {
|
||||||
assertDoesNotThrow(() -> commandService.createCommand(taskCommandInfo));
|
assertDoesNotThrow(() -> assertNotNull(commandService.createCommand(taskCommandInfo)));
|
||||||
assertNotNull(taskCommandInfo.getUUID());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -85,7 +85,7 @@ class CommandServiceTest extends ProtectionApplicationTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void queryCommandByUUID() {
|
void queryCommandInfos() {
|
||||||
List<TaskCommandInfo> taskCommandInfos = commandService.queryCommandInfos(30L,
|
List<TaskCommandInfo> taskCommandInfos = commandService.queryCommandInfos(30L,
|
||||||
null, null, null, null,1, 5);
|
null, null, null, null,1, 5);
|
||||||
assertTrue(taskCommandInfos != null && !taskCommandInfos.isEmpty());
|
assertTrue(taskCommandInfos != null && !taskCommandInfos.isEmpty());
|
||||||
@@ -94,4 +94,14 @@ class CommandServiceTest extends ProtectionApplicationTests {
|
|||||||
assertNotNull(commandService.queryCommandInfoByUUID(taskCommandInfo.getUUID()));
|
assertNotNull(commandService.queryCommandInfoByUUID(taskCommandInfo.getUUID()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void queryCommandByUUID() {
|
||||||
|
taskCommandInfo.setTaskId(new Random().nextLong());
|
||||||
|
String uuid = commandService.createCommand(taskCommandInfo);
|
||||||
|
TaskCommandInfo taskCommandInfo = commandService.queryCommandInfoByUUID(uuid);
|
||||||
|
assertNotNull(taskCommandInfo);
|
||||||
|
assertNotNull(taskCommandInfo.getUUID());
|
||||||
|
assertEquals(uuid, taskCommandInfo.getUUID());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user