1. 添加部分swagger文档
This commit is contained in:
@@ -3,6 +3,7 @@ package com.realtime.protection.configuration.entity.defense.object;
|
||||
import com.alibaba.excel.annotation.ExcelIgnore;
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.Max;
|
||||
import jakarta.validation.constraints.Min;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
@@ -13,20 +14,24 @@ import lombok.Data;
|
||||
public class ProtectObject {
|
||||
@JsonProperty("proobj_id")
|
||||
@ExcelIgnore
|
||||
@Schema(description = "防护对象ID", accessMode = Schema.AccessMode.READ_ONLY)
|
||||
private Integer protectObjectId;
|
||||
|
||||
@JsonProperty("proobj_name")
|
||||
@NotNull(message = "proobj_name should not be empty.")
|
||||
@ExcelProperty("名称")
|
||||
@Schema(description = "防护对象名称", example = "静态对象测试")
|
||||
private String protectObjectName;
|
||||
|
||||
@JsonProperty("proobj_system_name")
|
||||
@ExcelProperty("操作系统名称")
|
||||
@Schema(description = "防护对象操作系统名称", example = "xxx操作系统")
|
||||
private String protectObjectSystemName;
|
||||
|
||||
@JsonProperty("proobj_ip_address")
|
||||
@Pattern(regexp = "^(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})$", message = "Invalid IPv4 Address")
|
||||
@ExcelProperty("IP地址")
|
||||
@Schema(description = "防护对象IPv4地址", example = "192.168.0.1")
|
||||
private String protectObjectIPAddress;
|
||||
|
||||
@JsonProperty("proobj_port")
|
||||
@@ -34,31 +39,38 @@ public class ProtectObject {
|
||||
@Max(value = 65535, message = "port should not be more than 65535")
|
||||
@Min(value = 1, message = "port should not be less than 1")
|
||||
@ExcelProperty("端口")
|
||||
@Schema(description = "防护对象端口", maximum = "65535", minimum = "1", example = "8080")
|
||||
private Integer protectObjectPort;
|
||||
|
||||
@JsonProperty("proobj_url")
|
||||
@NotNull(message = "proobj_url should not be empty.")
|
||||
@ExcelProperty("URL")
|
||||
@Schema(description = "防护对象URL", example = "alice.bob.com")
|
||||
private String protectObjectURL;
|
||||
|
||||
@JsonProperty("proobj_protocol")
|
||||
@NotNull(message = "proobj_protocol should not be empty.")
|
||||
@ExcelProperty("协议")
|
||||
@Schema(description = "防护对象网络协议(目前仅可以填写TCP或UDP)", example = "TCP")
|
||||
private String protectObjectProtocol;
|
||||
|
||||
@JsonProperty("proobj_audit_status")
|
||||
@ExcelIgnore
|
||||
@Schema(description = "防护对象审核状态(0为未审核,1为已退回,2为审核通过)", example = "2")
|
||||
private Integer protectObjectAuditStatus;
|
||||
|
||||
@JsonProperty("proobj_create_username")
|
||||
@ExcelIgnore
|
||||
@Schema(description = "防护对象创建人", example = "xxx", accessMode = Schema.AccessMode.READ_ONLY)
|
||||
private String protectObjectCreateUsername;
|
||||
|
||||
@JsonProperty("proobj_create_depart")
|
||||
@ExcelIgnore
|
||||
@Schema(description = "防护对象创建人处室", example = "xxx", accessMode = Schema.AccessMode.READ_ONLY)
|
||||
private String protectObjectCreateDepart;
|
||||
|
||||
@JsonProperty("proobj_create_userid")
|
||||
@ExcelIgnore
|
||||
@Schema(description = "防护对象创建人ID", example = "0", accessMode = Schema.AccessMode.READ_ONLY)
|
||||
private Integer protectObjectCreateUserId;
|
||||
}
|
||||
|
||||
@@ -1,22 +1,31 @@
|
||||
package com.realtime.protection.configuration.entity.defense.template;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class ProtectLevel {
|
||||
@Schema(description = "防护等级ID", accessMode = Schema.AccessMode.READ_ONLY)
|
||||
private Integer protectLevelId;
|
||||
|
||||
@Schema(description = "该防护等级是否需要提取防护对象IP地址字段")
|
||||
private Boolean hasProtectObjectIP = false;
|
||||
|
||||
@Schema(description = "该防护等级是否需要提取防护对象端口字段")
|
||||
private Boolean hasProtectObjectPort = false;
|
||||
|
||||
@Schema(description = "该防护等级是否需要提取对端IP地址字段")
|
||||
private Boolean hasPeerIP = false;
|
||||
|
||||
@Schema(description = "该防护等级是否需要提取对端端口字段")
|
||||
private Boolean hasPeerPort = false;
|
||||
|
||||
@Schema(description = "该防护等级是否需要提取网络协议字段")
|
||||
private Boolean hasProtocol = false;
|
||||
|
||||
@Schema(description = "该防护等级是否需要提取URL字段")
|
||||
private Boolean hasURL = false;
|
||||
|
||||
@Schema(description = "该防护等级是否需要提取DNS")
|
||||
private Boolean hasDNS = false;
|
||||
}
|
||||
|
||||
@@ -1,49 +1,58 @@
|
||||
package com.realtime.protection.configuration.entity.defense.template;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class Template {
|
||||
@JsonProperty("template_id")
|
||||
@Schema(description = "防御策略模板ID", example = "2", accessMode = Schema.AccessMode.READ_ONLY)
|
||||
private Integer templateId;
|
||||
|
||||
@JsonProperty("template_name")
|
||||
@NotNull(message = "template name should not be empty.")
|
||||
@Schema(description = "防御策略模板名称", example = "自定义模板")
|
||||
private String templateName;
|
||||
|
||||
@JsonProperty("template_running_tasks")
|
||||
private Integer templateRunningTasks;
|
||||
|
||||
@JsonProperty("template_used")
|
||||
private Integer templateUsedTimes;
|
||||
|
||||
@JsonProperty("source_system")
|
||||
@NotNull(message = "source_system should not be empty. ")
|
||||
@Schema(description = "防御策略模板数据来源系统", example = "BW系统")
|
||||
private String sourceSystem;
|
||||
|
||||
@JsonProperty("protect_level_low")
|
||||
@NotNull(message = "protect_level_low should not be empty. ")
|
||||
@Schema(description = "防御策略模板日常态字段提取选项")
|
||||
private ProtectLevel protectLevelLow;
|
||||
|
||||
@JsonProperty("protect_level_medium")
|
||||
@NotNull(message = "protect_level_medium should not be empty. ")
|
||||
@Schema(description = "防御策略模板应急态字段提取选项")
|
||||
private ProtectLevel protectLevelMedium;
|
||||
|
||||
@JsonProperty("protect_level_high")
|
||||
@NotNull(message = "protect_level_high should not be empty. ")
|
||||
@Schema(description = "防御策略模板紧急态字段提取选项")
|
||||
private ProtectLevel protectLevelHigh;
|
||||
|
||||
@JsonProperty("template_used_times")
|
||||
@Schema(description = "防御策略模板使用次数", example = "20", accessMode = Schema.AccessMode.READ_ONLY)
|
||||
private Integer usedTimes;
|
||||
|
||||
@JsonProperty("running_tasks")
|
||||
@Schema(description = "防御策略模板已运行的任务数量", example = "30", accessMode = Schema.AccessMode.READ_ONLY)
|
||||
private Integer runningTasks;
|
||||
|
||||
@JsonProperty("create_user_id")
|
||||
@Schema(description = "防御策略模板创建人ID", example = "1", accessMode = Schema.AccessMode.READ_ONLY)
|
||||
private Integer createUserId;
|
||||
|
||||
@JsonProperty("create_user_name")
|
||||
@Schema(description = "防御策略模板创建人名称", example = "xxx", accessMode = Schema.AccessMode.READ_ONLY)
|
||||
private String createUsername;
|
||||
|
||||
@JsonProperty("create_user_depart")
|
||||
@Schema(description = "防御策略模板创建人处室", example = "xxx", accessMode = Schema.AccessMode.READ_ONLY)
|
||||
private String createDepart;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package com.realtime.protection.configuration.entity.task;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.Future;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
@@ -9,56 +11,72 @@ import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@Schema(description = "一个任务对象包含的所有信息")
|
||||
public class Task {
|
||||
@JsonProperty("task_id")
|
||||
@Schema(description = "任务ID", accessMode = Schema.AccessMode.READ_ONLY)
|
||||
private Long taskId;
|
||||
|
||||
@JsonProperty("task_name")
|
||||
@NotNull(message = "task_name should not be empty. ")
|
||||
@Schema(description = "任务名称", example = "静态任务")
|
||||
private String taskName;
|
||||
|
||||
@JsonProperty("task_start_time")
|
||||
@NotNull(message = "task_start_time should not be empty. ")
|
||||
@Future(message = "task_start_time should be a future time")
|
||||
@Schema(description = "任务开始时间,必须晚于当前时间", example = "2024-10-23T00:00:00")
|
||||
private LocalDateTime taskStartTime;
|
||||
|
||||
@JsonProperty("task_end_time")
|
||||
@NotNull(message = "task_end_time should not be empty. ")
|
||||
@Future(message = "task_end_time should be a future time. ")
|
||||
@Schema(description = "任务结束时间,必须晚于开始时间", example = "2024-10-24T00:00:00")
|
||||
private LocalDateTime taskEndTime;
|
||||
|
||||
@JsonProperty("task_create_time")
|
||||
@Schema(hidden = true)
|
||||
private LocalDateTime taskCreateTime;
|
||||
|
||||
@JsonProperty("task_modify_time")
|
||||
@Schema(hidden = true)
|
||||
private LocalDateTime taskModifyTime;
|
||||
|
||||
@JsonProperty("task_type")
|
||||
@NotNull(message = "task_type should not be empty. ")
|
||||
@Schema(description = "任务类型,1为静态任务,2为实时任务,3为研判后任务", example = "1")
|
||||
private Integer taskType;
|
||||
|
||||
@JsonProperty("task_act")
|
||||
@NotNull(message = "task_act should not be empty. ")
|
||||
@Schema(description = "任务行为,目前只能为【阻断】", example = "阻断")
|
||||
private String taskAct;
|
||||
|
||||
@JsonProperty("task_create_username")
|
||||
@Schema(hidden = true)
|
||||
private String taskCreateUsername;
|
||||
|
||||
@JsonProperty("task_create_depart")
|
||||
@Schema(hidden = true)
|
||||
private String taskCreateDepart;
|
||||
|
||||
@JsonProperty("task_create_userid")
|
||||
@Schema(hidden = true)
|
||||
private Long taskCreateUserId;
|
||||
|
||||
@JsonProperty("static_rule_ids")
|
||||
@Schema(description = "静态规则ID列表,动态和静态至少存在1个规则", example = "[10, 12]")
|
||||
private List<Long> staticRuleIds;
|
||||
|
||||
@JsonProperty("dynamic_rule_ids")
|
||||
@Schema(description = "动态规则ID列表,动态和静态至少存在1个规则", example = "[20, 30]")
|
||||
private List<Long> dynamicRuleIds;
|
||||
|
||||
@JsonProperty("task_status")
|
||||
@Schema(description = "任务状态(0为未启动,1为生成中,2为运行中,3为暂停中,4为已停止,5为已结束,6为失败)", accessMode = Schema.AccessMode.READ_ONLY)
|
||||
private Integer taskStatus;
|
||||
|
||||
@JsonProperty("task_audit_status")
|
||||
@Schema(description = "任务审核状态(0为未审核,1为已退回,2为已通过)", accessMode = Schema.AccessMode.READ_ONLY)
|
||||
private Integer taskAuditStatus;
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import cn.dev33.satoken.exception.SaTokenException;
|
||||
import com.realtime.protection.configuration.response.ResponseResult;
|
||||
import com.realtime.protection.configuration.utils.enums.StateEnum;
|
||||
import com.realtime.protection.server.task.status.StateChangeService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.ibatis.exceptions.PersistenceException;
|
||||
import org.springframework.context.support.DefaultMessageSourceResolvable;
|
||||
import org.springframework.core.annotation.Order;
|
||||
@@ -16,6 +17,7 @@ import org.springframework.web.method.annotation.HandlerMethodValidationExceptio
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@RestControllerAdvice
|
||||
@Slf4j
|
||||
public class GlobalExceptionHandler {
|
||||
|
||||
private final StateChangeService stateChangeService;
|
||||
@@ -27,6 +29,7 @@ public class GlobalExceptionHandler {
|
||||
@Order(3)
|
||||
@ExceptionHandler(value = Exception.class)
|
||||
public ResponseResult handleGlobalException(Exception e) {
|
||||
log.error("meets global exception: " + e.getMessage());
|
||||
return ResponseResult.error().setMessage(e.getMessage());
|
||||
}
|
||||
|
||||
@@ -34,6 +37,7 @@ public class GlobalExceptionHandler {
|
||||
@Order(2)
|
||||
@ExceptionHandler(value = PersistenceException.class)
|
||||
public ResponseResult handleSQLException(PersistenceException e) {
|
||||
log.error("meets database exception: " + e.getMessage());
|
||||
return ResponseResult.invalid().setMessage(
|
||||
"please check the integrity of the data. check if the json data exists in the database");
|
||||
}
|
||||
@@ -41,6 +45,7 @@ public class GlobalExceptionHandler {
|
||||
@Order(2)
|
||||
@ExceptionHandler(value = MethodArgumentNotValidException.class)
|
||||
public ResponseResult handleBindException(MethodArgumentNotValidException e) {
|
||||
log.debug("meets data bind exception: " + e.getMessage());
|
||||
return ResponseResult.invalid().setMessage(
|
||||
e.getBindingResult().getAllErrors().stream()
|
||||
.map(DefaultMessageSourceResolvable::getDefaultMessage).collect(Collectors.joining())
|
||||
@@ -54,12 +59,14 @@ public class GlobalExceptionHandler {
|
||||
IllegalStateException.class
|
||||
})
|
||||
public ResponseResult handleHandlerMethodValidationException(Exception e) {
|
||||
log.debug("meets illegal argument exception: " + e.getMessage());
|
||||
return ResponseResult.invalid().setMessage(e.getMessage());
|
||||
}
|
||||
|
||||
@Order(2)
|
||||
@ExceptionHandler(value = NotLoginException.class)
|
||||
public ResponseResult handleNotLoginException(NotLoginException e) {
|
||||
log.debug("meets not login exception, login type: " + e.getLoginType());
|
||||
return new ResponseResult(
|
||||
401,
|
||||
e.getMessage()
|
||||
@@ -69,12 +76,14 @@ public class GlobalExceptionHandler {
|
||||
@Order(2)
|
||||
@ExceptionHandler(value = SaTokenException.class)
|
||||
public ResponseResult handleSaTokenException(SaTokenException e) {
|
||||
log.debug("sa-token meets exception: " + e.getMessage());
|
||||
return ResponseResult.unAuthorized().setMessage(e.getMessage());
|
||||
}
|
||||
|
||||
@Order(2)
|
||||
@ExceptionHandler(value = DorisStartException.class)
|
||||
public ResponseResult handleDorisStartException(DorisStartException e) {
|
||||
log.warn("doris database meets exception: " + e.getMessage());
|
||||
ResponseResult responseResult = ResponseResult.error()
|
||||
.setMessage("Doris command creation meets error: " + e.getMessage());
|
||||
|
||||
@@ -84,6 +93,7 @@ public class GlobalExceptionHandler {
|
||||
responseResult.setAnother(ResponseResult.error().setMessage(e.getMessage()));
|
||||
}
|
||||
|
||||
log.error(responseResult.getMessage());
|
||||
return responseResult;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.realtime.protection.configuration.response;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
@@ -7,11 +8,19 @@ import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Data
|
||||
@Schema(name = "通用返回对象", description = "用于所有接口返回的通用返回对象")
|
||||
public class ResponseResult implements Serializable {
|
||||
|
||||
@Schema(description = "状态码")
|
||||
private int code;
|
||||
|
||||
@Schema(description = "返回信息")
|
||||
private String message;
|
||||
|
||||
@Schema(description = "封装数据")
|
||||
private Map<String, Object> data;
|
||||
|
||||
@Schema(description = "返回对象链接的另外一个返回对象")
|
||||
private ResponseResult another;
|
||||
|
||||
public ResponseResult(int code, String message, LinkedHashMap<String, Object> data) {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.realtime.protection.configuration.satoken.role;
|
||||
|
||||
public enum Admin implements Role {
|
||||
ADMIN
|
||||
public enum User implements Role {
|
||||
ADMIN,
|
||||
NORMAL
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.realtime.protection.configuration.swagger;
|
||||
|
||||
import io.swagger.v3.oas.annotations.OpenAPIDefinition;
|
||||
import io.swagger.v3.oas.annotations.info.Contact;
|
||||
import io.swagger.v3.oas.annotations.info.Info;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@OpenAPIDefinition(
|
||||
info = @Info(
|
||||
title = "实时方宇项目",
|
||||
version = "1.0",
|
||||
description = "实时方宇项目——前端接口文档",
|
||||
contact = @Contact(name = "陈松岳", email = "chensongyue@iie.ac.cn")
|
||||
)
|
||||
)
|
||||
public class SwaggerConfiguration {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package com.realtime.protection.configuration.threadpool;
|
||||
|
||||
import com.realtime.protection.configuration.exception.DorisStartException;
|
||||
import com.realtime.protection.configuration.exception.GlobalExceptionHandler;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler;
|
||||
import org.springframework.scheduling.annotation.AsyncConfigurer;
|
||||
import org.springframework.scheduling.annotation.EnableAsync;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
@EnableAsync
|
||||
public class OverrideDefaultThreadPoolConfig implements AsyncConfigurer {
|
||||
private final TaskThreadPoolConfig taskThreadPoolConfig;
|
||||
private final GlobalExceptionHandler globalExceptionHandler;
|
||||
|
||||
public OverrideDefaultThreadPoolConfig(TaskThreadPoolConfig taskThreadPoolConfig,
|
||||
GlobalExceptionHandler globalExceptionHandler) {
|
||||
this.taskThreadPoolConfig = taskThreadPoolConfig;
|
||||
this.globalExceptionHandler = globalExceptionHandler;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Executor getAsyncExecutor() {
|
||||
ThreadPoolTaskExecutor threadPoolTaskExecutor = new ThreadPoolTaskExecutor();
|
||||
|
||||
threadPoolTaskExecutor.setCorePoolSize(taskThreadPoolConfig.getCorePoolSize());
|
||||
threadPoolTaskExecutor.setMaxPoolSize(taskThreadPoolConfig.getMaxPoolSize());
|
||||
threadPoolTaskExecutor.setKeepAliveSeconds(taskThreadPoolConfig.getKeepAliveSeconds());
|
||||
threadPoolTaskExecutor.setQueueCapacity(taskThreadPoolConfig.getQueueCapacity());
|
||||
|
||||
threadPoolTaskExecutor.setThreadNamePrefix("ThreadPool-");
|
||||
threadPoolTaskExecutor.setRejectedExecutionHandler(new ThreadPoolExecutor.AbortPolicy());
|
||||
|
||||
threadPoolTaskExecutor.initialize();
|
||||
|
||||
return threadPoolTaskExecutor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AsyncUncaughtExceptionHandler getAsyncUncaughtExceptionHandler() {
|
||||
return (ex, method, params) -> {
|
||||
log.debug(method.getName() + " meets error: " + ex.getMessage());
|
||||
|
||||
if (ex instanceof DorisStartException) {
|
||||
globalExceptionHandler.handleDorisStartException((DorisStartException) ex);
|
||||
return;
|
||||
}
|
||||
|
||||
globalExceptionHandler.handleGlobalException((Exception) ex);
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.realtime.protection.configuration.threadpool;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Data
|
||||
@Component
|
||||
@ConfigurationProperties(prefix = "task.pool")
|
||||
public class TaskThreadPoolConfig {
|
||||
private int corePoolSize;
|
||||
private int maxPoolSize;
|
||||
private int keepAliveSeconds;
|
||||
private int queueCapacity;
|
||||
}
|
||||
@@ -11,11 +11,12 @@ import java.util.Map;
|
||||
public enum StateEnum {
|
||||
// 仅需修改此处即可将任务状态以及对应的State和Num进行对应
|
||||
PENDING(0, new PendingState()),
|
||||
RUNNING(1, new RunningState()),
|
||||
PAUSED(2, new PauseState()),
|
||||
STOP(3, new StopState()),
|
||||
FINISHED(4, new FinishedState()),
|
||||
FAILED(5, new FailedState());
|
||||
GENERATING(1, new GeneratingState()),
|
||||
RUNNING(2, new RunningState()),
|
||||
PAUSED(3, new PauseState()),
|
||||
STOP(4, new StopState()),
|
||||
FINISHED(5, new FinishedState()),
|
||||
FAILED(6, new FailedState());
|
||||
// ----------------------------------------------
|
||||
|
||||
private final State state;
|
||||
|
||||
Reference in New Issue
Block a user