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"
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -14,10 +14,13 @@ 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);
|
||||||
|
|||||||
@@ -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,7 +19,8 @@
|
|||||||
</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_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
|
values
|
||||||
@@ -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>
|
||||||
|
|||||||
@@ -15,8 +15,7 @@
|
|||||||
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},
|
||||||
@@ -28,8 +27,7 @@
|
|||||||
</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">
|
||||||
@@ -62,12 +60,14 @@
|
|||||||
<!-- # 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>
|
||||||
|
|
||||||
@@ -85,9 +85,13 @@
|
|||||||
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 =
|
||||||
|
#{object.dynamicRuleSourceSystem},
|
||||||
|
</if>
|
||||||
<if test="object.dynamicRuleEventType != null">dynamic_rule_event_type = #{object.dynamicRuleEventType},</if>
|
<if test="object.dynamicRuleEventType != null">dynamic_rule_event_type = #{object.dynamicRuleEventType},</if>
|
||||||
<if test="object.dynamicRuleProtectLevel != null"> dynamic_rule_protec_level = #{object.dynamicRuleProtectLevel},</if>
|
<if test="object.dynamicRuleProtectLevel != null">dynamic_rule_protec_level =
|
||||||
|
#{object.dynamicRuleProtectLevel},
|
||||||
|
</if>
|
||||||
<if test="object.dynamicRulePriority != null">dynamic_rule_priority = #{object.dynamicRulePriority},</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.dynamicRuleRange != null">dynamic_rule_range = #{object.dynamicRuleRange},</if>
|
||||||
<if test="object.dynamicRuleFrequency != null">dynamic_rule_frequency = #{object.dynamicRuleFrequency}</if>
|
<if test="object.dynamicRuleFrequency != null">dynamic_rule_frequency = #{object.dynamicRuleFrequency}</if>
|
||||||
@@ -96,7 +100,8 @@
|
|||||||
</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"/>
|
||||||
|
|||||||
@@ -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>
|
||||||
|
|
||||||
|
|||||||
@@ -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>
|
||||||
|
|
||||||
@@ -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
|
||||||
|
|||||||
@@ -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,7 +140,8 @@
|
|||||||
</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>
|
||||||
|
|
||||||
|
|||||||
@@ -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);
|
||||||
|
|||||||
@@ -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() {
|
||||||
|
try {
|
||||||
Integer templateId = templateService.newTemplate(template);
|
Integer templateId = templateService.newTemplate(template);
|
||||||
assertTrue(templateId > 0);
|
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