优化Restful接口校验

This commit is contained in:
六如
2025-02-09 17:14:54 +08:00
parent be50186da6
commit 71b064d607
11 changed files with 54 additions and 13 deletions

View File

@@ -70,6 +70,11 @@ public class ApiInfoDTO implements Serializable {
private Integer status;
/**
* 接口模式1-open接口2-Restful模式
*/
private Integer apiMode;
public String buildApiNameVersion() {
return apiName + apiVersion;
}

View File

@@ -85,6 +85,11 @@ public class ApiInfo {
*/
private Integer status;
/**
* 接口模式1-open接口2-Restful模式
*/
private Integer apiMode;
private LocalDateTime addTime;
private LocalDateTime updateTime;

View File

@@ -15,6 +15,7 @@ import com.gitee.sop.gateway.service.manager.IsvApiPermissionManager;
import com.gitee.sop.gateway.service.manager.IsvManager;
import com.gitee.sop.gateway.service.manager.SecretManager;
import com.gitee.sop.gateway.service.manager.dto.IsvDTO;
import com.gitee.sop.support.enums.ApiModeEnum;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.BooleanUtils;
import org.springframework.beans.factory.annotation.Autowired;
@@ -31,6 +32,7 @@ import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import java.util.List;
import java.util.Locale;
import java.util.Objects;
/**
* 负责校验,校验工作都在这里
@@ -111,6 +113,11 @@ public class ApiValidator implements Validator {
ApiInfoDTO apiInfo = apiManager.get(apiRequest.getMethod(), apiRequest.getVersion());
// 检查接口信息
checkApiInfo(apiRequestContext, apiInfo);
if (!Objects.equals(apiInfo.getApiMode(), ApiModeEnum.RESTFUL.getValue())) {
log.error("Open模式接口不允许使用Restful进行访问, apiInfo={}", apiInfo);
throw new ApiException(ErrorEnum.ISV_INVALID_METHOD, apiRequestContext.getLocale());
}
// IP能否访问
checkIP(apiRequestContext);
// 检查上传文件