Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
package com.realtime.protection.configuration.entity.rule.dynamicrule;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.realtime.protection.configuration.entity.task.FiveTupleWithMask;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class AlertMessage {
|
||||
|
||||
@JsonProperty("task_id")
|
||||
private Long taskId;
|
||||
@JsonProperty("five_tuple_with_mask")
|
||||
private FiveTupleWithMask fiveTupleWithMask;
|
||||
|
||||
}
|
||||
@@ -128,7 +128,9 @@ public class StaticRuleObject {
|
||||
|
||||
@JsonProperty("static_rule_priority")
|
||||
@ExcelProperty("优先级")
|
||||
@Schema(description = "优先级", example = "1", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@Max(value = 3)
|
||||
@Min(value = 1)
|
||||
@Schema(description = "优先级,1代表高2代表中3代表低", example = "1", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
private Integer staticRulePriority;
|
||||
@JsonProperty("static_rule_range")
|
||||
@ExcelProperty("范围")
|
||||
@@ -136,7 +138,8 @@ public class StaticRuleObject {
|
||||
private String staticRuleRange;
|
||||
@JsonProperty("static_rule_frequency")
|
||||
@ExcelProperty("频率")
|
||||
@Schema(description = "频率", example = "1", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@Min(value = 1)
|
||||
@Schema(description = "频率,最低为1", example = "1", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
private Integer staticRuleFrequency;
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.realtime.protection.server.alertmessage;
|
||||
|
||||
import com.realtime.protection.configuration.entity.rule.dynamicrule.AlertMessage;
|
||||
import com.realtime.protection.configuration.response.ResponseResult;
|
||||
import jakarta.validation.Valid;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("alertmessage")
|
||||
@Slf4j
|
||||
public class AlertMessageController
|
||||
{
|
||||
private final AlertMessageService alertMessageService;
|
||||
public AlertMessageController(final AlertMessageService alertMessageService) {
|
||||
this.alertMessageService = alertMessageService;
|
||||
}
|
||||
|
||||
@PostMapping("/new")
|
||||
public ResponseResult receiveAlertMessage(@RequestBody @Valid AlertMessage alertMessage){
|
||||
alertMessageService.receiveAlertMessage(alertMessage);
|
||||
return ResponseResult.ok();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.realtime.protection.server.alertmessage;
|
||||
|
||||
import com.realtime.protection.configuration.entity.rule.dynamicrule.AlertMessage;
|
||||
import com.realtime.protection.configuration.entity.task.Task;
|
||||
import com.realtime.protection.configuration.entity.task.TaskCommandInfo;
|
||||
import com.realtime.protection.server.task.TaskService;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.realtime.protection.server.command.CommandService;
|
||||
import com.realtime.protection.configuration.utils.enums.StateEnum;
|
||||
|
||||
@Service
|
||||
public class AlertMessageService {
|
||||
private final CommandService commandService;
|
||||
private final TaskService taskService;
|
||||
|
||||
public AlertMessageService(CommandService commandService,TaskService taskService) {
|
||||
this.commandService = commandService;
|
||||
this.taskService = taskService;
|
||||
}
|
||||
|
||||
public void receiveAlertMessage(AlertMessage alertMessage) {
|
||||
Long taskId = alertMessage.getTaskId();
|
||||
//查task信息
|
||||
Task task = taskService.queryTask(taskId);
|
||||
//检查task status是否为running?
|
||||
// if (task.getTaskStatus() != StateEnum.RUNNING.getStateNum()) {
|
||||
// return;
|
||||
// }
|
||||
|
||||
//task信息和alertMessage中的fiveTuple信息 合并成 TaskCommandInfo
|
||||
TaskCommandInfo dynamicTaskCommandInfo = new TaskCommandInfo();
|
||||
|
||||
|
||||
//command入库
|
||||
//commandService.createCommand(staticTaskCommandInfo);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -15,7 +15,7 @@
|
||||
dynamic_rule_priority, dynamic_rule_range,
|
||||
dynamic_rule_frequency, dynamic_rule_create_user_id)
|
||||
values (#{object.dynamicRuleName},
|
||||
#{object.dynamicRuleCreateTime}, #{object.dynamicRuleModifyTime},
|
||||
NOW(), #{object.dynamicRuleModifyTime},
|
||||
#{object.dynamicRuleCreateUsername}, #{object.dynamicRuleCreateDepart},
|
||||
#{object.templateId}, #{object.dynamicRuleProtectLevel},
|
||||
#{object.dynamicRulePriority}, #{object.dynamicRuleRange},
|
||||
@@ -40,7 +40,7 @@
|
||||
values
|
||||
<foreach collection="dynamicRuleObjects" item="object" separator=",">
|
||||
(#{object.dynamicRuleName},
|
||||
#{object.dynamicRuleCreateTime},#{object.dynamicRuleModifyTime},
|
||||
NOW(),#{object.dynamicRuleModifyTime},
|
||||
#{object.dynamicRuleCreateUsername},#{object.dynamicRuleCreateDepart},
|
||||
#{object.templateId}, #{object.dynamicRuleProtectLevel},
|
||||
#{object.dynamicRulePriority}, #{object.dynamicRuleRange},
|
||||
@@ -96,7 +96,8 @@
|
||||
</if>
|
||||
<if test="object.dynamicRulePriority != null">dynamic_rule_priority = #{object.dynamicRulePriority},</if>
|
||||
<if test="object.dynamicRuleRange != null">dynamic_rule_range = #{object.dynamicRuleRange},</if>
|
||||
<if test="object.dynamicRuleFrequency != null">dynamic_rule_frequency = #{object.dynamicRuleFrequency}</if>
|
||||
<if test="object.dynamicRuleFrequency != null">dynamic_rule_frequency = #{object.dynamicRuleFrequency},</if>
|
||||
modify_time = NOW()
|
||||
where
|
||||
dynamic_rule_id = #{dynamicRuleId}
|
||||
</update>
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
static_rule_frequency, static_rule_audit_status)
|
||||
values
|
||||
<foreach collection="staticRuleBatch" item="object" separator=",">
|
||||
(#{object.staticRuleName}, #{object.staticRuleCreateTime}, #{object.staticRuleCreateUsername},
|
||||
(#{object.staticRuleName}, NOW(), #{object.staticRuleCreateUsername},
|
||||
#{object.staticRuleCreateDepart}, #{object.staticRuleCreateUserId}, INET_ATON(#{object.staticRuleSip}),
|
||||
INET_ATON(#{object.staticRuleMsip}), #{object.staticRuleSport}, #{object.staticRuleMsport},
|
||||
INET_ATON(#{object.staticRuleDip}), INET_ATON(#{object.staticRuleMdip}), #{object.staticRuleDport},
|
||||
@@ -74,6 +74,7 @@
|
||||
<if test="object.staticRuleFrequency != null and object.staticRuleFrequency != ''">
|
||||
static_rule_frequency = #{object.staticRuleFrequency},
|
||||
</if>
|
||||
static_rule_modify_time = NOW()
|
||||
|
||||
</set>
|
||||
where static_rule_id = #{id}
|
||||
|
||||
@@ -8,24 +8,24 @@
|
||||
insert into t_white_list(white_list_name, white_list_system_name,
|
||||
white_list_ip, white_list_port,
|
||||
white_list_url, white_list_protocol,
|
||||
white_list_audit_status)
|
||||
white_list_audit_status, create_time)
|
||||
values (#{object.whiteListName}, #{object.whiteListSystemName},
|
||||
INET_ATON(#{object.whiteListIP}), #{object.whiteListPort},
|
||||
#{object.whiteListUrl}, #{object.whiteListProtocol},
|
||||
0)
|
||||
0, NOW())
|
||||
</insert>
|
||||
|
||||
<insert id="newWhiteListObjects">
|
||||
insert into t_white_list(white_list_name, white_list_system_name,
|
||||
white_list_ip, white_list_port,
|
||||
white_list_url, white_list_protocol,
|
||||
white_list_audit_status)
|
||||
white_list_audit_status, create_time)
|
||||
values
|
||||
<foreach collection="whiteListObjects" item="object" separator=",">
|
||||
(#{object.whiteListName}, #{object.whiteListSystemName},
|
||||
INET_ATON(#{object.whiteListIP}), #{object.whiteListPort},
|
||||
#{object.whiteListUrl}, #{object.whiteListProtocol},
|
||||
0)
|
||||
0, NOW())
|
||||
</foreach>
|
||||
</insert>
|
||||
|
||||
@@ -92,6 +92,7 @@
|
||||
<if test="object.whiteListAuditStatus != null">
|
||||
white_list_audit_status = #{object.whiteListAuditStatus},
|
||||
</if>
|
||||
modify_time = NOW()
|
||||
</set>
|
||||
where white_list_id = #{id}
|
||||
</update>
|
||||
|
||||
@@ -28,11 +28,11 @@ public class DynamicRuleServiceTest extends ProtectionApplicationTests {
|
||||
object.setDynamicRuleRange("北京");
|
||||
object.setDynamicRuleProtectLevel(2);
|
||||
object.setTemplateId(1);
|
||||
//object.setProtectObjectIds(List.of(new Integer[]{5521, 5520}));
|
||||
object.setProtectObjectIds(List.of(new Integer[]{5521, 5520}));
|
||||
|
||||
|
||||
Integer objectId = dynamicRuleService.newDynamicRuleObject(object);
|
||||
assertTrue(objectId > 0);
|
||||
// Integer objectId = dynamicRuleService.newDynamicRuleObject(object);
|
||||
// assertTrue(objectId > 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -42,8 +42,8 @@ public class DynamicRuleServiceTest extends ProtectionApplicationTests {
|
||||
|
||||
@Test
|
||||
void testQueryDynamicRule() {
|
||||
DynamicRuleObject object = dynamicRuleService.queryDynamicRuleById(9);
|
||||
System.out.println(object);
|
||||
// DynamicRuleObject object = dynamicRuleService.queryDynamicRuleById(9);
|
||||
// System.out.println(object);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -55,9 +55,9 @@ public class DynamicRuleServiceTest extends ProtectionApplicationTests {
|
||||
object.setDynamicRuleRange("北京");
|
||||
object.setDynamicRuleProtectLevel(2);
|
||||
object.setTemplateId(1);
|
||||
object.setProtectObjectIds(List.of(new Integer[]{5521, 5520}));
|
||||
object.setProtectObjectIds(List.of(new Integer[]{6061}));
|
||||
|
||||
dynamicRuleService.updateDynamicRuleObject(2, object);
|
||||
dynamicRuleService.updateDynamicRuleObject(5, object);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -44,7 +44,7 @@ public class StaticRuleServiceTest extends ProtectionApplicationTests {
|
||||
@Test
|
||||
void testNewStaticRule(){
|
||||
Integer i = 0;
|
||||
while(i<20) {
|
||||
while(i<2) {
|
||||
i++;
|
||||
StaticRuleObject object = new StaticRuleObject();
|
||||
|
||||
@@ -67,7 +67,7 @@ public class StaticRuleServiceTest extends ProtectionApplicationTests {
|
||||
@Test
|
||||
void testNewStaticRules(){
|
||||
List<StaticRuleObject> staticRuleObjects = new ArrayList<>();
|
||||
for (int i = 0; i < 100; i++) {
|
||||
for (int i = 0; i < 2; i++) {
|
||||
staticRuleObjects.add(staticRuleTest);
|
||||
}
|
||||
Boolean success = staticRuleService.newStaticRuleObjects(staticRuleObjects);
|
||||
|
||||
@@ -48,7 +48,7 @@ class WhiteListServiceTest extends ProtectionApplicationTests {
|
||||
@Test
|
||||
void newProtectObjects() {
|
||||
List<WhiteListObject> whiteListObjects = new ArrayList<>();
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
for (int i = 0; i < 2; i++) {
|
||||
whiteListObjects.add(whiteListObject);
|
||||
}
|
||||
Boolean success = whiteListService.newWhiteListObjects(whiteListObjects);
|
||||
@@ -73,7 +73,7 @@ class WhiteListServiceTest extends ProtectionApplicationTests {
|
||||
|
||||
@Test
|
||||
void testUpdateWhiteListAuditStatus() {
|
||||
whiteListService.updateWhiteListObjectAuditStatus(7, 1);
|
||||
//whiteListService.updateWhiteListObjectAuditStatus(7, 1);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user