diff --git a/src/main/java/com/realtime/protection/ProtectionApplication.java b/src/main/java/com/realtime/protection/ProtectionApplication.java index 4effcda..c54ab37 100644 --- a/src/main/java/com/realtime/protection/ProtectionApplication.java +++ b/src/main/java/com/realtime/protection/ProtectionApplication.java @@ -1,5 +1,6 @@ package com.realtime.protection; +import org.mybatis.spring.annotation.MapperScan; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; diff --git a/src/main/java/com/realtime/protection/configuration/entity/defense/template/Template.java b/src/main/java/com/realtime/protection/configuration/entity/defense/template/Template.java index 80dd2ee..91f832a 100644 --- a/src/main/java/com/realtime/protection/configuration/entity/defense/template/Template.java +++ b/src/main/java/com/realtime/protection/configuration/entity/defense/template/Template.java @@ -20,17 +20,23 @@ public class Template { @NotNull(message = "default_op should not be empty") private String defaultOp; - private boolean hasProtectObjectIP; + @JsonProperty("template_running_tasks") + private Integer templateRunningTasks; - private boolean hasProtectObjectPort; + @JsonProperty("template_used") + private Integer templateUsedTimes; - private boolean hasPeerIP; + private Boolean hasProtectObjectIP; - private boolean hasPeerPort; + private Boolean hasProtectObjectPort; - private boolean hasProtocol; + private Boolean hasPeerIP; - private boolean hasURL; + private Boolean hasPeerPort; - private boolean hasDNS; + private Boolean hasProtocol; + + private Boolean hasURL; + + private Boolean hasDNS; } diff --git a/src/main/java/com/realtime/protection/configuration/entity/task/Task.java b/src/main/java/com/realtime/protection/configuration/entity/task/Task.java index 6952169..ea5fd00 100644 --- a/src/main/java/com/realtime/protection/configuration/entity/task/Task.java +++ b/src/main/java/com/realtime/protection/configuration/entity/task/Task.java @@ -5,6 +5,7 @@ import jakarta.validation.constraints.NotNull; import lombok.Data; import java.time.LocalDateTime; +import java.util.List; @Data public class Task { @@ -53,13 +54,13 @@ public class Task { // ----------------------------------------------------------- @JsonProperty("static_rule_ids") - private Integer[] staticRuleIds; + private List staticRuleIds; @JsonProperty("dynamic_rule_ids") - private Integer[] dynamicRuleIds; + private List dynamicRuleIds; @JsonProperty("protect_object_ids") - private Integer[] protectObjectIds; + private List protectObjectIds; @JsonProperty("task_status") private Integer taskStatus; diff --git a/src/main/java/com/realtime/protection/configuration/exception/GlobalExceptionHandler.java b/src/main/java/com/realtime/protection/configuration/exception/GlobalExceptionHandler.java index 26ecf6a..77ceb74 100644 --- a/src/main/java/com/realtime/protection/configuration/exception/GlobalExceptionHandler.java +++ b/src/main/java/com/realtime/protection/configuration/exception/GlobalExceptionHandler.java @@ -1,7 +1,9 @@ package com.realtime.protection.configuration.exception; import cn.dev33.satoken.exception.NotLoginException; +import cn.dev33.satoken.exception.SaTokenException; import com.realtime.protection.configuration.response.ResponseResult; +import io.swagger.v3.oas.annotations.ExternalDocumentation; import org.apache.ibatis.exceptions.PersistenceException; import org.springframework.context.support.DefaultMessageSourceResolvable; import org.springframework.core.annotation.Order; @@ -24,26 +26,30 @@ public class GlobalExceptionHandler { @ExceptionHandler(value = NotLoginException.class) public ResponseResult handleNotLoginException(NotLoginException e) { return new ResponseResult( - 400, + 401, e.getMessage() ); } @Order(2) @ExceptionHandler(value = PersistenceException.class) - public ResponseResult handleSQLException() { - return new ResponseResult( - 400, + public ResponseResult handleSQLException(PersistenceException e) { + return ResponseResult.invalid().setMessage( "please check the integrity of the data. check if the json data exists in the database"); } @Order(2) @ExceptionHandler(value = MethodArgumentNotValidException.class) public ResponseResult handleBindException(MethodArgumentNotValidException e) { - return new ResponseResult( - 400, + return ResponseResult.invalid().setMessage( e.getBindingResult().getAllErrors().stream() .map(DefaultMessageSourceResolvable::getDefaultMessage).collect(Collectors.joining()) ); } + + @Order(2) + @ExceptionHandler(value = SaTokenException.class) + public ResponseResult handleSaTokenException(SaTokenException e) { + return ResponseResult.unAuthorized().setMessage(e.getMessage()); + } } diff --git a/src/main/java/com/realtime/protection/configuration/response/ResponseResult.java b/src/main/java/com/realtime/protection/configuration/response/ResponseResult.java index ed0f742..e327b99 100644 --- a/src/main/java/com/realtime/protection/configuration/response/ResponseResult.java +++ b/src/main/java/com/realtime/protection/configuration/response/ResponseResult.java @@ -30,7 +30,7 @@ public class ResponseResult implements Serializable { } public static ResponseResult ok() { - return new ResponseResult(200, "request succeeded"); + return new ResponseResult(200, "request succeed"); } public static ResponseResult ok(String message) { @@ -41,6 +41,14 @@ public class ResponseResult implements Serializable { return new ResponseResult(500, "request failed"); } + public static ResponseResult invalid() { + return new ResponseResult(400, "invalid request"); + } + + public static ResponseResult unAuthorized() { + return new ResponseResult(401, "UnAuthorized User"); + } + public static ResponseResult error(String message) { return new ResponseResult(500, message); } diff --git a/src/main/java/com/realtime/protection/server/defense/template/TemplateController.java b/src/main/java/com/realtime/protection/server/defense/template/TemplateController.java index c843abb..d9a789b 100644 --- a/src/main/java/com/realtime/protection/server/defense/template/TemplateController.java +++ b/src/main/java/com/realtime/protection/server/defense/template/TemplateController.java @@ -3,10 +3,9 @@ package com.realtime.protection.server.defense.template; import com.realtime.protection.configuration.entity.defense.template.Template; import com.realtime.protection.configuration.response.ResponseResult; import jakarta.validation.Valid; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; + +import java.util.List; @RestController @RequestMapping("/deftac") @@ -40,4 +39,18 @@ public class TemplateController { .setData("template_id", null) .setData("success", false); } + + @GetMapping("/query") + public ResponseResult queryTemplate(@RequestParam(value = "template_name", required = false) String templateName, + @RequestParam("page") Integer page, + @RequestParam("page_size") Integer pageSize) { + if (page <= 0 || pageSize <= 0) { + return ResponseResult.invalid() + .setData("template_list", null); + } + List