1、静态规则文件上传bug解决,文件上传增加ip、掩码不匹配判断

2、策略模板新增querySourceSystem、queryEventNam、queryTemplateId方法用于动态规则新建
This commit is contained in:
Hao Miao
2024-01-31 18:11:29 +08:00
parent 11fb439e4c
commit 384c48ae78
9 changed files with 141 additions and 19 deletions

View File

@@ -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();

View File

@@ -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 = "下载静态规则模板",

View File

@@ -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();

View File

@@ -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;