1、重构Template,一个策略模板只有一个防护等级,并且把防护等级配置都放在策略模板中。补充新Template的crud、审批等方法,并写swager
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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);
|
||||
@@ -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<TemplateMapper, Function<Map<Integer, Integer>, Boolean>> updateTemplateAuditStatusFunction =
|
||||
Function<TemplateMapperOld, Function<Map<Integer, Integer>, 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);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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<TemplateNew> 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<String> querySourceSystem();
|
||||
|
||||
List<String> queryEventName(String sourceSystem);
|
||||
// List<String> queryEventName(String sourceSystem);
|
||||
|
||||
// Integer queryTemplateId(String sourceSystem, String eventName);
|
||||
|
||||
@@ -59,7 +57,7 @@ public interface TemplateMapper {
|
||||
|
||||
void updateAuditStatusByIdBatch(@Param("idWithAuditStatusBatch") Map<Integer, Integer> idWithAuditStatusBatch);
|
||||
|
||||
Boolean updateAuditInfo(List<Integer> ids, String auditInfo);
|
||||
Boolean updateAuditInfo(@Param("ids")List<Integer> ids,@Param("auditInfo") String auditInfo);
|
||||
|
||||
String queryAuditInfo(Integer id);
|
||||
|
||||
|
||||
@@ -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")
|
||||
ResponseResult deleteTemplate(@PathVariable @Min(1) Integer templateId);
|
||||
@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<Integer, Integer> 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<Integer> ids,
|
||||
@RequestBody Map<String, String> 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);
|
||||
}
|
||||
|
||||
@@ -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<String> queryEventName(String sourceSystem) {
|
||||
return templateMapper.queryEventName(sourceSystem);
|
||||
}
|
||||
// public List<String> queryEventName(String sourceSystem) {
|
||||
// return templateMapper.queryEventName(sourceSystem);
|
||||
// }
|
||||
|
||||
|
||||
|
||||
@@ -132,7 +131,7 @@ public class TemplateService {
|
||||
throw new IllegalArgumentException("策略模板无法修改为对应审核状态, 错误id: " + errorIds);
|
||||
}
|
||||
|
||||
Function<com.realtime.protection.server.defense.template.TemplateMapper, Function<Map<Integer, Integer>, Boolean>> updateTemplateAuditStatusFunction =
|
||||
Function<TemplateMapper, Function<Map<Integer, Integer>, 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);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -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})
|
||||
</insert>
|
||||
|
||||
<update id="updateTemplateInformation">
|
||||
UPDATE t_strategy_template_new
|
||||
<set>
|
||||
<if test="template.templateName != null">strategy_template_name = #{template.templateName},</if>
|
||||
<if test="template.sourceSystem != null">strategy_template_source_system = #{template.sourceSystem},</if>
|
||||
<if test="template.template.hasProtectObjectIp != null">has_protect_object_ip = #{template.hasProtectObjectIp},</if>
|
||||
<if test="template.template.hasProtectObjectPort != null">has_protect_object_port = #{template.hasProtectObjectPort},</if>
|
||||
<if test="template.template.hasProtocol != null">has_protocol = #{template.hasProtocol},</if>
|
||||
<if test="template.template.hasUrl != null">has_url = #{template.hasUrl},</if>
|
||||
<if test="template.template.hasDns != null">has_dns = #{template.hasDns},</if>
|
||||
<if test="template.template.hasPeerIp != null">has_peer_ip = #{template.hasPeerIp},</if>
|
||||
<if test="template.template.hasPeerPort != null">has_peer_port = #{template.hasPeerPort},</if>
|
||||
<if test="template.template.isFullFlow != null">is_full_flow = #{template.isFullFlow},</if>
|
||||
<if test="template.template.isProtectObjectSrc != null">is_protect_object_src = #{template.isProtectObjectSrc},</if>
|
||||
<if test="template.templateName != null and template.templateName != ''">strategy_template_name = #{template.templateName},</if>
|
||||
<if test="template.sourceSystem != null and template.sourceSystem != ''">strategy_template_source_system = #{template.sourceSystem},</if>
|
||||
<if test="template.eventType != null and template.eventType != ''">event_type = #{template.eventType},</if>
|
||||
<if test="template.protectLevel != null and template.protectLevel != ''">protect_level = #{template.protectLevel},</if>
|
||||
|
||||
<if test="template.hasProtectObjectIP != null">has_protect_object_ip = #{template.hasProtectObjectIP},</if>
|
||||
<if test="template.hasProtectObjectPort != null">has_protect_object_port = #{template.hasProtectObjectPort},</if>
|
||||
<if test="template.hasProtocol != null">has_protocol = #{template.hasProtocol},</if>
|
||||
<if test="template.hasURL != null">has_url = #{template.hasURL},</if>
|
||||
<if test="template.hasDNS != null">has_dns = #{template.hasDNS},</if>
|
||||
<if test="template.hasPeerIP != null">has_peer_ip = #{template.hasPeerIP},</if>
|
||||
<if test="template.hasPeerPort != null">has_peer_port = #{template.hasPeerPort},</if>
|
||||
<if test="template.isFullFlow != null">is_full_flow = #{template.isFullFlow},</if>
|
||||
<if test="template.isProtectObjectIPSrc != null">is_protect_object_src = #{template.isProtectObjectIPSrc},</if>
|
||||
|
||||
modify_time = NOW()
|
||||
</set>
|
||||
@@ -41,8 +46,33 @@
|
||||
AND strategy_template_id = #{template.templateId}
|
||||
</where>
|
||||
</update>
|
||||
<update id="updateAuditStatusById">
|
||||
UPDATE t_strategy_template_new
|
||||
SET audit_status = #{auditStatus}
|
||||
WHERE strategy_template_id = #{id}
|
||||
</update>
|
||||
|
||||
<update id="updateAuditStatusByIdBatch">
|
||||
update t_strategy_template_new
|
||||
set audit_status = CASE strategy_template_id
|
||||
<foreach collection="idWithAuditStatusBatch" index="id" item="auditStatus" separator=" ">
|
||||
WHEN #{id} THEN #{auditStatus}
|
||||
</foreach>
|
||||
END
|
||||
WHERE strategy_template_id IN
|
||||
<foreach collection="idWithAuditStatusBatch" index="id" open="(" separator="," close=")">
|
||||
#{id}
|
||||
</foreach>
|
||||
</update>
|
||||
|
||||
<update id="updateAuditInfo">
|
||||
UPDATE t_strategy_template_new
|
||||
SET audit_info = #{auditInfo}
|
||||
WHERE strategy_template_id IN
|
||||
<foreach collection="ids" item="id" open="(" separator="," close=")">
|
||||
#{id}
|
||||
</foreach>
|
||||
</update>
|
||||
|
||||
<resultMap id="templateMap" type="com.realtime.protection.configuration.entity.defense.template.TemplateNew">
|
||||
<id column="strategy_template_id" property="templateId"/>
|
||||
@@ -140,6 +170,37 @@
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<select id="querySourceSystem" resultType="java.lang.String">
|
||||
SELECT DISTINCT dict_label
|
||||
FROM t_dict_data
|
||||
WHERE dict_type = 'source_system' and status = 0
|
||||
</select>
|
||||
<select id="queryUsedTemplateTotalNum" resultType="java.lang.Integer">
|
||||
SELECT COUNT(DISTINCT template_id)
|
||||
FROM t_dynamic_rule
|
||||
</select>
|
||||
<select id="queryAuditTemplateTotalNum" resultType="java.lang.Integer">
|
||||
SELECT COUNT(*)
|
||||
FROM t_strategy_template_new
|
||||
WHERE audit_status = #{auditState}
|
||||
</select>
|
||||
<select id="queryAuditStatusById" resultType="java.lang.Integer">
|
||||
SELECT audit_status
|
||||
FROM t_strategy_template_new
|
||||
WHERE strategy_template_id = #{id}
|
||||
</select>
|
||||
<select id="queryAuditStatusByIds" resultType="java.lang.Integer">
|
||||
select audit_status
|
||||
from t_strategy_template_new
|
||||
where strategy_template_id in
|
||||
<foreach collection="idsWithAuditStatusMap" index="id" open="(" separator="," close=")">
|
||||
#{id}
|
||||
</foreach>
|
||||
</select>
|
||||
<select id="queryAuditInfo" resultType="java.lang.String">
|
||||
SELECT audit_info
|
||||
FROM t_strategy_template_new
|
||||
WHERE strategy_template_id = #{id}
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
|
||||
@@ -265,7 +265,7 @@ class TaskServiceTest extends ProtectionApplicationTests {
|
||||
|
||||
List<Integer> 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);
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user