1、静态规则文件上传bug解决,文件上传增加ip、掩码不匹配判断
2、策略模板新增querySourceSystem、queryEventNam、queryTemplateId方法用于动态规则新建
This commit is contained in:
@@ -7,6 +7,7 @@ import jakarta.validation.constraints.Min;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/template")
|
||||
@@ -75,4 +76,29 @@ public class TemplateController implements TemplateControllerApi {
|
||||
.setData("template_id", templateId)
|
||||
.setData("success", templateService.deleteTemplate(templateId));
|
||||
}
|
||||
|
||||
@Override
|
||||
@GetMapping("/query/source_system")
|
||||
public ResponseResult querySourceSystem() {
|
||||
return ResponseResult.ok()
|
||||
.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
|
||||
@PostMapping("/query/templateId")
|
||||
public ResponseResult queryTemplateId(@RequestBody Map<String,String> map) {
|
||||
String sourceSystem = map.get("source_system");
|
||||
String eventName = map.get("event_name");
|
||||
return ResponseResult.ok()
|
||||
.setData("template_id", templateService.queryTemplateId(sourceSystem, eventName));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -13,6 +13,8 @@ import jakarta.validation.Valid;
|
||||
import jakarta.validation.constraints.Min;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@Tag(name = "防御策略模板API", description = "防御策略模板模块所有接口")
|
||||
public interface TemplateControllerApi {
|
||||
@PostMapping("/new")
|
||||
@@ -39,7 +41,7 @@ public interface TemplateControllerApi {
|
||||
""",
|
||||
description = """
|
||||
"success": 新建防御策略模板是否成功
|
||||
|
||||
|
||||
"template_id": 新建防御策略模板ID
|
||||
"""
|
||||
)
|
||||
@@ -147,17 +149,17 @@ public interface TemplateControllerApi {
|
||||
""",
|
||||
description = """
|
||||
"template_id": 防御策略模板ID
|
||||
|
||||
|
||||
"template_name": 防御策略模板名称
|
||||
|
||||
|
||||
"protect_level_low": 防御策略模板日常态数据
|
||||
|
||||
|
||||
"protect_level_medium": 防御策略模板应急态数据
|
||||
|
||||
|
||||
"protect_level_high": 防御策略模板紧急态数据
|
||||
|
||||
|
||||
"template_used_times": 防御策略模板使用次数
|
||||
|
||||
|
||||
"running_tasks": 防御策略模板任务运行数量
|
||||
"""
|
||||
)
|
||||
@@ -232,17 +234,17 @@ public interface TemplateControllerApi {
|
||||
""",
|
||||
description = """
|
||||
"template_id": 防御策略模板ID
|
||||
|
||||
|
||||
"template_name": 防御策略模板名称
|
||||
|
||||
|
||||
"protect_level_low": 防御策略模板日常态数据
|
||||
|
||||
|
||||
"protect_level_medium": 防御策略模板应急态数据
|
||||
|
||||
|
||||
"protect_level_high": 防御策略模板紧急态数据
|
||||
|
||||
|
||||
"template_used_times": 防御策略模板使用次数
|
||||
|
||||
|
||||
"running_tasks": 防御策略模板任务运行数量
|
||||
"""
|
||||
)
|
||||
@@ -279,7 +281,7 @@ public interface TemplateControllerApi {
|
||||
""",
|
||||
description = """
|
||||
"success": 更新是否成功
|
||||
|
||||
|
||||
"template_id": 更新的策略模板ID
|
||||
"""
|
||||
)
|
||||
@@ -317,7 +319,7 @@ public interface TemplateControllerApi {
|
||||
""",
|
||||
description = """
|
||||
"success": 删除是否成功
|
||||
|
||||
|
||||
"template_id": 删除的策略模板ID
|
||||
"""
|
||||
)
|
||||
@@ -329,4 +331,54 @@ public interface TemplateControllerApi {
|
||||
}
|
||||
)
|
||||
ResponseResult deleteTemplate(@PathVariable @Min(1) Integer templateId);
|
||||
}
|
||||
|
||||
|
||||
@GetMapping("/source_system")
|
||||
@Operation(
|
||||
summary = "查询来源系统名称",
|
||||
description = "查询策略模板中的所有来源系统名称",
|
||||
responses = {
|
||||
@ApiResponse(
|
||||
description = "返回来源系统名称查询结果,返回字符串列表",
|
||||
content = @Content(
|
||||
mediaType = "application/json",
|
||||
schema = @Schema(implementation = ResponseResult.class)
|
||||
)
|
||||
)
|
||||
}
|
||||
)
|
||||
ResponseResult querySourceSystem();
|
||||
|
||||
@GetMapping("/query/event_name/{sourceSystem}")
|
||||
@Operation(
|
||||
summary = "查询事件类型",
|
||||
description = "查询当前来源系统下的事件类型",
|
||||
responses = {
|
||||
@ApiResponse(
|
||||
description = "返回当前来源系统下的事件类型,返回字符串列表",
|
||||
content = @Content(
|
||||
mediaType = "application/json",
|
||||
schema = @Schema(implementation = ResponseResult.class)
|
||||
)
|
||||
)
|
||||
}
|
||||
)
|
||||
ResponseResult queryEventName(@PathVariable String sourceSystem);
|
||||
|
||||
@PostMapping("/query/templateId")
|
||||
@Operation(
|
||||
summary = "查询策略模板id",
|
||||
description = "根据来源系统和事件类型查询策略模板id",
|
||||
responses = {
|
||||
@ApiResponse(
|
||||
description = "返回来源系统和事件类型对应的策略模板id,整数",
|
||||
content = @Content(
|
||||
mediaType = "application/json",
|
||||
schema = @Schema(implementation = ResponseResult.class)
|
||||
)
|
||||
)
|
||||
}
|
||||
)
|
||||
|
||||
public ResponseResult queryTemplateId(@RequestBody Map<String,String> map);
|
||||
}
|
||||
@@ -28,4 +28,10 @@ public interface TemplateMapper {
|
||||
Boolean deleteTemplate(@Param("template_id") Integer templateId);
|
||||
|
||||
Integer queryTemplateTotalNum(String templateName);
|
||||
|
||||
List<String> querySourceSystem();
|
||||
|
||||
List<String> queryEventName(String sourceSystem);
|
||||
|
||||
Integer queryTemplateId(String sourceSystem, String eventName);
|
||||
}
|
||||
|
||||
@@ -50,4 +50,16 @@ public class TemplateService {
|
||||
public Integer queryTemplateTotalNum(String templateName) {
|
||||
return templateMapper.queryTemplateTotalNum(templateName);
|
||||
}
|
||||
|
||||
public List<String> querySourceSystem() {
|
||||
return templateMapper.querySourceSystem();
|
||||
}
|
||||
|
||||
public List<String> queryEventName(String sourceSystem) {
|
||||
return templateMapper.queryEventName(sourceSystem);
|
||||
}
|
||||
|
||||
public Integer queryTemplateId(String sourceSystem, String eventName) {
|
||||
return templateMapper.queryTemplateId(sourceSystem, eventName);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import com.realtime.protection.configuration.entity.rule.staticrule.StaticRuleOb
|
||||
import com.realtime.protection.configuration.response.ResponseResult;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import jakarta.validation.Valid;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
@@ -44,7 +45,8 @@ public class StaticRuleController implements StaticRuleControllerApi {
|
||||
//以Excel方式批量导入静态规则
|
||||
@PostMapping("/upload")
|
||||
@Override
|
||||
public ResponseResult uploadFile(@RequestPart("file")MultipartFile uploadFile) throws IOException {
|
||||
public ResponseResult uploadFile(@NotNull(message = "uploadFile字段不能为空")
|
||||
MultipartFile uploadFile) throws IOException {
|
||||
EasyExcel.read(uploadFile.getInputStream(), StaticRuleObject.class,
|
||||
new StaticRuleDataListener(staticRuleService)).sheet().doRead();
|
||||
return ResponseResult.ok();
|
||||
|
||||
@@ -10,6 +10,7 @@ import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import jakarta.validation.Valid;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
@@ -65,7 +66,7 @@ public interface StaticRuleControllerApi {
|
||||
requestBody = @io.swagger.v3.oas.annotations.parameters.RequestBody(
|
||||
description = "Excel文件")
|
||||
)
|
||||
ResponseResult uploadFile(@RequestPart("file")MultipartFile uploadFile) throws IOException;
|
||||
ResponseResult uploadFile(@NotNull(message = "uploadFile字段不能为空")MultipartFile uploadFile) throws IOException;
|
||||
|
||||
@Operation(
|
||||
summary = "下载静态规则模板",
|
||||
|
||||
@@ -23,6 +23,16 @@ public class StaticRuleDataListener implements ReadListener<StaticRuleObject> {
|
||||
@Override
|
||||
public void invoke(StaticRuleObject object, AnalysisContext analysisContext) {
|
||||
log.info("解析到一条数据:{}", object.toString());
|
||||
if (!staticRuleService.isIpMaskValid(object.getStaticRuleSip(),object.getStaticRuleMsip()) ||
|
||||
!staticRuleService.isIpMaskValid(object.getStaticRuleDip(),object.getStaticRuleMdip())
|
||||
){
|
||||
throw new IllegalArgumentException("IP和IP掩码不匹配!静态规则名称:" +
|
||||
object.getStaticRuleName() + ",源ip:" +
|
||||
object.getStaticRuleSip() + ",源ip掩码:" +
|
||||
object.getStaticRuleMsip() + ",目的ip:" +
|
||||
object.getStaticRuleDip() + ",目的ip掩码:" +
|
||||
object.getStaticRuleMdip() );
|
||||
}
|
||||
cachedDataList.add(object);
|
||||
if (cachedDataList.size() > batchCount) {
|
||||
saveData();
|
||||
|
||||
@@ -36,7 +36,7 @@ public class StaticRuleService {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
private Boolean isIpMaskValid(String ip, String mip) {
|
||||
public Boolean isIpMaskValid(String ip, String mip) {
|
||||
if (ip == null && mip != null) throw new IllegalArgumentException("有ip掩码但没设置ip");
|
||||
if (mip == null) return true;
|
||||
|
||||
|
||||
@@ -113,6 +113,19 @@
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
<select id="querySourceSystem" resultType="java.lang.String">
|
||||
SELECT DISTINCT strategy_template_source_system FROM t_strategy_template
|
||||
</select>
|
||||
<select id="queryEventName" resultType="java.lang.String">
|
||||
SELECT DISTINCT strategy_template_name
|
||||
FROM t_strategy_template
|
||||
WHERE strategy_template_source_system = #{sourceSystem}
|
||||
</select>
|
||||
<select id="queryTemplateId" resultType="java.lang.Integer">
|
||||
SELECT strategy_template_id
|
||||
FROM t_strategy_template
|
||||
WHERE strategy_template_name = #{eventName} AND strategy_template_source_system = #{sourceSystem}
|
||||
</select>
|
||||
|
||||
<update id="updateTemplateInformation">
|
||||
UPDATE t_strategy_template
|
||||
|
||||
Reference in New Issue
Block a user