diff --git a/src/main/java/com/realtime/protection/configuration/entity/defense/template/TemplateNew.java b/src/main/java/com/realtime/protection/configuration/entity/defense/template/TemplateNew.java index 2563e67..8290f91 100644 --- a/src/main/java/com/realtime/protection/configuration/entity/defense/template/TemplateNew.java +++ b/src/main/java/com/realtime/protection/configuration/entity/defense/template/TemplateNew.java @@ -2,6 +2,8 @@ package com.realtime.protection.configuration.entity.defense.template; import com.fasterxml.jackson.annotation.JsonProperty; import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.constraints.Max; +import jakarta.validation.constraints.Min; import jakarta.validation.constraints.NotNull; import lombok.Data; @@ -13,7 +15,7 @@ public class TemplateNew { @JsonProperty("template_name") @NotNull(message = "template_name字段不能为空。") - @Schema(description = "防御策略模板名称(事件类型)", example = "APT攻击事件") + @Schema(description = "防御策略模板名称", example = "APT攻击事件日常态") private String templateName; @JsonProperty("source_system") @@ -23,12 +25,14 @@ public class TemplateNew { @JsonProperty("event_type") @NotNull(message = "事件类型字段不能为空。") - @Schema(description = "防御策略模板数据来源系统", example = "BW系统") + @Schema(description = "防御策略模板事件类型", example = "APT攻击事件") private String eventType; @JsonProperty("protect_level") @NotNull(message = "防护等级字段不能为空。") - @Schema(description = "防御策略模板数据来源系统", example = "BW系统") + @Max(value = 3) + @Min(value = 1) + @Schema(description = "防护等级:1代表日常态、2代表应急态、3代表紧急态", example = "1") private String protectLevel; @JsonProperty("description") @@ -91,20 +95,20 @@ public class TemplateNew { private String templateDisplayId; @JsonProperty("audit_user_name") - @Schema(description = "审核用户名称", example = "user11") + @Schema(description = "审核用户名称", example = "user11", accessMode = Schema.AccessMode.READ_ONLY) private String auditUserName; @JsonProperty("audit_user_id") - @Schema(description = "审核用户id", example = "11111") + @Schema(description = "审核用户id", example = "11111", accessMode = Schema.AccessMode.READ_ONLY) private String auditUserId; @JsonProperty("audit_user_depart") - @Schema(description = "审核用户部门", example = "部门1") + @Schema(description = "审核用户部门", example = "部门1", accessMode = Schema.AccessMode.READ_ONLY) private String auditUserDepart; @JsonProperty("create_time") - @Schema(description = "新建时间") + @Schema(description = "新建时间", example = "部门1", accessMode = Schema.AccessMode.READ_ONLY) private String createTime; @JsonProperty("update_time") - @Schema(description = "更新时间") + @Schema(description = "更新时间", example = "部门1", accessMode = Schema.AccessMode.READ_ONLY) private String updateTime; } diff --git a/src/main/java/com/realtime/protection/server/defense/template/TemplateController.java b/src/main/java/com/realtime/protection/server/defense/template/TemplateController.java index feb7dd8..bae8d39 100644 --- a/src/main/java/com/realtime/protection/server/defense/template/TemplateController.java +++ b/src/main/java/com/realtime/protection/server/defense/template/TemplateController.java @@ -11,8 +11,8 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; -@RestController -@RequestMapping("/template") +@RestController("TemplateControllerOld") +@RequestMapping("/templateold") public class TemplateController implements TemplateControllerApi { private final TemplateService templateService; diff --git a/src/main/java/com/realtime/protection/server/defense/template/TemplateControllerApi.java b/src/main/java/com/realtime/protection/server/defense/template/TemplateControllerApi.java index 0f8dcad..3a2c995 100644 --- a/src/main/java/com/realtime/protection/server/defense/template/TemplateControllerApi.java +++ b/src/main/java/com/realtime/protection/server/defense/template/TemplateControllerApi.java @@ -16,7 +16,7 @@ import org.springframework.web.bind.annotation.*; import java.util.List; import java.util.Map; -@Tag(name = "防御策略模板API", description = "防御策略模板模块所有接口") +@Tag(name = "old防御策略模板API", description = "防御策略模板模块所有接口") public interface TemplateControllerApi { @PostMapping("/new") @Operation( diff --git a/src/main/java/com/realtime/protection/server/defense/template/TemplateMapper.java b/src/main/java/com/realtime/protection/server/defense/template/TemplateMapperOld.java similarity index 98% rename from src/main/java/com/realtime/protection/server/defense/template/TemplateMapper.java rename to src/main/java/com/realtime/protection/server/defense/template/TemplateMapperOld.java index 6753cb4..870e33d 100644 --- a/src/main/java/com/realtime/protection/server/defense/template/TemplateMapper.java +++ b/src/main/java/com/realtime/protection/server/defense/template/TemplateMapperOld.java @@ -9,8 +9,8 @@ import org.apache.ibatis.annotations.Param; import java.util.List; import java.util.Map; -@Mapper -public interface TemplateMapper { +@Mapper() +public interface TemplateMapperOld { void newTemplate(@Param("template") Template template); void newProtectLevel(@Param("level") ProtectLevel protectLevel); diff --git a/src/main/java/com/realtime/protection/server/defense/template/TemplateService.java b/src/main/java/com/realtime/protection/server/defense/template/TemplateService.java index 85f69d2..a63b153 100644 --- a/src/main/java/com/realtime/protection/server/defense/template/TemplateService.java +++ b/src/main/java/com/realtime/protection/server/defense/template/TemplateService.java @@ -5,7 +5,6 @@ import com.realtime.protection.configuration.utils.Counter; import com.realtime.protection.configuration.utils.SqlSessionWrapper; import com.realtime.protection.configuration.utils.enums.audit.AuditStatusValidator; -import com.realtime.protection.server.whitelist.WhiteListMapper; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -17,14 +16,14 @@ import java.util.List; import java.util.Map; import java.util.function.Function; -@Service +@Service("TemplateServiceOld") public class TemplateService { - private final TemplateMapper templateMapper; + private final TemplateMapperOld templateMapper; private final Counter counter; private final SqlSessionWrapper sqlSessionWrapper; - public TemplateService(TemplateMapper templateMapper, Counter counter, SqlSessionWrapper sqlSessionWrapper) { + public TemplateService(TemplateMapperOld templateMapper, Counter counter, SqlSessionWrapper sqlSessionWrapper) { this.templateMapper = templateMapper; this.counter = counter; this.sqlSessionWrapper = sqlSessionWrapper; @@ -147,7 +146,7 @@ public class TemplateService { throw new IllegalArgumentException("策略模板无法修改为对应审核状态, 错误id: " + errorIds); } - Function, Boolean>> updateTemplateAuditStatusFunction = + Function, Boolean>> updateTemplateAuditStatusFunction = mapper -> map -> { if (map == null || map.isEmpty()) { return false; @@ -169,7 +168,7 @@ public class TemplateService { return true; }; //实现事务操作 - return sqlSessionWrapper.startBatchSession(TemplateMapper.class, updateTemplateAuditStatusFunction, idsWithAuditStatusMap); + return sqlSessionWrapper.startBatchSession(TemplateMapperOld.class, updateTemplateAuditStatusFunction, idsWithAuditStatusMap); } diff --git a/src/main/java/com/realtime/protection/server/defense/templatenew/TemplateController.java b/src/main/java/com/realtime/protection/server/defense/templatenew/TemplateController.java index f1fc607..93096c6 100644 --- a/src/main/java/com/realtime/protection/server/defense/templatenew/TemplateController.java +++ b/src/main/java/com/realtime/protection/server/defense/templatenew/TemplateController.java @@ -12,7 +12,7 @@ import java.util.List; import java.util.Map; @RestController -@RequestMapping("/templatenew/") +@RequestMapping("/template/") public class TemplateController implements TemplateNewCpntrollerApi{ private final TemplateService templateService; @@ -21,7 +21,7 @@ public class TemplateController implements TemplateNewCpntrollerApi{ } - // @Override + @Override @PostMapping("/new") public ResponseResult newTemplate(@RequestBody @Valid TemplateNew template) { @@ -110,12 +110,14 @@ public class TemplateController implements TemplateNewCpntrollerApi{ .setData("source_system", templateService.querySourceSystem()); } - @Override - @GetMapping("/query/event_name/{sourceSystem}") - public ResponseResult queryEventName(@PathVariable String sourceSystem) { - return ResponseResult.ok() - .setData("event_name", templateService.queryEventName(sourceSystem)); - } + + +// @Override +// @GetMapping("/query/event_name/{sourceSystem}") +// public ResponseResult queryEventName(@PathVariable String sourceSystem) { +// return ResponseResult.ok() +// .setData("event_name", templateService.queryEventName(sourceSystem)); +// } // @Override // @PostMapping("/query/templateId") diff --git a/src/main/java/com/realtime/protection/server/defense/templatenew/TemplateMapper.java b/src/main/java/com/realtime/protection/server/defense/templatenew/TemplateMapper.java index 8a2556c..76fb5a5 100644 --- a/src/main/java/com/realtime/protection/server/defense/templatenew/TemplateMapper.java +++ b/src/main/java/com/realtime/protection/server/defense/templatenew/TemplateMapper.java @@ -1,7 +1,5 @@ package com.realtime.protection.server.defense.templatenew; -import com.realtime.protection.configuration.entity.defense.template.ProtectLevel; -import com.realtime.protection.configuration.entity.defense.template.Template; import com.realtime.protection.configuration.entity.defense.template.TemplateNew; import org.apache.ibatis.annotations.Delete; import org.apache.ibatis.annotations.Mapper; @@ -12,7 +10,7 @@ import java.util.Map; @Mapper public interface TemplateMapper { - void newTemplate(TemplateNew template); + void newTemplate(@Param("template")TemplateNew template); List queryTemplates(@Param("template_name") String templateName, @Param("source_system") String sourceSystem, @@ -29,7 +27,7 @@ public interface TemplateMapper { TemplateNew queryTemplate(@Param("template_id") Integer templateId); - @Delete("DELETE FROM t_strategy_template WHERE strategy_template_id = #{template_id}") + @Delete("DELETE FROM t_strategy_template_new WHERE strategy_template_id = #{template_id}") Boolean deleteTemplate(@Param("template_id") Integer templateId); Integer queryTemplateTotalNum(@Param("template_name") String templateName, @@ -43,7 +41,7 @@ public interface TemplateMapper { List querySourceSystem(); - List queryEventName(String sourceSystem); +// List queryEventName(String sourceSystem); // Integer queryTemplateId(String sourceSystem, String eventName); @@ -59,7 +57,7 @@ public interface TemplateMapper { void updateAuditStatusByIdBatch(@Param("idWithAuditStatusBatch") Map idWithAuditStatusBatch); - Boolean updateAuditInfo(List ids, String auditInfo); + Boolean updateAuditInfo(@Param("ids")List ids,@Param("auditInfo") String auditInfo); String queryAuditInfo(Integer id); diff --git a/src/main/java/com/realtime/protection/server/defense/templatenew/TemplateNewCpntrollerApi.java b/src/main/java/com/realtime/protection/server/defense/templatenew/TemplateNewCpntrollerApi.java index c19deb7..e5d0d56 100644 --- a/src/main/java/com/realtime/protection/server/defense/templatenew/TemplateNewCpntrollerApi.java +++ b/src/main/java/com/realtime/protection/server/defense/templatenew/TemplateNewCpntrollerApi.java @@ -2,18 +2,92 @@ package com.realtime.protection.server.defense.templatenew; import com.realtime.protection.configuration.entity.defense.template.Template; import com.realtime.protection.configuration.entity.defense.template.TemplateNew; +import com.realtime.protection.configuration.entity.whitelist.WhiteListObject; import com.realtime.protection.configuration.response.ResponseResult; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.ExampleObject; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.validation.Valid; import jakarta.validation.constraints.Min; import org.springframework.web.bind.annotation.*; import java.util.List; import java.util.Map; - +@Tag(name = "策略模板API", description = "策略模板模块所有接口") public interface TemplateNewCpntrollerApi { + @PostMapping("/new") + @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": { + "success": true, + "template_id": 1442 + } + } + """, + description = """ + "success": 新建防御策略模板是否成功 + "template_id": 新建防御策略模板ID + """ + ) + ) + ) + }, + requestBody = @io.swagger.v3.oas.annotations.parameters.RequestBody( + content = @Content( + mediaType = "application/json", + schema = @Schema(implementation = TemplateNew.class) + ), + description = "防御策略模板信息") + + ) + ResponseResult newTemplate(@RequestBody @Valid TemplateNew template); + @GetMapping("/query") + @Operation( + summary = "分頁查询策略模板", + description = "分頁查询策略模板", + responses = { + @ApiResponse( + description = "返回策略模板防护等级信息", + content = @Content( + mediaType = "application/json", + schema = @Schema(title = "ResponseResult和Template的属性", + anyOf = {ResponseResult.class, TemplateNew.class}) + + ) + ) + }, + parameters = { + @Parameter(name = "template_name", description = "防御策略模板名称", example = "DDOS"), + @Parameter(name = "source_system", description = "策略模板来源那系统", example = "xxx系统"), + @Parameter(name = "create_user_name", description = "创建人名称", example = "xxx"), + @Parameter(name = "template_id", description = "防御策略模板ID", example = "1"), + @Parameter(name = "audit_status", description = "审核状态", example = "0"), + @Parameter(name = "event_type", description = "事件类型", example = "ddos"), + @Parameter(name = "protect_level", description = "防护等级", example = "1"), + @Parameter(name = "page", description = "页码", example = "1"), + @Parameter(name = "page_size", description = "每页对象数量", example = "5") + } + ) ResponseResult queryTemplates(@RequestParam(value = "template_name", required = false) String templateName, @RequestParam(value = "source_system", required = false) String sourceSystem, @RequestParam(value = "create_user_name", required = false) String createUserName, @@ -26,42 +100,259 @@ public interface TemplateNewCpntrollerApi { @RequestParam("page_size") @Min(1) Integer pageSize); @GetMapping("/{templateId}/query") + @Operation( + summary = "查询单个防御策略模板", + description = "根据模板ID查询单个防御策略模板信息", + responses = { + @ApiResponse( + description = "返回单个防御策略模板信息", + content = @Content( + mediaType = "application/json", + schema = @Schema(implementation = ResponseResult.class) + ) + ) + }, + parameters = { + @Parameter(name = "templateId", description = "防御策略模板ID", example = "5") + } + ) ResponseResult queryTemplate(@PathVariable Integer templateId); - @PostMapping("/{templateId}/update") + @Operation( + summary = "更新防御策略模板信息", + description = "根据提供的防御策略模板信息更新指定ID对应的防御策略模板", + responses = { + @ApiResponse( + description = "返回防御策略模板信息更新结果", + content = @Content( + mediaType = "application/json", + schema = @Schema(implementation = ResponseResult.class), + examples = @ExampleObject( + name = "example", + value = """ + { + "code": 200, + "message": "request succeed", + "data": { + "success": true, + "template_id": 262 + } + } + """, + description = """ + "success": 更新是否成功 + + "template_id": 更新的策略模板ID + """ + ) + ) + ) + }, + parameters = { + @Parameter(name = "templateId", description = "防御策略模板ID", example = "5") + }, + requestBody = @io.swagger.v3.oas.annotations.parameters.RequestBody( + content = @Content( + mediaType = "application/json", + schema = @Schema(implementation = TemplateNew.class) + ), + description = "防御策略模板信息") + ) ResponseResult updateTemplate(@PathVariable @Min(1) Integer templateId, @RequestBody @Valid TemplateNew template); @DeleteMapping("/{templateId}/delete") + @Operation( + summary = "删除防御策略模板信息", + description = "根据策略模板ID删除指定的防御策略模板信息", + responses = { + @ApiResponse( + description = "返回防御策略模板删除结果", + content = @Content( + mediaType = "application/json", + schema = @Schema(implementation = ResponseResult.class), + examples = @ExampleObject( + name = "example", + value = """ + { + "code": 200, + "message": "request succeed", + "data": { + "success": true, + "template_id": 262 + } + } + """, + description = """ + "success": 删除是否成功 + + "template_id": 删除的策略模板ID + """ + ) + ) + ) + }, + parameters = { + @Parameter(name = "templateId", description = "防御策略模板ID", example = "5") + } + ) ResponseResult deleteTemplate(@PathVariable @Min(1) Integer templateId); - + @Operation( + summary = "查询来源系统名称", + description = "查询策略模板中的所有来源系统名称", + responses = { + @ApiResponse( + description = "返回来源系统名称查询结果,返回字符串列表", + content = @Content( + mediaType = "application/json", + schema = @Schema(implementation = ResponseResult.class) + ) + ) + } + ) @GetMapping("/query/source_system") ResponseResult querySourceSystem(); - @GetMapping("/query/event_name/{sourceSystem}") - ResponseResult queryEventName(@PathVariable String sourceSystem); +// @GetMapping("/query/event_name/{sourceSystem}") +// ResponseResult queryEventName(@PathVariable String sourceSystem); /* 策略模板数据统计 */ + @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": { + "template_num": 1, + "template_used_num": 1, + "template_audit_num": 0, + "template_unaudit_num": 1 + } + } + """ + ) + ) + ) + }, + parameters = { + + } + ) @GetMapping("/statistics") ResponseResult statisticsTemplate(); + @Operation( + summary = "按id修改审计状态", + description = "按id修改审计状态", + responses = { + @ApiResponse( + description = "返回数据统计", + content = @Content( + mediaType = "application/json", + schema = @Schema(implementation = ResponseResult.class) + + ) + ) + }, + parameters = { + @Parameter(name = "id", description = "防御策略模板ID", example = "5"), + @Parameter(name = "auditStatus", description = "修改为的审批状态", example = "2") + } + ) @GetMapping("/{id}/audit/{auditStatus}") ResponseResult updateTemplateAuditStatus(@PathVariable Integer id, @PathVariable Integer auditStatus); + @Operation( + summary = "批量更新审批状态", + description = "批量更新审批状态,0未审核、1审核不通过、2审核通过", + responses = { + @io.swagger.v3.oas.annotations.responses.ApiResponse( + description = "返回审核结果", + content = @Content( + mediaType = "application/json", + schema = @Schema(implementation = ResponseResult.class) + ) + ) + }, + requestBody = @io.swagger.v3.oas.annotations.parameters.RequestBody( + description = "字典,key是id,value是审核状态", + content = @Content( + mediaType = "application/json", + schema = @Schema(implementation = Map.class) + ) + ) + ) @PostMapping("/auditbatch") ResponseResult updateWhiteListAuditStatusBatch(@RequestBody Map idsWithAuditStatusMap); /* 修改审批信息 */ + @Operation( + summary = "更新审批意见", + description = "批量更新审批意见,接收多个id", + responses = { + @io.swagger.v3.oas.annotations.responses.ApiResponse( + description = "返回是否成功", + content = @Content( + mediaType = "application/json", + schema = @Schema(implementation = ResponseResult.class) + ) + ) + }, + requestBody = @io.swagger.v3.oas.annotations.parameters.RequestBody( + description = "字典,key是'audit_info',value是审核意见", + content = @Content( + mediaType = "application/json", + schema = @Schema(implementation = Map.class), + examples = @ExampleObject( + name = "example", + value = """ + { + "auditInfo": "审核不通过,原因是xxxx" + } + """ + ) + + ) + ), + parameters = { + @Parameter(name = "ids", description = "欲更新的ID", example = "2,3"), + } + ) @PostMapping("/auditInfo/{ids}") ResponseResult updateAuditInfo(@PathVariable List ids, @RequestBody Map auditInfo); - + @Operation( + summary = "查询审批意见", + description = "查询审批意见,只接收一个id", + responses = { + @io.swagger.v3.oas.annotations.responses.ApiResponse( + description = "返回是否成功", + content = @Content( + mediaType = "application/json", + schema = @Schema(implementation = ResponseResult.class) + ) + ) + }, + parameters = { + @Parameter(name = "id", description = "查询的ID", example = "2"), + } + ) @GetMapping("/auditInfo/{id}") ResponseResult queryAuditInfo(@PathVariable Integer id); } diff --git a/src/main/java/com/realtime/protection/server/defense/templatenew/TemplateService.java b/src/main/java/com/realtime/protection/server/defense/templatenew/TemplateService.java index be202ff..1a303b7 100644 --- a/src/main/java/com/realtime/protection/server/defense/templatenew/TemplateService.java +++ b/src/main/java/com/realtime/protection/server/defense/templatenew/TemplateService.java @@ -1,6 +1,5 @@ package com.realtime.protection.server.defense.templatenew; -import com.realtime.protection.configuration.entity.defense.template.Template; import com.realtime.protection.configuration.entity.defense.template.TemplateNew; import com.realtime.protection.configuration.utils.Counter; import com.realtime.protection.configuration.utils.SqlSessionWrapper; @@ -81,9 +80,9 @@ public class TemplateService { return templateMapper.querySourceSystem(); } - public List queryEventName(String sourceSystem) { - return templateMapper.queryEventName(sourceSystem); - } +// public List queryEventName(String sourceSystem) { +// return templateMapper.queryEventName(sourceSystem); +// } @@ -132,7 +131,7 @@ public class TemplateService { throw new IllegalArgumentException("策略模板无法修改为对应审核状态, 错误id: " + errorIds); } - Function, Boolean>> updateTemplateAuditStatusFunction = + Function, Boolean>> updateTemplateAuditStatusFunction = mapper -> map -> { if (map == null || map.isEmpty()) { return false; @@ -154,7 +153,7 @@ public class TemplateService { return true; }; //实现事务操作 - return sqlSessionWrapper.startBatchSession(com.realtime.protection.server.defense.template.TemplateMapper.class, updateTemplateAuditStatusFunction, idsWithAuditStatusMap); + return sqlSessionWrapper.startBatchSession(TemplateMapper.class, updateTemplateAuditStatusFunction, idsWithAuditStatusMap); } diff --git a/src/main/resources/mappers/TemplateNewMapper.xml b/src/main/resources/mappers/TemplateNewMapper.xml index 1c82fe4..844c523 100644 --- a/src/main/resources/mappers/TemplateNewMapper.xml +++ b/src/main/resources/mappers/TemplateNewMapper.xml @@ -10,30 +10,35 @@ has_peer_ip, has_peer_port, is_full_flow, is_protect_object_src, strategy_template_create_user_id, strategy_template_create_username, strategy_template_create_depart, - strategy_template_description, strategy_template_display_id) + strategy_template_description, strategy_template_display_id, + event_type, protect_level) VALUE (#{template.templateName}, #{template.sourceSystem}, - #{template.hasProtectObjectIp}, #{template.hasProtectObjectPort}, - #{template.hasProtocol}, #{template.hasUrl}, #{template.hasDns}, - #{template.hasPeerIp}, #{template.hasPeerPort}, #{template.isFullFlow}, - #{template.isProtectObjectSrc}, + #{template.hasProtectObjectIP}, #{template.hasProtectObjectPort}, + #{template.hasProtocol}, #{template.hasURL}, #{template.hasDNS}, + #{template.hasPeerIP}, #{template.hasPeerPort}, #{template.isFullFlow}, + #{template.isProtectObjectIPSrc}, #{template.createUserId}, #{template.createUsername}, #{template.createDepart}, - #{template.description}, #{template.templateDisplayId}) + #{template.description}, #{template.templateDisplayId}, + #{template.eventType}, #{template.protectLevel}) UPDATE t_strategy_template_new - strategy_template_name = #{template.templateName}, - strategy_template_source_system = #{template.sourceSystem}, - has_protect_object_ip = #{template.hasProtectObjectIp}, - has_protect_object_port = #{template.hasProtectObjectPort}, - has_protocol = #{template.hasProtocol}, - has_url = #{template.hasUrl}, - has_dns = #{template.hasDns}, - has_peer_ip = #{template.hasPeerIp}, - has_peer_port = #{template.hasPeerPort}, - is_full_flow = #{template.isFullFlow}, - is_protect_object_src = #{template.isProtectObjectSrc}, + strategy_template_name = #{template.templateName}, + strategy_template_source_system = #{template.sourceSystem}, + event_type = #{template.eventType}, + protect_level = #{template.protectLevel}, + + has_protect_object_ip = #{template.hasProtectObjectIP}, + has_protect_object_port = #{template.hasProtectObjectPort}, + has_protocol = #{template.hasProtocol}, + has_url = #{template.hasURL}, + has_dns = #{template.hasDNS}, + has_peer_ip = #{template.hasPeerIP}, + has_peer_port = #{template.hasPeerPort}, + is_full_flow = #{template.isFullFlow}, + is_protect_object_src = #{template.isProtectObjectIPSrc}, modify_time = NOW() @@ -41,8 +46,33 @@ AND strategy_template_id = #{template.templateId} + + UPDATE t_strategy_template_new + SET audit_status = #{auditStatus} + WHERE strategy_template_id = #{id} + + + update t_strategy_template_new + set audit_status = CASE strategy_template_id + + WHEN #{id} THEN #{auditStatus} + + END + WHERE strategy_template_id IN + + #{id} + + + + UPDATE t_strategy_template_new + SET audit_info = #{auditInfo} + WHERE strategy_template_id IN + + #{id} + + @@ -140,6 +170,37 @@ - + + + + + + \ No newline at end of file diff --git a/src/test/java/com/realtime/protection/server/alertmessage/AlertMessageTest.java b/src/test/java/com/realtime/protection/server/alertmessage/AlertMessageTest.java index c5b788d..1b8295e 100644 --- a/src/test/java/com/realtime/protection/server/alertmessage/AlertMessageTest.java +++ b/src/test/java/com/realtime/protection/server/alertmessage/AlertMessageTest.java @@ -63,7 +63,7 @@ public class AlertMessageTest { object.setTemplateId(templates.get(0).getTemplateId()); object.setProtectObjectIds(List.of(new Integer[]{protectObject.get(0).getProtectObjectId()})); Integer dynamicRuleId = dynamicRuleService.newDynamicRuleObject(object); - dynamicRuleService.updateAuditStatus(object.getDynamicRuleId(), 2); + dynamicRuleService.updateAuditStatus(object.getDynamicRuleId(), 2,null,null,null); Task task = new Task(); @@ -84,24 +84,24 @@ public class AlertMessageTest { //审核状态 taskService.changeTaskAuditStatus(taskId, 2); //启动任务 -// stateChangeService.changeState(2, taskId, false); + stateChangeService.changeState(2, taskId, false); -// for (int i = 0 ; i< 5; i++) { -// AlertMessage alert = new AlertMessage(); -// FiveTupleWithMask fiveTupleWithMask = new FiveTupleWithMask(); -// fiveTupleWithMask.setSourceIP("111.1.1." + i); -// fiveTupleWithMask.setDestinationIP("222.22.2." + i); -// fiveTupleWithMask.setSourcePort("111"); -// fiveTupleWithMask.setDestinationPort("222"); -// fiveTupleWithMask.setProtocol("tcp"); -// -// alert.setDynamicRuleId(dynamicRuleId); -// alert.setTaskId(taskId); -// alert.setFiveTupleWithMask(fiveTupleWithMask); -// alert.setContent("testcontent"); -// alert.setProtectIsSrcOrDst(1); -// alertMessageService.processAlertMessage(alert); -// } + for (int i = 0 ; i< 5; i++) { + AlertMessage alert = new AlertMessage(); + FiveTupleWithMask fiveTupleWithMask = new FiveTupleWithMask(); + fiveTupleWithMask.setSourceIP("111.1.1." + i); + fiveTupleWithMask.setDestinationIP("222.22.2." + i); + fiveTupleWithMask.setSourcePort("111"); + fiveTupleWithMask.setDestinationPort("222"); + fiveTupleWithMask.setProtocol("tcp"); + + alert.setDynamicRuleId(dynamicRuleId); + alert.setTaskId(taskId); + alert.setFiveTupleWithMask(fiveTupleWithMask); + alert.setContent("testcontent"); + alert.setProtectIsSrcOrDst(1); + alertMessageService.processAlertMessage(alert); + } diff --git a/src/test/java/com/realtime/protection/server/defense/templatenew/NewTemplateServiceTest.java b/src/test/java/com/realtime/protection/server/defense/templatenew/NewTemplateServiceTest.java new file mode 100644 index 0000000..914d23b --- /dev/null +++ b/src/test/java/com/realtime/protection/server/defense/templatenew/NewTemplateServiceTest.java @@ -0,0 +1,72 @@ +package com.realtime.protection.server.defense.templatenew; + +import com.realtime.protection.configuration.entity.defense.template.TemplateNew; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.dao.DuplicateKeyException; + +import java.time.LocalDateTime; + +import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertTrue; + +@SpringBootTest +public class NewTemplateServiceTest { + + private final TemplateService templateService; + private TemplateNew template; + private Long startTime; + + + @Autowired + NewTemplateServiceTest(TemplateService templateService) { + this.templateService = templateService; + } + + @BeforeEach + void mockTemplate() { + + template = new TemplateNew(); + + template.setTemplateName("反射型DDOS攻击"); + template.setSourceSystem("xxxx系统"); + template.setEventType("dsdos"); + template.setHasPeerIP(true); + template.setProtectLevel("2"); + + + + startTime = System.currentTimeMillis(); + } + + @AfterEach + void summary() { + Long endTime = System.currentTimeMillis(); + System.out.printf("total time: %d ms", endTime - startTime); + } + + @Test + void testNewTemplate() { + try { + Integer templateId = templateService.newTemplate(template); + assertTrue(templateId > 0); + } catch (DuplicateKeyException e) { + System.out.println(e.getMessage()); + } + + for (int i = 0; i < 2; i++) { + assertThrows(DuplicateKeyException.class, () -> { + Integer templateId = templateService.newTemplate(template); + assertTrue(templateId > 0); + }); + assertDoesNotThrow(() -> { + template.setTemplateName("反射型DDOS攻击-" + LocalDateTime.now()); + Integer templateId = templateService.newTemplate(template); + assertTrue(templateId > 0); + }); + } + } +} diff --git a/src/test/java/com/realtime/protection/server/rule/dynamic/DynamicRuleServiceTest.java b/src/test/java/com/realtime/protection/server/rule/dynamic/DynamicRuleServiceTest.java index e4a344f..34a4dc7 100644 --- a/src/test/java/com/realtime/protection/server/rule/dynamic/DynamicRuleServiceTest.java +++ b/src/test/java/com/realtime/protection/server/rule/dynamic/DynamicRuleServiceTest.java @@ -82,7 +82,7 @@ public class DynamicRuleServiceTest extends ProtectionApplicationTests { object.setTemplateId(templates.get(0).getTemplateId()); object.setProtectObjectIds(List.of(new Integer[]{protectObject.get(0).getProtectObjectId()})); Integer dynamicRuleId = dynamicRuleService.newDynamicRuleObject(object); - dynamicRuleService.updateAuditStatus(dynamicRuleId, 2); + dynamicRuleService.updateAuditStatus(dynamicRuleId, 2,null,null,null); Task task = new Task(); diff --git a/src/test/java/com/realtime/protection/server/task/TaskServiceTest.java b/src/test/java/com/realtime/protection/server/task/TaskServiceTest.java index 3ef0fc8..948444e 100644 --- a/src/test/java/com/realtime/protection/server/task/TaskServiceTest.java +++ b/src/test/java/com/realtime/protection/server/task/TaskServiceTest.java @@ -265,7 +265,7 @@ class TaskServiceTest extends ProtectionApplicationTests { List staticRuleIds = new ArrayList<>(); staticRuleIds.add(staticRuleId); - staticRuleService.updateAuditStatus(staticRuleId, 2); + staticRuleService.updateAuditStatus(staticRuleId, 2,null,null,null); task.setStaticRuleIds(staticRuleIds); @@ -307,7 +307,7 @@ class TaskServiceTest extends ProtectionApplicationTests { object.setTemplateId(templates.get(0).getTemplateId()); object.setProtectObjectIds(List.of(new Integer[]{protectObject.get(0).getProtectObjectId()})); Integer dynamicRuleId = dynamicRuleService.newDynamicRuleObject(object); - dynamicRuleService.updateAuditStatus(object.getDynamicRuleId(), 2); + dynamicRuleService.updateAuditStatus(object.getDynamicRuleId(), 2,null,null,null);