Merge remote-tracking branch 'origin/master'

This commit is contained in:
Hao Miao
2024-01-04 17:05:48 +08:00
16 changed files with 342 additions and 73 deletions

View File

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

View File

@@ -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<Integer> staticRuleIds;
@JsonProperty("dynamic_rule_ids")
private Integer[] dynamicRuleIds;
private List<Integer> dynamicRuleIds;
@JsonProperty("protect_object_ids")
private Integer[] protectObjectIds;
private List<Integer> protectObjectIds;
@JsonProperty("task_status")
private Integer taskStatus;

View File

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

View File

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