1. 添加策略模板API文档
This commit is contained in:
@@ -1,18 +1,13 @@
|
|||||||
package com.realtime.protection;
|
package com.realtime.protection;
|
||||||
|
|
||||||
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
|
||||||
|
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
public class ProtectionApplication {
|
public class ProtectionApplication {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
SpringApplicationBuilder builder = new SpringApplicationBuilder(ProtectionApplication.class);
|
SpringApplication.run(ProtectionApplication.class, args);
|
||||||
|
|
||||||
// 在实际环境中应该修改为prod
|
|
||||||
builder.application().setAdditionalProfiles("test");
|
|
||||||
|
|
||||||
builder.run(args);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package com.realtime.protection.configuration.entity.task;
|
package com.realtime.protection.configuration.entity.task;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
import io.swagger.v3.oas.annotations.Parameter;
|
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import jakarta.validation.constraints.Future;
|
import jakarta.validation.constraints.Future;
|
||||||
import jakarta.validation.constraints.NotNull;
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import lombok.extern.slf4j.Slf4j;
|
|||||||
import org.apache.ibatis.exceptions.PersistenceException;
|
import org.apache.ibatis.exceptions.PersistenceException;
|
||||||
import org.springframework.context.support.DefaultMessageSourceResolvable;
|
import org.springframework.context.support.DefaultMessageSourceResolvable;
|
||||||
import org.springframework.core.annotation.Order;
|
import org.springframework.core.annotation.Order;
|
||||||
|
import org.springframework.dao.DuplicateKeyException;
|
||||||
import org.springframework.web.bind.MethodArgumentNotValidException;
|
import org.springframework.web.bind.MethodArgumentNotValidException;
|
||||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||||
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||||
@@ -27,7 +28,7 @@ public class GlobalExceptionHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Order(3)
|
@Order(3)
|
||||||
@ExceptionHandler(value = Exception.class)
|
@ExceptionHandler(value = {Exception.class})
|
||||||
public ResponseResult handleGlobalException(Exception e) {
|
public ResponseResult handleGlobalException(Exception e) {
|
||||||
log.error("meets global exception: " + e.getMessage());
|
log.error("meets global exception: " + e.getMessage());
|
||||||
return ResponseResult.error().setMessage(e.getMessage());
|
return ResponseResult.error().setMessage(e.getMessage());
|
||||||
@@ -35,13 +36,20 @@ public class GlobalExceptionHandler {
|
|||||||
|
|
||||||
|
|
||||||
@Order(2)
|
@Order(2)
|
||||||
@ExceptionHandler(value = PersistenceException.class)
|
@ExceptionHandler(value = {PersistenceException.class})
|
||||||
public ResponseResult handleSQLException(PersistenceException e) {
|
public ResponseResult handleSQLException(PersistenceException e) {
|
||||||
log.error("meets database exception: " + e.getMessage());
|
log.error("meets database exception: " + e.getMessage());
|
||||||
return ResponseResult.invalid().setMessage(
|
return ResponseResult.invalid().setMessage(
|
||||||
"please check the integrity of the data. check if the json data exists in the database");
|
"please check the integrity of the data. check if the json data exists in the database");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Order(2)
|
||||||
|
@ExceptionHandler(value = DuplicateKeyException.class)
|
||||||
|
public ResponseResult handleDuplicateKeyException(DuplicateKeyException e) {
|
||||||
|
log.debug("meets duplicate key exception: " + e.getMessage());
|
||||||
|
return ResponseResult.invalid().setMessage("duplicate key in json data");
|
||||||
|
}
|
||||||
|
|
||||||
@Order(2)
|
@Order(2)
|
||||||
@ExceptionHandler(value = MethodArgumentNotValidException.class)
|
@ExceptionHandler(value = MethodArgumentNotValidException.class)
|
||||||
public ResponseResult handleBindException(MethodArgumentNotValidException e) {
|
public ResponseResult handleBindException(MethodArgumentNotValidException e) {
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import java.util.LinkedHashMap;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@Schema(name = "通用返回对象", description = "用于所有接口返回的通用返回对象")
|
@Schema(description = "用于所有接口返回的通用返回对象")
|
||||||
public class ResponseResult implements Serializable {
|
public class ResponseResult implements Serializable {
|
||||||
|
|
||||||
@Schema(description = "状态码")
|
@Schema(description = "状态码")
|
||||||
|
|||||||
@@ -3,8 +3,6 @@ package com.realtime.protection.configuration.swagger;
|
|||||||
import io.swagger.v3.oas.annotations.OpenAPIDefinition;
|
import io.swagger.v3.oas.annotations.OpenAPIDefinition;
|
||||||
import io.swagger.v3.oas.annotations.info.Contact;
|
import io.swagger.v3.oas.annotations.info.Contact;
|
||||||
import io.swagger.v3.oas.annotations.info.Info;
|
import io.swagger.v3.oas.annotations.info.Info;
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
|
|
||||||
@OpenAPIDefinition(
|
@OpenAPIDefinition(
|
||||||
info = @Info(
|
info = @Info(
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package com.realtime.protection.server.command;
|
package com.realtime.protection.server.command;
|
||||||
|
|
||||||
import com.baomidou.dynamic.datasource.annotation.DS;
|
|
||||||
import com.realtime.protection.configuration.entity.task.Command;
|
import com.realtime.protection.configuration.entity.task.Command;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
import org.apache.ibatis.annotations.Param;
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import com.realtime.protection.configuration.entity.task.TaskCommandInfo;
|
|||||||
import com.realtime.protection.configuration.exception.DorisStartException;
|
import com.realtime.protection.configuration.exception.DorisStartException;
|
||||||
import com.realtime.protection.configuration.utils.SqlSessionWrapper;
|
import com.realtime.protection.configuration.utils.SqlSessionWrapper;
|
||||||
import com.realtime.protection.configuration.utils.enums.StateEnum;
|
import com.realtime.protection.configuration.utils.enums.StateEnum;
|
||||||
import com.realtime.protection.server.task.TaskMapper;
|
|
||||||
import com.realtime.protection.server.task.TaskService;
|
import com.realtime.protection.server.task.TaskService;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.scheduling.annotation.Async;
|
import org.springframework.scheduling.annotation.Async;
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ import jakarta.servlet.http.HttpServletResponse;
|
|||||||
import jakarta.validation.Valid;
|
import jakarta.validation.Valid;
|
||||||
import jakarta.validation.constraints.Min;
|
import jakarta.validation.constraints.Min;
|
||||||
import jakarta.validation.constraints.NotNull;
|
import jakarta.validation.constraints.NotNull;
|
||||||
import org.apache.coyote.Response;
|
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
@@ -86,7 +85,10 @@ public interface ProtectObjectControllerApi {
|
|||||||
)
|
)
|
||||||
},
|
},
|
||||||
parameters = {
|
parameters = {
|
||||||
@Parameter()
|
@Parameter(name = "proobj_name", description = "防护对象名称"),
|
||||||
|
@Parameter(name = "proobj_id", description = "防护对象ID"),
|
||||||
|
@Parameter(name = "page", description = "页码", example = "1"),
|
||||||
|
@Parameter(name = "page_size", description = "每页的对象个数", example = "5")
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
ResponseResult queryProtectObjects(@RequestParam(value = "proobj_name", required = false)
|
ResponseResult queryProtectObjects(@RequestParam(value = "proobj_name", required = false)
|
||||||
@@ -97,19 +99,102 @@ public interface ProtectObjectControllerApi {
|
|||||||
@RequestParam("page_size") @Min(1) Integer pageSize);
|
@RequestParam("page_size") @Min(1) Integer pageSize);
|
||||||
|
|
||||||
@GetMapping("/{protectObjectId}/query")
|
@GetMapping("/{protectObjectId}/query")
|
||||||
|
@Operation(
|
||||||
|
summary = "查询单个防护对象",
|
||||||
|
description = "根据ID查询单个防护对象的信息",
|
||||||
|
responses = {
|
||||||
|
@ApiResponse(
|
||||||
|
description = "返回单个防护对象信息",
|
||||||
|
content = @Content(
|
||||||
|
mediaType = "application/json",
|
||||||
|
schema = @Schema(implementation = ResponseResult.class)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
},
|
||||||
|
parameters = {
|
||||||
|
@Parameter(name = "protectObjectId", description = "防护对象ID", example = "2")
|
||||||
|
}
|
||||||
|
)
|
||||||
ResponseResult queryProtectObject(@PathVariable Integer protectObjectId) throws IllegalAccessException;
|
ResponseResult queryProtectObject(@PathVariable Integer protectObjectId) throws IllegalAccessException;
|
||||||
|
|
||||||
@PostMapping("/{protectObjectId}/update")
|
@PostMapping("/{protectObjectId}/update")
|
||||||
|
@Operation(
|
||||||
|
summary = "更新防护对象",
|
||||||
|
description = "根据防护对象ID和信息更新防护对象",
|
||||||
|
responses = {
|
||||||
|
@ApiResponse(
|
||||||
|
description = "防护对象更新情况",
|
||||||
|
content = @Content(
|
||||||
|
mediaType = "application/json",
|
||||||
|
schema = @Schema(implementation = ResponseResult.class)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
},
|
||||||
|
parameters = {
|
||||||
|
@Parameter(name = "protectObjectId", description = "防护对象ID", example = "2")
|
||||||
|
},
|
||||||
|
requestBody = @io.swagger.v3.oas.annotations.parameters.RequestBody(description = "防护对象更新信息")
|
||||||
|
)
|
||||||
ResponseResult updateProtectObject(@PathVariable Integer protectObjectId,
|
ResponseResult updateProtectObject(@PathVariable Integer protectObjectId,
|
||||||
@RequestBody @Valid ProtectObject protectObject);
|
@RequestBody @Valid ProtectObject protectObject);
|
||||||
|
|
||||||
|
|
||||||
@DeleteMapping("/{protectObjectId}/delete")
|
@DeleteMapping("/{protectObjectId}/delete")
|
||||||
|
@Operation(
|
||||||
|
summary = "删除防护对象",
|
||||||
|
description = "根据防护对象ID删除对应防护对象",
|
||||||
|
responses = {
|
||||||
|
@ApiResponse(
|
||||||
|
description = "防护对象删除情况",
|
||||||
|
content = @Content(
|
||||||
|
mediaType = "application/json",
|
||||||
|
schema = @Schema(implementation = ResponseResult.class)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
},
|
||||||
|
parameters = {
|
||||||
|
@Parameter(name = "protectObjectId", description = "欲删除的防护对象ID", example = "2")
|
||||||
|
}
|
||||||
|
)
|
||||||
ResponseResult deleteProtectObject(@PathVariable Integer protectObjectId);
|
ResponseResult deleteProtectObject(@PathVariable Integer protectObjectId);
|
||||||
|
|
||||||
@DeleteMapping("/delete/{protectObjectIds}")
|
@DeleteMapping("/delete/{protectObjectIds}")
|
||||||
|
@Operation(
|
||||||
|
summary = "批量删除防护对象",
|
||||||
|
description = "根据多个对象ID删除多个防护对象",
|
||||||
|
responses = {
|
||||||
|
@ApiResponse(
|
||||||
|
description = "防护对象删除情况",
|
||||||
|
content = @Content(
|
||||||
|
mediaType = "application/json",
|
||||||
|
schema = @Schema(implementation = ResponseResult.class)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
},
|
||||||
|
parameters = {
|
||||||
|
@Parameter(name = "protectObjectIds", description = "欲删除的多个防护对象ID", example = "1,2,3,4")
|
||||||
|
}
|
||||||
|
)
|
||||||
ResponseResult deleteProtectObject(@PathVariable List<Integer> protectObjectIds);
|
ResponseResult deleteProtectObject(@PathVariable List<Integer> protectObjectIds);
|
||||||
|
|
||||||
@GetMapping("/{protectObjectId}/audit/{auditStatus}")
|
@GetMapping("/{protectObjectId}/audit/{auditStatus}")
|
||||||
|
@Operation(
|
||||||
|
summary = "修改防护对象审核状态",
|
||||||
|
description = "修改指定防护对象ID对应的防护对象的审核状态",
|
||||||
|
responses = {
|
||||||
|
@ApiResponse(
|
||||||
|
description = "防护对象审核状态修改情况",
|
||||||
|
content = @Content(
|
||||||
|
mediaType = "application/json",
|
||||||
|
schema = @Schema(implementation = ResponseResult.class)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
},
|
||||||
|
parameters = {
|
||||||
|
@Parameter(name = "protectObjectId", description = "欲修改的防护对象ID", example = "2"),
|
||||||
|
@Parameter(name = "auditStatus", description = "欲修改的审核状态", example = "2")
|
||||||
|
}
|
||||||
|
)
|
||||||
ResponseResult changeProtectObjectAuditStatus(@PathVariable Integer protectObjectId,
|
ResponseResult changeProtectObjectAuditStatus(@PathVariable Integer protectObjectId,
|
||||||
@PathVariable Integer auditStatus);
|
@PathVariable Integer auditStatus);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import java.util.List;
|
|||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/template")
|
@RequestMapping("/template")
|
||||||
public class TemplateController {
|
public class TemplateController implements TemplateControllerApi {
|
||||||
|
|
||||||
private final TemplateService templateService;
|
private final TemplateService templateService;
|
||||||
|
|
||||||
@@ -19,6 +19,7 @@ public class TemplateController {
|
|||||||
this.templateService = templateService;
|
this.templateService = templateService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
@PostMapping("/new")
|
@PostMapping("/new")
|
||||||
public ResponseResult newTemplate(@RequestBody @Valid Template template) {
|
public ResponseResult newTemplate(@RequestBody @Valid Template template) {
|
||||||
|
|
||||||
@@ -35,6 +36,7 @@ public class TemplateController {
|
|||||||
.setData("success", false);
|
.setData("success", false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
@GetMapping("/query")
|
@GetMapping("/query")
|
||||||
public ResponseResult queryTemplates(@RequestParam(value = "template_name", required = false) String templateName,
|
public ResponseResult queryTemplates(@RequestParam(value = "template_name", required = false) String templateName,
|
||||||
@RequestParam("page") @Min(1) Integer page,
|
@RequestParam("page") @Min(1) Integer page,
|
||||||
@@ -45,12 +47,19 @@ public class TemplateController {
|
|||||||
.setData("templates", templates);
|
.setData("templates", templates);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
@GetMapping("/{templateId}/query")
|
@GetMapping("/{templateId}/query")
|
||||||
public ResponseResult queryTemplate(@PathVariable Integer templateId) throws IllegalAccessException {
|
public ResponseResult queryTemplate(@PathVariable Integer templateId) throws IllegalAccessException {
|
||||||
|
Template template = templateService.queryTemplate(templateId);
|
||||||
|
if (template == null) {
|
||||||
|
return ResponseResult.invalid()
|
||||||
|
.setMessage("invalid templateId, maybe this template doesn't exist?");
|
||||||
|
}
|
||||||
return ResponseResult.ok()
|
return ResponseResult.ok()
|
||||||
.setDataMap(EntityUtils.entityToMap(templateService.queryTemplate(templateId)));
|
.setDataMap(EntityUtils.entityToMap(template));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
@PostMapping("/{templateId}/update")
|
@PostMapping("/{templateId}/update")
|
||||||
public ResponseResult updateTemplate(@PathVariable @Min(1) Integer templateId,
|
public ResponseResult updateTemplate(@PathVariable @Min(1) Integer templateId,
|
||||||
@RequestBody @Valid Template template) {
|
@RequestBody @Valid Template template) {
|
||||||
@@ -60,6 +69,7 @@ public class TemplateController {
|
|||||||
.setData("success", success);
|
.setData("success", success);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
@DeleteMapping("/{templateId}/delete")
|
@DeleteMapping("/{templateId}/delete")
|
||||||
public ResponseResult deleteTemplate(@PathVariable @Min(1) Integer templateId) {
|
public ResponseResult deleteTemplate(@PathVariable @Min(1) Integer templateId) {
|
||||||
return ResponseResult.ok()
|
return ResponseResult.ok()
|
||||||
|
|||||||
@@ -0,0 +1,114 @@
|
|||||||
|
package com.realtime.protection.server.defense.template;
|
||||||
|
|
||||||
|
import com.realtime.protection.configuration.entity.defense.template.Template;
|
||||||
|
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.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.*;
|
||||||
|
|
||||||
|
@Tag(name = "防御策略模板API", description = "防御策略模板模块所有接口")
|
||||||
|
public interface TemplateControllerApi {
|
||||||
|
@PostMapping("/new")
|
||||||
|
@Operation(
|
||||||
|
summary = "新建防御策略模板",
|
||||||
|
description = "根据信息新建一个防护策略模板",
|
||||||
|
responses = {
|
||||||
|
@ApiResponse(
|
||||||
|
description = "返回新建防御策略模板结果",
|
||||||
|
content = @Content(
|
||||||
|
mediaType = "application/json",
|
||||||
|
schema = @Schema(implementation = ResponseResult.class)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
},
|
||||||
|
requestBody = @io.swagger.v3.oas.annotations.parameters.RequestBody(description = "防御策略模板信息")
|
||||||
|
)
|
||||||
|
ResponseResult newTemplate(@RequestBody @Valid Template template);
|
||||||
|
|
||||||
|
@GetMapping("/query")
|
||||||
|
@Operation(
|
||||||
|
summary = "查询多个防御策略模板",
|
||||||
|
description = "根据查询条件查询多个防御策略模板",
|
||||||
|
responses = {
|
||||||
|
@ApiResponse(
|
||||||
|
description = "返回所有查询到的防御策略模板",
|
||||||
|
content = @Content(
|
||||||
|
mediaType = "application/json",
|
||||||
|
schema = @Schema(implementation = ResponseResult.class)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
},
|
||||||
|
parameters = {
|
||||||
|
@Parameter(name = "template_name", description = "防御策略模板名称", example = "DDOS"),
|
||||||
|
@Parameter(name = "page", description = "页码", example = "1"),
|
||||||
|
@Parameter(name = "page_size", description = "每页对象数量", example = "5")
|
||||||
|
}
|
||||||
|
)
|
||||||
|
ResponseResult queryTemplates(@RequestParam(value = "template_name", required = false) String templateName,
|
||||||
|
@RequestParam("page") @Min(1) Integer page,
|
||||||
|
@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) throws IllegalAccessException;
|
||||||
|
|
||||||
|
@PostMapping("/{templateId}/update")
|
||||||
|
@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 updateTemplate(@PathVariable @Min(1) Integer templateId,
|
||||||
|
@RequestBody @Valid Template template);
|
||||||
|
|
||||||
|
@DeleteMapping("/{templateId}/delete")
|
||||||
|
@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 deleteTemplate(@PathVariable @Min(1) Integer templateId);
|
||||||
|
}
|
||||||
@@ -93,6 +93,9 @@ public interface TaskControllerApi {
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
|
parameters = {
|
||||||
|
@Parameter(name = "taskId", description = "任务ID")
|
||||||
|
},
|
||||||
requestBody = @io.swagger.v3.oas.annotations.parameters.RequestBody(
|
requestBody = @io.swagger.v3.oas.annotations.parameters.RequestBody(
|
||||||
description = "任务信息,必须包含任务原有的或者添加/删除部分后的static_rule_ids和dynamic_rule_ids"
|
description = "任务信息,必须包含任务原有的或者添加/删除部分后的static_rule_ids和dynamic_rule_ids"
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import com.realtime.protection.server.task.status.StateHandler;
|
|||||||
public class GeneratingState extends StateHandler implements State {
|
public class GeneratingState extends StateHandler implements State {
|
||||||
@Override
|
@Override
|
||||||
public Boolean handle(State newState, CommandService commandService, TaskService taskService, Long taskId) throws DorisStartException {
|
public Boolean handle(State newState, CommandService commandService, TaskService taskService, Long taskId) throws DorisStartException {
|
||||||
return switch(StateEnum.getStateEnumByState(newState)) {
|
return switch (StateEnum.getStateEnumByState(newState)) {
|
||||||
case RUNNING, GENERATING -> true;
|
case RUNNING, GENERATING -> true;
|
||||||
case FAILED -> handleFailed(commandService, taskId);
|
case FAILED -> handleFailed(commandService, taskId);
|
||||||
default -> throw new IllegalStateException("Unexpected value: " + StateEnum.getStateEnumByState(newState));
|
default -> throw new IllegalStateException("Unexpected value: " + StateEnum.getStateEnumByState(newState));
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import com.realtime.protection.server.task.status.StateHandler;
|
|||||||
public class RunningState extends StateHandler implements State {
|
public class RunningState extends StateHandler implements State {
|
||||||
@Override
|
@Override
|
||||||
public Boolean handle(State newState, CommandService commandService, TaskService taskService, Long taskId) {
|
public Boolean handle(State newState, CommandService commandService, TaskService taskService, Long taskId) {
|
||||||
return switch(StateEnum.getStateEnumByState(newState)) {
|
return switch (StateEnum.getStateEnumByState(newState)) {
|
||||||
case RUNNING, GENERATING -> true;
|
case RUNNING, GENERATING -> true;
|
||||||
case PAUSED -> handlePause(commandService, taskId);
|
case PAUSED -> handlePause(commandService, taskId);
|
||||||
case STOP -> handleStop(commandService, taskId);
|
case STOP -> handleStop(commandService, taskId);
|
||||||
|
|||||||
@@ -125,9 +125,9 @@ public class WhiteListController {
|
|||||||
|
|
||||||
|
|
||||||
//查询ip是否存在于白名单
|
//查询ip是否存在于白名单
|
||||||
@RequestMapping ("/exist")
|
@RequestMapping("/exist")
|
||||||
public ResponseResult existWhiteListObject(@RequestParam(value = "ruleId", required = true)Integer ruleId,
|
public ResponseResult existWhiteListObject(@RequestParam(value = "ruleId", required = true) Integer ruleId,
|
||||||
@RequestParam(value = "ruleType", required = true)Integer ruleType) {
|
@RequestParam(value = "ruleType", required = true) Integer ruleType) {
|
||||||
//是请求规则的id,然后判断这个id所属的ip是否在白名单中吗
|
//是请求规则的id,然后判断这个id所属的ip是否在白名单中吗
|
||||||
//静态应该可以,但动态的,动态是实时过来告警信息,不存储规则? 存的话也行,那这里要区分id是静态的还是动态的
|
//静态应该可以,但动态的,动态是实时过来告警信息,不存储规则? 存的话也行,那这里要区分id是静态的还是动态的
|
||||||
//这里先走通静态的,要获取规则的源IP和目的IP,去白名单select看有没有(有的还有IP掩码,暂未实现)
|
//这里先走通静态的,要获取规则的源IP和目的IP,去白名单select看有没有(有的还有IP掩码,暂未实现)
|
||||||
|
|||||||
@@ -14,23 +14,26 @@ public interface WhiteListMapper {
|
|||||||
|
|
||||||
//新建
|
//新建
|
||||||
void newWhiteListObject(@Param("object") WhiteListObject object);
|
void newWhiteListObject(@Param("object") WhiteListObject object);
|
||||||
|
|
||||||
//分页查询
|
//分页查询
|
||||||
List<WhiteListObject> queryWhiteListObject(String whiteListName, Integer whiteListId, Integer page, Integer pageSize);
|
List<WhiteListObject> queryWhiteListObject(String whiteListName, Integer whiteListId, Integer page, Integer pageSize);
|
||||||
|
|
||||||
//根据主键查询
|
//根据主键查询
|
||||||
WhiteListObject queryWhiteListObjectById(Integer id);
|
WhiteListObject queryWhiteListObjectById(Integer id);
|
||||||
|
|
||||||
//根据主键删除
|
//根据主键删除
|
||||||
@Delete("delete from t_white_list where white_list_id = #{id}")
|
@Delete("delete from t_white_list where white_list_id = #{id}")
|
||||||
Integer deleteWhiteListObject(Integer id);
|
Integer deleteWhiteListObject(Integer id);
|
||||||
|
|
||||||
Integer updateWhiteListObject(@Param("object") WhiteListObject object);
|
Integer updateWhiteListObject(@Param("object") WhiteListObject object);
|
||||||
|
|
||||||
List<String> existWhiteListObject(@Param("staticRuleObject")StaticRuleObject staticRuleObject);
|
List<String> existWhiteListObject(@Param("staticRuleObject") StaticRuleObject staticRuleObject);
|
||||||
|
|
||||||
Integer queryWhiteListObjectAuditStuatusById(Integer id);
|
Integer queryWhiteListObjectAuditStuatusById(Integer id);
|
||||||
|
|
||||||
Boolean updateWhiteListObjectAuditStatus(Integer id, Integer status);
|
Boolean updateWhiteListObjectAuditStatus(Integer id, Integer status);
|
||||||
|
|
||||||
void newWhiteListObjects(@Param("whiteListObjects")List<WhiteListObject> whiteListBatch);
|
void newWhiteListObjects(@Param("whiteListObjects") List<WhiteListObject> whiteListBatch);
|
||||||
|
|
||||||
void deleteWhiteListObjects(@Param("whiteListIds") List<Integer> whiteListBatch);
|
void deleteWhiteListObjects(@Param("whiteListIds") List<Integer> whiteListBatch);
|
||||||
|
|
||||||
|
|||||||
@@ -128,6 +128,7 @@ public class WhiteListService {
|
|||||||
return whiteListMapper.existWhiteListObject(staticRuleObject);
|
return whiteListMapper.existWhiteListObject(staticRuleObject);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<WhiteListObject> whiteListCommandJudge(Command command) {
|
public List<WhiteListObject> whiteListCommandJudge(Command command) {
|
||||||
//参数应该是指令,不管动态静态
|
//参数应该是指令,不管动态静态
|
||||||
// 命中的whitelist列表:每一列包含ip port url
|
// 命中的whitelist列表:每一列包含ip port url
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ server:
|
|||||||
logging:
|
logging:
|
||||||
level:
|
level:
|
||||||
com.realtime.protection: debug
|
com.realtime.protection: debug
|
||||||
|
file:
|
||||||
|
name: classpath:log/realtime_protection.log
|
||||||
|
|
||||||
spring:
|
spring:
|
||||||
datasource:
|
datasource:
|
||||||
@@ -39,7 +41,13 @@ mybatis:
|
|||||||
|
|
||||||
task:
|
task:
|
||||||
pool:
|
pool:
|
||||||
core-pool-size: 1
|
core-pool-size: 50
|
||||||
max-pool-size: 1
|
max-pool-size: 100
|
||||||
queue-capacity: 1
|
queue-capacity: 50
|
||||||
keep-alive-seconds: 120
|
keep-alive-seconds: 120
|
||||||
|
|
||||||
|
springdoc:
|
||||||
|
api-docs:
|
||||||
|
enabled: false
|
||||||
|
swagger-ui:
|
||||||
|
enabled: false
|
||||||
@@ -1,9 +1,11 @@
|
|||||||
server:
|
server:
|
||||||
port: 8081
|
port: 80
|
||||||
|
|
||||||
logging:
|
logging:
|
||||||
level:
|
level:
|
||||||
com.realtime.protection: warning
|
com.realtime.protection: warning
|
||||||
|
file:
|
||||||
|
name: classpath:log/realtime_protection.log
|
||||||
|
|
||||||
spring:
|
spring:
|
||||||
datasource:
|
datasource:
|
||||||
@@ -41,4 +43,10 @@ task:
|
|||||||
core-pool-size: 20
|
core-pool-size: 20
|
||||||
max-pool-size: 100
|
max-pool-size: 100
|
||||||
queue-capacity: 100
|
queue-capacity: 100
|
||||||
keep-alive-seconds: 60
|
keep-alive-seconds: 120
|
||||||
|
|
||||||
|
springdoc:
|
||||||
|
api-docs:
|
||||||
|
enabled: false
|
||||||
|
swagger-ui:
|
||||||
|
enabled: false
|
||||||
@@ -4,7 +4,8 @@ server:
|
|||||||
logging:
|
logging:
|
||||||
level:
|
level:
|
||||||
com.realtime.protection: info
|
com.realtime.protection: info
|
||||||
|
file:
|
||||||
|
name: classpath:log/realtime_protection.log
|
||||||
|
|
||||||
spring:
|
spring:
|
||||||
datasource:
|
datasource:
|
||||||
@@ -26,7 +27,7 @@ spring:
|
|||||||
aop:
|
aop:
|
||||||
enabled: true
|
enabled: true
|
||||||
primary: mysql
|
primary: mysql
|
||||||
strict: true
|
strict: false
|
||||||
grace-destroy: true
|
grace-destroy: true
|
||||||
mvc:
|
mvc:
|
||||||
servlet:
|
servlet:
|
||||||
@@ -42,7 +43,7 @@ task:
|
|||||||
core-pool-size: 20
|
core-pool-size: 20
|
||||||
max-pool-size: 100
|
max-pool-size: 100
|
||||||
queue-capacity: 100
|
queue-capacity: 100
|
||||||
keep-alive-seconds: 60
|
keep-alive-seconds: 120
|
||||||
|
|
||||||
springdoc:
|
springdoc:
|
||||||
api-docs:
|
api-docs:
|
||||||
|
|||||||
3
src/main/resources/config/application.yml
Normal file
3
src/main/resources/config/application.yml
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
spring:
|
||||||
|
config:
|
||||||
|
import: classpath:config/application-test.yml
|
||||||
@@ -4,7 +4,8 @@
|
|||||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
<mapper namespace="com.realtime.protection.server.command.CommandMapper">
|
<mapper namespace="com.realtime.protection.server.command.CommandMapper">
|
||||||
<insert id="createCommand" parameterType="com.realtime.protection.configuration.entity.task.Command">
|
<insert id="createCommand" parameterType="com.realtime.protection.configuration.entity.task.Command">
|
||||||
insert into t_command(COMMAND_ID, ADDR_TYPE, SRC_IP, SRC_PORT, DST_IP, DST_PORT, PROTOCOL, MASK_SRC_IP, MASK_SRC_PORT,
|
insert into t_command(COMMAND_ID, ADDR_TYPE, SRC_IP, SRC_PORT, DST_IP, DST_PORT, PROTOCOL, MASK_SRC_IP,
|
||||||
|
MASK_SRC_PORT,
|
||||||
MASK_DST_IP, MASK_DST_PORT, IS_VALID, VALID_TIME, INVALID_TIME, IS_SENT,
|
MASK_DST_IP, MASK_DST_PORT, IS_VALID, VALID_TIME, INVALID_TIME, IS_SENT,
|
||||||
CREATE_TIME, LAST_UPDATE, IS_DELETED, TASK_ID)
|
CREATE_TIME, LAST_UPDATE, IS_DELETED, TASK_ID)
|
||||||
values (UUID(), DEFAULT,
|
values (UUID(), DEFAULT,
|
||||||
@@ -18,9 +19,10 @@
|
|||||||
</insert>
|
</insert>
|
||||||
|
|
||||||
<insert id="createCommands" parameterType="com.realtime.protection.configuration.entity.task.Command">
|
<insert id="createCommands" parameterType="com.realtime.protection.configuration.entity.task.Command">
|
||||||
insert into t_command(COMMAND_ID, ADDR_TYPE, SRC_IP, SRC_PORT, DST_IP, DST_PORT, PROTOCOL, MASK_SRC_IP, MASK_SRC_PORT,
|
insert into t_command(COMMAND_ID, ADDR_TYPE, SRC_IP, SRC_PORT, DST_IP, DST_PORT, PROTOCOL, MASK_SRC_IP,
|
||||||
MASK_DST_IP, MASK_DST_PORT, IS_VALID, VALID_TIME, INVALID_TIME, IS_SENT,
|
MASK_SRC_PORT,
|
||||||
CREATE_TIME, LAST_UPDATE, IS_DELETED, TASK_ID)
|
MASK_DST_IP, MASK_DST_PORT, IS_VALID, VALID_TIME, INVALID_TIME, IS_SENT,
|
||||||
|
CREATE_TIME, LAST_UPDATE, IS_DELETED, TASK_ID)
|
||||||
values
|
values
|
||||||
<foreach collection="commands" item="command" separator=",">
|
<foreach collection="commands" item="command" separator=",">
|
||||||
(UUID(), DEFAULT,
|
(UUID(), DEFAULT,
|
||||||
@@ -36,19 +38,24 @@
|
|||||||
|
|
||||||
<update id="stopCommandsByTaskId">
|
<update id="stopCommandsByTaskId">
|
||||||
UPDATE t_command
|
UPDATE t_command
|
||||||
SET IS_VALID = FALSE, LAST_UPDATE = NOW()
|
SET IS_VALID = FALSE,
|
||||||
WHERE TASK_ID = #{task_id} AND IS_DELETED = FALSE
|
LAST_UPDATE = NOW()
|
||||||
|
WHERE TASK_ID = #{task_id}
|
||||||
|
AND IS_DELETED = FALSE
|
||||||
</update>
|
</update>
|
||||||
|
|
||||||
<update id="startCommandsByTaskId">
|
<update id="startCommandsByTaskId">
|
||||||
UPDATE t_command
|
UPDATE t_command
|
||||||
SET IS_VALID = TRUE, LAST_UPDATE = NOW()
|
SET IS_VALID = TRUE,
|
||||||
WHERE TASK_ID = #{task_id} AND IS_DELETED = FALSE
|
LAST_UPDATE = NOW()
|
||||||
|
WHERE TASK_ID = #{task_id}
|
||||||
|
AND IS_DELETED = FALSE
|
||||||
</update>
|
</update>
|
||||||
|
|
||||||
<update id="removeCommandsByTaskId">
|
<update id="removeCommandsByTaskId">
|
||||||
UPDATE t_command
|
UPDATE t_command
|
||||||
SET IS_DELETED = TRUE, LAST_UPDATE = NOW()
|
SET IS_DELETED = TRUE,
|
||||||
|
LAST_UPDATE = NOW()
|
||||||
WHERE TASK_ID = #{task_id}
|
WHERE TASK_ID = #{task_id}
|
||||||
</update>
|
</update>
|
||||||
</mapper>
|
</mapper>
|
||||||
|
|||||||
@@ -4,42 +4,40 @@
|
|||||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
<mapper namespace="com.realtime.protection.server.rule.dynamicrule.DynamicRuleMapper">
|
<mapper namespace="com.realtime.protection.server.rule.dynamicrule.DynamicRuleMapper">
|
||||||
|
|
||||||
<!-- useGeneratedKeys="true": 这个属性指定了是否要获取数据库生成的主键。如果设置为true,MyBatis会使用JDBC的getGeneratedKeys方法来获取由数据库自动生成的主键。-->
|
<!-- useGeneratedKeys="true": 这个属性指定了是否要获取数据库生成的主键。如果设置为true,MyBatis会使用JDBC的getGeneratedKeys方法来获取由数据库自动生成的主键。-->
|
||||||
<!-- keyProperty="id": 这个属性指定了要将生成的主键赋值给哪个属性。在这个例子中,生成的主键将被赋值给名为id的属性。-->
|
<!-- keyProperty="id": 这个属性指定了要将生成的主键赋值给哪个属性。在这个例子中,生成的主键将被赋值给名为id的属性。-->
|
||||||
<insert id="newDynamicRule" useGeneratedKeys="true" keyProperty="dynamicRuleId">
|
<insert id="newDynamicRule" useGeneratedKeys="true" keyProperty="dynamicRuleId">
|
||||||
|
|
||||||
insert into t_dynamic_rule
|
insert into t_dynamic_rule
|
||||||
(dynamic_rule_name,
|
(dynamic_rule_name,
|
||||||
create_time, modify_time, dynamic_rule_create_username,
|
create_time, modify_time, dynamic_rule_create_username,
|
||||||
dynamic_rule_create_depart, dynamic_rule_source_system,
|
dynamic_rule_create_depart, dynamic_rule_source_system,
|
||||||
dynamic_rule_event_type, dynamic_rule_protec_level,
|
dynamic_rule_event_type, dynamic_rule_protec_level,
|
||||||
dynamic_rule_priority, dynamic_rule_range,
|
dynamic_rule_priority, dynamic_rule_range,
|
||||||
dynamic_rule_frequency, dynamic_rule_create_user_id)
|
dynamic_rule_frequency, dynamic_rule_create_user_id)
|
||||||
values
|
values (#{object.dynamicRuleName},
|
||||||
(#{object.dynamicRuleName},
|
#{object.dynamicRuleCreateTime}, #{object.dynamicRuleModifyTime},
|
||||||
#{object.dynamicRuleCreateTime},#{object.dynamicRuleModifyTime},
|
#{object.dynamicRuleCreateUsername}, #{object.dynamicRuleCreateDepart},
|
||||||
#{object.dynamicRuleCreateUsername},#{object.dynamicRuleCreateDepart},
|
#{object.dynamicRuleSourceSystem},
|
||||||
#{object.dynamicRuleSourceSystem},
|
#{object.dynamicRuleEventType}, #{object.dynamicRuleProtectLevel},
|
||||||
#{object.dynamicRuleEventType}, #{object.dynamicRuleProtectLevel},
|
#{object.dynamicRulePriority}, #{object.dynamicRuleRange},
|
||||||
#{object.dynamicRulePriority}, #{object.dynamicRuleRange},
|
#{object.dynamicRuleFrequency},
|
||||||
#{object.dynamicRuleFrequency},
|
#{object.dynamicRuleCreateUserId})
|
||||||
#{object.dynamicRuleCreateUserId})
|
|
||||||
|
|
||||||
</insert>
|
</insert>
|
||||||
|
|
||||||
<insert id="newDynamicRulProtectObjectConcat">
|
<insert id="newDynamicRulProtectObjectConcat">
|
||||||
insert into
|
insert into t_protect_object_dynamic_rule_conn(dynamic_rule_id, protect_object_id)
|
||||||
t_protect_object_dynamic_rule_conn(dynamic_rule_id, protect_object_id)
|
|
||||||
values (#{dynamicRuleId}, #{protectObjectId})
|
values (#{dynamicRuleId}, #{protectObjectId})
|
||||||
</insert>
|
</insert>
|
||||||
<insert id="newDynamicRules">
|
<insert id="newDynamicRules">
|
||||||
insert into t_dynamic_rule
|
insert into t_dynamic_rule
|
||||||
(dynamic_rule_name,
|
(dynamic_rule_name,
|
||||||
create_time, modify_time, dynamic_rule_create_username,
|
create_time, modify_time, dynamic_rule_create_username,
|
||||||
dynamic_rule_create_depart, dynamic_rule_source_system,
|
dynamic_rule_create_depart, dynamic_rule_source_system,
|
||||||
dynamic_rule_event_type, dynamic_rule_protec_level,
|
dynamic_rule_event_type, dynamic_rule_protec_level,
|
||||||
dynamic_rule_priority, dynamic_rule_range,
|
dynamic_rule_priority, dynamic_rule_range,
|
||||||
dynamic_rule_frequency, dynamic_rule_create_user_id
|
dynamic_rule_frequency, dynamic_rule_create_user_id
|
||||||
)
|
)
|
||||||
values
|
values
|
||||||
<foreach collection="dynamicRuleObjects" item="object" separator=",">
|
<foreach collection="dynamicRuleObjects" item="object" separator=",">
|
||||||
@@ -56,18 +54,20 @@
|
|||||||
|
|
||||||
|
|
||||||
<!-- join删除-->
|
<!-- join删除-->
|
||||||
<!-- # delete t_dynamic_rule, t_protect_object_dynamic_rule_conn-->
|
<!-- # delete t_dynamic_rule, t_protect_object_dynamic_rule_conn-->
|
||||||
<!-- # from t_dynamic_rule-->
|
<!-- # from t_dynamic_rule-->
|
||||||
<!-- # inner join t_protect_object_dynamic_rule_conn-->
|
<!-- # inner join t_protect_object_dynamic_rule_conn-->
|
||||||
<!-- # on t_dynamic_rule.dynamic_rule_id = t_protect_object_dynamic_rule_conn.dynamic_rule_id-->
|
<!-- # on t_dynamic_rule.dynamic_rule_id = t_protect_object_dynamic_rule_conn.dynamic_rule_id-->
|
||||||
<!-- # where t_dynamic_rule.dynamic_rule_id = #{dynamicRuleId}-->
|
<!-- # where t_dynamic_rule.dynamic_rule_id = #{dynamicRuleId}-->
|
||||||
<delete id="deleteDynamicRuleObject">
|
<delete id="deleteDynamicRuleObject">
|
||||||
delete from t_dynamic_rule
|
delete
|
||||||
|
from t_dynamic_rule
|
||||||
where dynamic_rule_id = #{dynamicRuleId}
|
where dynamic_rule_id = #{dynamicRuleId}
|
||||||
</delete>
|
</delete>
|
||||||
<!-- 用于update时删去之前的关联-->
|
<!-- 用于update时删去之前的关联-->
|
||||||
<delete id="deleteDynamicRuleProtectObjectConcat">
|
<delete id="deleteDynamicRuleProtectObjectConcat">
|
||||||
delete from t_protect_object_dynamic_rule_conn
|
delete
|
||||||
|
from t_protect_object_dynamic_rule_conn
|
||||||
where dynamic_rule_id = #{dynamicRuleId}
|
where dynamic_rule_id = #{dynamicRuleId}
|
||||||
</delete>
|
</delete>
|
||||||
|
|
||||||
@@ -83,20 +83,25 @@
|
|||||||
<update id="updateDynamicRuleObject">
|
<update id="updateDynamicRuleObject">
|
||||||
update t_dynamic_rule
|
update t_dynamic_rule
|
||||||
set
|
set
|
||||||
<if test="object.dynamicRuleName != null"> dynamic_rule_name = #{object.dynamicRuleName},</if>
|
<if test="object.dynamicRuleName != null">dynamic_rule_name = #{object.dynamicRuleName},</if>
|
||||||
<if test="object.dynamicRuleModifyTime != null"> modify_time = #{object.dynamicRuleModifyTime},</if>
|
<if test="object.dynamicRuleModifyTime != null">modify_time = #{object.dynamicRuleModifyTime},</if>
|
||||||
<if test="object.dynamicRuleSourceSystem != null"> dynamic_rule_source_system = #{object.dynamicRuleSourceSystem},</if>
|
<if test="object.dynamicRuleSourceSystem != null">dynamic_rule_source_system =
|
||||||
<if test="object.dynamicRuleEventType != null"> dynamic_rule_event_type = #{object.dynamicRuleEventType},</if>
|
#{object.dynamicRuleSourceSystem},
|
||||||
<if test="object.dynamicRuleProtectLevel != null"> dynamic_rule_protec_level = #{object.dynamicRuleProtectLevel},</if>
|
</if>
|
||||||
<if test="object.dynamicRulePriority != null"> dynamic_rule_priority = #{object.dynamicRulePriority},</if>
|
<if test="object.dynamicRuleEventType != null">dynamic_rule_event_type = #{object.dynamicRuleEventType},</if>
|
||||||
<if test="object.dynamicRuleRange != null"> dynamic_rule_range = #{object.dynamicRuleRange},</if>
|
<if test="object.dynamicRuleProtectLevel != null">dynamic_rule_protec_level =
|
||||||
<if test="object.dynamicRuleFrequency != null"> dynamic_rule_frequency = #{object.dynamicRuleFrequency}</if>
|
#{object.dynamicRuleProtectLevel},
|
||||||
|
</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>
|
||||||
where
|
where
|
||||||
dynamic_rule_id = #{dynamicRuleId}
|
dynamic_rule_id = #{dynamicRuleId}
|
||||||
</update>
|
</update>
|
||||||
|
|
||||||
|
|
||||||
<resultMap id="dynamicRuleMap" type="com.realtime.protection.configuration.entity.rule.dynamicrule.DynamicRuleObject">
|
<resultMap id="dynamicRuleMap"
|
||||||
|
type="com.realtime.protection.configuration.entity.rule.dynamicrule.DynamicRuleObject">
|
||||||
<id column="dynamic_rule_id" property="dynamicRuleId"/>
|
<id column="dynamic_rule_id" property="dynamicRuleId"/>
|
||||||
<result column="dynamic_rule_name" property="dynamicRuleName"/>
|
<result column="dynamic_rule_name" property="dynamicRuleName"/>
|
||||||
<result column="create_time" property="dynamicRuleCreateTime"/>
|
<result column="create_time" property="dynamicRuleCreateTime"/>
|
||||||
@@ -114,7 +119,7 @@
|
|||||||
|
|
||||||
<select id="queryDynamicRuleById" resultMap="dynamicRuleMap">
|
<select id="queryDynamicRuleById" resultMap="dynamicRuleMap">
|
||||||
select *
|
select *
|
||||||
from t_dynamic_rule dynamicRule
|
from t_dynamic_rule dynamicRule
|
||||||
where dynamicRule.dynamic_rule_id = #{dynamicRuleId}
|
where dynamicRule.dynamic_rule_id = #{dynamicRuleId}
|
||||||
|
|
||||||
</select>
|
</select>
|
||||||
@@ -133,10 +138,10 @@
|
|||||||
<select id="queryProtectObjectByRuleId"
|
<select id="queryProtectObjectByRuleId"
|
||||||
resultMap="protectObjectMap">
|
resultMap="protectObjectMap">
|
||||||
select t_protect_object.*
|
select t_protect_object.*
|
||||||
from t_protect_object
|
from t_protect_object
|
||||||
inner join t_protect_object_dynamic_rule_conn
|
inner join t_protect_object_dynamic_rule_conn
|
||||||
on t_protect_object.protect_object_id = t_protect_object_dynamic_rule_conn.protect_object_id
|
on t_protect_object.protect_object_id = t_protect_object_dynamic_rule_conn.protect_object_id
|
||||||
where t_protect_object_dynamic_rule_conn.dynamic_rule_id = #{dynamicRuleId}
|
where t_protect_object_dynamic_rule_conn.dynamic_rule_id = #{dynamicRuleId}
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="queryDynamicRuleObject"
|
<select id="queryDynamicRuleObject"
|
||||||
|
|||||||
@@ -20,18 +20,18 @@
|
|||||||
|
|
||||||
<insert id="newProtectObjects" parameterType="List">
|
<insert id="newProtectObjects" parameterType="List">
|
||||||
INSERT INTO t_protect_object(protect_object_id, protect_object_name, protect_object_system_name,
|
INSERT INTO t_protect_object(protect_object_id, protect_object_name, protect_object_system_name,
|
||||||
protect_object_ip, protect_object_port, protect_object_url,
|
protect_object_ip, protect_object_port, protect_object_url,
|
||||||
protect_object_protocol,
|
protect_object_protocol,
|
||||||
protect_object_create_username, protect_object_create_depart,
|
protect_object_create_username, protect_object_create_depart,
|
||||||
protect_object_create_user_id)
|
protect_object_create_user_id)
|
||||||
VALUES
|
VALUES
|
||||||
<foreach collection="proobjs" item="proobj" separator=",">
|
<foreach collection="proobjs" item="proobj" separator=",">
|
||||||
(#{proobj.protectObjectId}, #{proobj.protectObjectName}, #{proobj.protectObjectSystemName},
|
(#{proobj.protectObjectId}, #{proobj.protectObjectName}, #{proobj.protectObjectSystemName},
|
||||||
INET_ATON(#{proobj.protectObjectIPAddress}), #{proobj.protectObjectPort}, #{proobj.protectObjectURL},
|
INET_ATON(#{proobj.protectObjectIPAddress}), #{proobj.protectObjectPort}, #{proobj.protectObjectURL},
|
||||||
#{proobj.protectObjectProtocol},
|
#{proobj.protectObjectProtocol},
|
||||||
#{proobj.protectObjectCreateUsername}, #{proobj.protectObjectCreateDepart},
|
#{proobj.protectObjectCreateUsername}, #{proobj.protectObjectCreateDepart},
|
||||||
#{proobj.protectObjectCreateUserId})
|
#{proobj.protectObjectCreateUserId})
|
||||||
</foreach>
|
</foreach>
|
||||||
</insert>
|
</insert>
|
||||||
|
|
||||||
<resultMap id="protectObjectMap" type="com.realtime.protection.configuration.entity.defense.object.ProtectObject">
|
<resultMap id="protectObjectMap" type="com.realtime.protection.configuration.entity.defense.object.ProtectObject">
|
||||||
@@ -55,7 +55,8 @@
|
|||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="queryProtectObject" resultMap="protectObjectMap">
|
<select id="queryProtectObject" resultMap="protectObjectMap">
|
||||||
SELECT * FROM t_protect_object
|
SELECT *
|
||||||
|
FROM t_protect_object
|
||||||
WHERE protect_object_id = #{proobj_id}
|
WHERE protect_object_id = #{proobj_id}
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
@@ -79,7 +80,8 @@
|
|||||||
</update>
|
</update>
|
||||||
|
|
||||||
<delete id="deleteProtectObject">
|
<delete id="deleteProtectObject">
|
||||||
DELETE FROM t_protect_object
|
DELETE
|
||||||
|
FROM t_protect_object
|
||||||
WHERE protect_object_id = #{proobj_id}
|
WHERE protect_object_id = #{proobj_id}
|
||||||
</delete>
|
</delete>
|
||||||
|
|
||||||
|
|||||||
@@ -26,13 +26,13 @@
|
|||||||
</insert>
|
</insert>
|
||||||
<insert id="newStaticRules">
|
<insert id="newStaticRules">
|
||||||
insert into t_static_rule(static_rule_name, static_rule_create_time,
|
insert into t_static_rule(static_rule_name, static_rule_create_time,
|
||||||
static_rule_create_username, static_rule_create_depart,
|
static_rule_create_username, static_rule_create_depart,
|
||||||
static_rule_create_user_id, static_rule_sip, static_rule_msip,
|
static_rule_create_user_id, static_rule_sip, static_rule_msip,
|
||||||
static_rule_sport, static_rule_msport,
|
static_rule_sport, static_rule_msport,
|
||||||
static_rule_dip, static_rule_mdip, static_rule_dport, static_rule_mdport,
|
static_rule_dip, static_rule_mdip, static_rule_dport, static_rule_mdport,
|
||||||
static_rule_protocol, static_rule_mprotocol, static_rule_dns,
|
static_rule_protocol, static_rule_mprotocol, static_rule_dns,
|
||||||
static_rule_url, static_rule_priority, static_rule_range,
|
static_rule_url, static_rule_priority, static_rule_range,
|
||||||
static_rule_frequency, static_rule_audit_status)
|
static_rule_frequency, static_rule_audit_status)
|
||||||
values
|
values
|
||||||
<foreach collection="staticRuleBatch" item="object" separator=",">
|
<foreach collection="staticRuleBatch" item="object" separator=",">
|
||||||
(#{object.staticRuleName}, #{object.staticRuleCreateTime}, #{object.staticRuleCreateUsername},
|
(#{object.staticRuleName}, #{object.staticRuleCreateTime}, #{object.staticRuleCreateUsername},
|
||||||
@@ -53,18 +53,18 @@
|
|||||||
<if test="staticRuleName != null and staticRuleName != ''">
|
<if test="staticRuleName != null and staticRuleName != ''">
|
||||||
static_rule_name = #{staticRuleName},
|
static_rule_name = #{staticRuleName},
|
||||||
</if>
|
</if>
|
||||||
static_rule_sip = INET_ATON(#{staticRuleSip}),
|
static_rule_sip = INET_ATON(#{staticRuleSip}),
|
||||||
static_rule_msip = INET_ATON(#{staticRuleMsip}),
|
static_rule_msip = INET_ATON(#{staticRuleMsip}),
|
||||||
static_rule_sport = #{staticRuleSport},
|
static_rule_sport = #{staticRuleSport},
|
||||||
static_rule_msport = #{staticRuleMsport},
|
static_rule_msport = #{staticRuleMsport},
|
||||||
static_rule_dip = INET_ATON(#{staticRuleDip}),
|
static_rule_dip = INET_ATON(#{staticRuleDip}),
|
||||||
static_rule_mdip = INET_ATON(#{staticRuleMdip}),
|
static_rule_mdip = INET_ATON(#{staticRuleMdip}),
|
||||||
static_rule_dport = #{staticRuleDport},
|
static_rule_dport = #{staticRuleDport},
|
||||||
static_rule_mdport = #{staticRuleMdport},
|
static_rule_mdport = #{staticRuleMdport},
|
||||||
static_rule_protocol = #{staticRuleProtocol},
|
static_rule_protocol = #{staticRuleProtocol},
|
||||||
static_rule_mprotocol = #{staticRuleMprotocol},
|
static_rule_mprotocol = #{staticRuleMprotocol},
|
||||||
static_rule_dns = #{staticRuleDns},
|
static_rule_dns = #{staticRuleDns},
|
||||||
static_rule_url = #{staticRuleURL},
|
static_rule_url = #{staticRuleURL},
|
||||||
<if test="staticRulePriority != null and staticRulePriority != ''">
|
<if test="staticRulePriority != null and staticRulePriority != ''">
|
||||||
static_rule_priority = #{staticRulePriority},
|
static_rule_priority = #{staticRulePriority},
|
||||||
</if>
|
</if>
|
||||||
@@ -98,7 +98,7 @@
|
|||||||
<result column="static_rule_protocol" property="staticRuleProtocol"/>
|
<result column="static_rule_protocol" property="staticRuleProtocol"/>
|
||||||
</resultMap>
|
</resultMap>
|
||||||
|
|
||||||
<select id="queryStaticRule" resultMap="staticRuleMap">
|
<select id="queryStaticRule" resultMap="staticRuleMap">
|
||||||
SELECT * FROM t_static_rule
|
SELECT * FROM t_static_rule
|
||||||
<where>
|
<where>
|
||||||
<if test="static_rule_name != null and static_rule_name != ''">
|
<if test="static_rule_name != null and static_rule_name != ''">
|
||||||
@@ -112,7 +112,8 @@
|
|||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="queryStaticRuleById" resultMap="staticRuleMap">
|
<select id="queryStaticRuleById" resultMap="staticRuleMap">
|
||||||
SELECT * FROM t_static_rule
|
SELECT *
|
||||||
|
FROM t_static_rule
|
||||||
WHERE static_rule_id = #{static_rule_id}
|
WHERE static_rule_id = #{static_rule_id}
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
|||||||
@@ -120,7 +120,8 @@
|
|||||||
|
|
||||||
<update id="clearTaskConnectedStaticRule">
|
<update id="clearTaskConnectedStaticRule">
|
||||||
UPDATE t_static_rule
|
UPDATE t_static_rule
|
||||||
SET static_rule_used_task_id = null, static_rule_modify_time = NOW()
|
SET static_rule_used_task_id = null,
|
||||||
|
static_rule_modify_time = NOW()
|
||||||
WHERE static_rule_used_task_id = #{task_id}
|
WHERE static_rule_used_task_id = #{task_id}
|
||||||
</update>
|
</update>
|
||||||
|
|
||||||
@@ -132,18 +133,21 @@
|
|||||||
|
|
||||||
<update id="changeTaskAuditStatus">
|
<update id="changeTaskAuditStatus">
|
||||||
UPDATE t_task
|
UPDATE t_task
|
||||||
SET task_audit_status = #{audit_status}, task_modify_time = NOW()
|
SET task_audit_status = #{audit_status},
|
||||||
|
task_modify_time = NOW()
|
||||||
WHERE task_id = #{task_id}
|
WHERE task_id = #{task_id}
|
||||||
</update>
|
</update>
|
||||||
|
|
||||||
<update id="changeTaskStatus">
|
<update id="changeTaskStatus">
|
||||||
UPDATE t_task
|
UPDATE t_task
|
||||||
SET task_status = #{state}, task_modify_time = NOW()
|
SET task_status = #{state},
|
||||||
|
task_modify_time = NOW()
|
||||||
WHERE task_id = #{task_id}
|
WHERE task_id = #{task_id}
|
||||||
</update>
|
</update>
|
||||||
|
|
||||||
<delete id="deleteTask">
|
<delete id="deleteTask">
|
||||||
DELETE FROM t_task
|
DELETE
|
||||||
|
FROM t_task
|
||||||
WHERE task_id = #{task_id}
|
WHERE task_id = #{task_id}
|
||||||
</delete>
|
</delete>
|
||||||
|
|
||||||
@@ -175,9 +179,9 @@
|
|||||||
t_task.task_act,
|
t_task.task_act,
|
||||||
t_task.task_start_time,
|
t_task.task_start_time,
|
||||||
t_task.task_end_time,
|
t_task.task_end_time,
|
||||||
INET_NTOA(tsr.static_rule_sip) as static_rule_sip,
|
INET_NTOA(tsr.static_rule_sip) as static_rule_sip,
|
||||||
tsr.static_rule_sport,
|
tsr.static_rule_sport,
|
||||||
INET_NTOA(tsr.static_rule_dip) as static_rule_dip,
|
INET_NTOA(tsr.static_rule_dip) as static_rule_dip,
|
||||||
tsr.static_rule_dport,
|
tsr.static_rule_dport,
|
||||||
tsr.static_rule_protocol,
|
tsr.static_rule_protocol,
|
||||||
INET_NTOA(tsr.static_rule_msip) as static_rule_msip,
|
INET_NTOA(tsr.static_rule_msip) as static_rule_msip,
|
||||||
@@ -187,6 +191,7 @@
|
|||||||
tsr.static_rule_frequency
|
tsr.static_rule_frequency
|
||||||
FROM t_task
|
FROM t_task
|
||||||
LEFT JOIN realtime_protection.t_static_rule tsr on t_task.task_id = tsr.static_rule_used_task_id
|
LEFT JOIN realtime_protection.t_static_rule tsr on t_task.task_id = tsr.static_rule_used_task_id
|
||||||
WHERE task_id = #{task_id} AND tsr.static_rule_audit_status = 2
|
WHERE task_id = #{task_id}
|
||||||
|
AND tsr.static_rule_audit_status = 2
|
||||||
</select>
|
</select>
|
||||||
</mapper>
|
</mapper>
|
||||||
@@ -93,6 +93,13 @@
|
|||||||
LIMIT ${(page - 1) * page_size}, #{page_size}
|
LIMIT ${(page - 1) * page_size}, #{page_size}
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
<select id="queryTemplate" resultMap="templateMap">
|
||||||
|
SELECT * FROM template_view
|
||||||
|
<where>
|
||||||
|
strategy_template_id = #{template_id}
|
||||||
|
</where>
|
||||||
|
</select>
|
||||||
|
|
||||||
<select id="queryProtectLevel" resultMap="protectLevelMap">
|
<select id="queryProtectLevel" resultMap="protectLevelMap">
|
||||||
SELECT *
|
SELECT *
|
||||||
FROM t_protect_level
|
FROM t_protect_level
|
||||||
|
|||||||
@@ -17,9 +17,9 @@
|
|||||||
|
|
||||||
<insert id="newWhiteListObjects">
|
<insert id="newWhiteListObjects">
|
||||||
insert into t_white_list(white_list_name, white_list_system_name,
|
insert into t_white_list(white_list_name, white_list_system_name,
|
||||||
white_list_ip, white_list_port,
|
white_list_ip, white_list_port,
|
||||||
white_list_url, white_list_protocol,
|
white_list_url, white_list_protocol,
|
||||||
white_list_audit_status)
|
white_list_audit_status)
|
||||||
values
|
values
|
||||||
<foreach collection="whiteListObjects" item="object" separator=",">
|
<foreach collection="whiteListObjects" item="object" separator=",">
|
||||||
(#{object.whiteListName}, #{object.whiteListSystemName},
|
(#{object.whiteListName}, #{object.whiteListSystemName},
|
||||||
@@ -46,7 +46,7 @@
|
|||||||
<result column="white_list_port" property="whiteListPort"/>
|
<result column="white_list_port" property="whiteListPort"/>
|
||||||
<result column="white_list_url" property="whiteListUrl"/>
|
<result column="white_list_url" property="whiteListUrl"/>
|
||||||
<result column="white_list_protocol" property="whiteListProtocol"/>
|
<result column="white_list_protocol" property="whiteListProtocol"/>
|
||||||
<!-- <result column="white_list_audit_status" property="whiteListAuditStatus"/>-->
|
<!-- <result column="white_list_audit_status" property="whiteListAuditStatus"/>-->
|
||||||
</resultMap>
|
</resultMap>
|
||||||
|
|
||||||
<select id="queryWhiteListObject" resultMap="whiteListMap">
|
<select id="queryWhiteListObject" resultMap="whiteListMap">
|
||||||
@@ -63,7 +63,8 @@
|
|||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="queryWhiteListObjectById" resultMap="whiteListMap">
|
<select id="queryWhiteListObjectById" resultMap="whiteListMap">
|
||||||
select * from t_white_list
|
select *
|
||||||
|
from t_white_list
|
||||||
where white_list_id = #{whiteListId}
|
where white_list_id = #{whiteListId}
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
@@ -139,27 +140,28 @@
|
|||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="queryWhiteListObjectAuditStuatusById" resultType="java.lang.Integer">
|
<select id="queryWhiteListObjectAuditStuatusById" resultType="java.lang.Integer">
|
||||||
select white_list_audit_status from t_white_list
|
select white_list_audit_status
|
||||||
|
from t_white_list
|
||||||
where white_list_id = #{id}
|
where white_list_id = #{id}
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
判断逻辑
|
判断逻辑
|
||||||
如果指令没有ip掩码:
|
如果指令没有ip掩码:
|
||||||
whitelist_ip == ip
|
whitelist_ip == ip
|
||||||
如果指令有端口:
|
如果指令有端口:
|
||||||
判断端口是否相同
|
判断端口是否相同
|
||||||
如果指令有ip掩码:
|
如果指令有ip掩码:
|
||||||
whitelist_ip & IP掩码 == 源IP & IP掩码 : 代表指令包含了whitelist_ip
|
whitelist_ip & IP掩码 == 源IP & IP掩码 : 代表指令包含了whitelist_ip
|
||||||
如果指令有端口:
|
如果指令有端口:
|
||||||
判断端口是否相同
|
判断端口是否相同
|
||||||
(又分了一下指令的源ip和目的ip)
|
(又分了一下指令的源ip和目的ip)
|
||||||
|
|
||||||
可能还要做的:
|
可能还要做的:
|
||||||
(1)端口掩码
|
(1)端口掩码
|
||||||
(2)协议
|
(2)协议
|
||||||
(3)url
|
(3)url
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<select id="whiteListCommandJudge" resultMap="whiteListMap">
|
<select id="whiteListCommandJudge" resultMap="whiteListMap">
|
||||||
select *
|
select *
|
||||||
|
|||||||
@@ -60,7 +60,8 @@ class ProtectObjectServiceTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void updateProtectObject() {
|
void updateProtectObject() {
|
||||||
Integer testId = 300;
|
List<ProtectObject> protectObjects = protectObjectService.queryProtectObjects(null, null, 1, 1);
|
||||||
|
Integer testId = protectObjects.get(0).getProtectObjectId();
|
||||||
|
|
||||||
protectObject.setProtectObjectName("x-1-1");
|
protectObject.setProtectObjectName("x-1-1");
|
||||||
protectObject.setProtectObjectId(testId);
|
protectObject.setProtectObjectId(testId);
|
||||||
@@ -71,7 +72,7 @@ class ProtectObjectServiceTest {
|
|||||||
@Test
|
@Test
|
||||||
void deleteProtectObject() {
|
void deleteProtectObject() {
|
||||||
int testNum = 0;
|
int testNum = 0;
|
||||||
for (int i = 0; i < 100000; i++ ) {
|
for (int i = 0; i < 100000; i++) {
|
||||||
if (protectObjectService.queryProtectObject(i) != null) {
|
if (protectObjectService.queryProtectObject(i) != null) {
|
||||||
testNum = i;
|
testNum = i;
|
||||||
break;
|
break;
|
||||||
@@ -84,7 +85,7 @@ class ProtectObjectServiceTest {
|
|||||||
@Test
|
@Test
|
||||||
void deleteProtectObjects() {
|
void deleteProtectObjects() {
|
||||||
ArrayList<Integer> testNums = new ArrayList<>();
|
ArrayList<Integer> testNums = new ArrayList<>();
|
||||||
for (int i = 0; i < 100000; i++ ) {
|
for (int i = 0; i < 100000; i++) {
|
||||||
if (protectObjectService.queryProtectObject(i) != null) {
|
if (protectObjectService.queryProtectObject(i) != null) {
|
||||||
testNums.add(i);
|
testNums.add(i);
|
||||||
if (testNums.size() > 5) {
|
if (testNums.size() > 5) {
|
||||||
@@ -102,7 +103,7 @@ class ProtectObjectServiceTest {
|
|||||||
@Test
|
@Test
|
||||||
void changeProtectObjectAuditStatus() {
|
void changeProtectObjectAuditStatus() {
|
||||||
int testNum = 0;
|
int testNum = 0;
|
||||||
for (int i = 300; i < 100000; i++ ) {
|
for (int i = 300; i < 100000; i++) {
|
||||||
if (protectObjectService.queryProtectObject(i) != null) {
|
if (protectObjectService.queryProtectObject(i) != null) {
|
||||||
testNum = i;
|
testNum = i;
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -7,7 +7,9 @@ import org.junit.jupiter.api.BeforeEach;
|
|||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
import org.springframework.dao.DuplicateKeyException;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
@@ -57,8 +59,24 @@ class TemplateServiceTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testNewTemplate() {
|
void testNewTemplate() {
|
||||||
Integer templateId = templateService.newTemplate(template);
|
try {
|
||||||
assertTrue(templateId > 0);
|
Integer templateId = templateService.newTemplate(template);
|
||||||
|
assertTrue(templateId > 0);
|
||||||
|
} catch (DuplicateKeyException e) {
|
||||||
|
System.out.println(e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < 100; 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);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -74,9 +92,9 @@ class TemplateServiceTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testUpdateTemplateSuccess() {
|
void testUpdateTemplateSuccess() {
|
||||||
List<Template> templates = templateService.queryTemplates("反射", 1, 6);
|
List<Template> templates = templateService.queryTemplates("DDOS", 1, 1);
|
||||||
Template testTemplate = templates.get(0);
|
Template testTemplate = templates.get(0);
|
||||||
testTemplate.setTemplateName("洪泛型DDOS攻击");
|
testTemplate.setTemplateName("洪泛型DDOS攻击-"+LocalDateTime.now());
|
||||||
|
|
||||||
assertTrue(templateService.updateTemplate(testTemplate.getTemplateId(), testTemplate));
|
assertTrue(templateService.updateTemplate(testTemplate.getTemplateId(), testTemplate));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import org.junit.jupiter.api.BeforeEach;
|
|||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
import org.springframework.dao.DataIntegrityViolationException;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -57,7 +58,7 @@ class TaskServiceTest {
|
|||||||
@Test
|
@Test
|
||||||
void testNewTaskLostData() {
|
void testNewTaskLostData() {
|
||||||
this.task.setTaskStartTime(null);
|
this.task.setTaskStartTime(null);
|
||||||
assertThrows(PersistenceException.class, () -> {
|
assertThrows(DataIntegrityViolationException.class, () -> {
|
||||||
Long taskId = taskService.newTask(task);
|
Long taskId = taskService.newTask(task);
|
||||||
assertTrue(taskId > 0);
|
assertTrue(taskId > 0);
|
||||||
});
|
});
|
||||||
@@ -101,7 +102,7 @@ class TaskServiceTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testGetStaticCommands() {
|
void testGetStaticCommands() {
|
||||||
List<TaskCommandInfo> taskCommandInfos = taskService.getStaticCommandInfos(26L);
|
List<TaskCommandInfo> taskCommandInfos = taskService.getStaticCommandInfos(38L);
|
||||||
assertEquals(3, taskCommandInfos.size());
|
assertNotNull(taskCommandInfos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -21,7 +21,6 @@ class CommandServiceTest {
|
|||||||
|
|
||||||
private final CommandService commandService;
|
private final CommandService commandService;
|
||||||
private TaskCommandInfo taskCommandInfo;
|
private TaskCommandInfo taskCommandInfo;
|
||||||
private Command command;
|
|
||||||
|
|
||||||
private Long startTime;
|
private Long startTime;
|
||||||
|
|
||||||
|
|||||||
@@ -1,43 +0,0 @@
|
|||||||
package com.realtime.protection.server.user.login;
|
|
||||||
|
|
||||||
import com.realtime.protection.configuration.entity.user.User;
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
|
||||||
|
|
||||||
import javax.security.auth.login.LoginException;
|
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
|
||||||
|
|
||||||
@SpringBootTest
|
|
||||||
class LoginServiceTest {
|
|
||||||
|
|
||||||
private final LoginService loginService;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
LoginServiceTest(LoginService loginService) {
|
|
||||||
this.loginService = loginService;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void testLoginFail() {
|
|
||||||
User user = new User();
|
|
||||||
user.setPassword("12345");
|
|
||||||
user.setUsername("endera");
|
|
||||||
|
|
||||||
assertThrows(LoginException.class, () -> loginService.login(user));
|
|
||||||
|
|
||||||
user.setUsername("");
|
|
||||||
user.setPassword("");
|
|
||||||
assertThrows(LoginException.class, () -> loginService.login(user));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void testLoginSuccess() {
|
|
||||||
User user = new User();
|
|
||||||
user.setUsername("endera");
|
|
||||||
user.setPassword("123456");
|
|
||||||
|
|
||||||
assertDoesNotThrow(() -> assertEquals(1, loginService.login(user)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -73,15 +73,4 @@ class WhiteListServiceTest {
|
|||||||
whiteListService.updateWhiteListObjectAuditStatus(7, 1);
|
whiteListService.updateWhiteListObjectAuditStatus(7, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
void testWhiteListCommandJudge() {
|
|
||||||
Command command = new Command();
|
|
||||||
command.setDestinationIP("128.1.1.123");
|
|
||||||
command.setMaskDestinationIP("255.255.255.0");
|
|
||||||
command.setDestinationPort("81");
|
|
||||||
|
|
||||||
List<WhiteListObject> whitelists = whiteListService.whiteListCommandJudge(command);
|
|
||||||
System.out.println(whitelists);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user