From 3ee2822a410e6499a71f36c69621add068d54617 Mon Sep 17 00:00:00 2001 From: = Date: Fri, 12 Jun 2020 14:55:16 +0800 Subject: [PATCH] =?UTF-8?q?validatorUtils=E5=B7=A5=E5=85=B7=E7=B1=BB?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/epmet/commons/tools/validator/ValidatorUtils.java | 5 ++++- .../com/epmet/openapi/scan/controller/ScanController.java | 3 +++ .../epmet/openapi/scan/service/impl/ScanServiceImpl.java | 1 + .../com/epmet/openapi/scan/support/param/ImgScanParam.java | 4 ++++ .../java/com/epmet/openapi/scan/support/param/ImgTask.java | 3 +++ .../com/epmet/openapi/scan/support/param/TextScanParam.java | 4 ++++ epmet-openapi/epmet-openapi-scan/src/main/resources/readme | 6 ++++-- 7 files changed, 23 insertions(+), 3 deletions(-) diff --git a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/validator/ValidatorUtils.java b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/validator/ValidatorUtils.java index c5ae8767a2..e98cc09fe7 100644 --- a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/validator/ValidatorUtils.java +++ b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/validator/ValidatorUtils.java @@ -50,7 +50,10 @@ public class ValidatorUtils { List> customerShowGroups = new ArrayList<>(); List> internalGroups = new ArrayList<>(); - + if (groups == null || groups.length ==0){ + validate(EpmetErrorCode.CUSTOMER_VALIDATE_ERROR ,object,groups); + return; + } Arrays.asList(groups).forEach(g -> { if (CustomerClientShowGroup.class.isAssignableFrom(g)) { //如果派生自客户端显示分组,那么会优先校验,并且将错误提示给客户端,返回客户端可见的错误码 diff --git a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/controller/ScanController.java b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/controller/ScanController.java index 96848bfc84..efaae3ddd5 100644 --- a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/controller/ScanController.java +++ b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/controller/ScanController.java @@ -1,6 +1,7 @@ package com.epmet.openapi.scan.controller; import com.epmet.commons.tools.utils.Result; +import com.epmet.commons.tools.validator.ValidatorUtils; import com.epmet.openapi.scan.service.impl.ScanService; import com.epmet.openapi.scan.support.param.ImgScanParam; import com.epmet.openapi.scan.support.param.TextScanParam; @@ -32,6 +33,7 @@ public class ScanController { */ @RequestMapping("imgSyncScan") public Result ImgSyncScan(@RequestBody ImgScanParam param) { + ValidatorUtils.validateEntity(param); Result scanResultResult = scanService.sendSyncImgScan(param); return scanResultResult; } @@ -44,6 +46,7 @@ public class ScanController { */ @RequestMapping("textSyncScan") public Result textSyncScan(@RequestBody TextScanParam param) { + ValidatorUtils.validateEntity(param); Result scanResultResult = scanService.sendTextScan(param); return scanResultResult; } diff --git a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/service/impl/ScanServiceImpl.java b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/service/impl/ScanServiceImpl.java index f69824ca14..6848de234f 100644 --- a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/service/impl/ScanServiceImpl.java +++ b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/service/impl/ScanServiceImpl.java @@ -12,6 +12,7 @@ import com.aliyuncs.green.model.v20180509.TextScanRequest; import com.aliyuncs.http.FormatType; import com.aliyuncs.http.HttpResponse; import com.epmet.commons.tools.utils.Result; +import com.epmet.commons.tools.validator.ValidatorUtils; import com.epmet.openapi.scan.common.constant.SysConstant; import com.epmet.openapi.scan.common.enu.ImgSceneEnum; import com.epmet.openapi.scan.common.enu.SuggestionEnum; diff --git a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/param/ImgScanParam.java b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/param/ImgScanParam.java index 16e38eaa04..82036797e3 100644 --- a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/param/ImgScanParam.java +++ b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/param/ImgScanParam.java @@ -2,6 +2,8 @@ package com.epmet.openapi.scan.support.param; import lombok.Data; +import javax.validation.Valid; +import javax.validation.constraints.NotEmpty; import java.io.Serializable; import java.util.List; @@ -30,6 +32,8 @@ public class ImgScanParam implements Serializable { * 要检测的内容列表,必填 * remark:一组任务列表中的taskId不能相同 */ + @Valid + @NotEmpty(message = "任务列表不能为空") private List tasks; /** diff --git a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/param/ImgTask.java b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/param/ImgTask.java index e06204415f..2ec15a9593 100644 --- a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/param/ImgTask.java +++ b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/param/ImgTask.java @@ -2,6 +2,7 @@ package com.epmet.openapi.scan.support.param; import lombok.Data; +import javax.validation.constraints.NotNull; import java.io.Serializable; /** @@ -19,10 +20,12 @@ public class ImgTask implements Serializable { * 要检测的数据id 非必填 * * */ + @NotNull(message = "dataId不能为空") private String dataId; /** * 图片url 必填 */ + @NotNull(message = "图片URL不能为空") private String url; } diff --git a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/param/TextScanParam.java b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/param/TextScanParam.java index 8a49fd5d2a..16ad063428 100644 --- a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/param/TextScanParam.java +++ b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/param/TextScanParam.java @@ -2,6 +2,8 @@ package com.epmet.openapi.scan.support.param; import lombok.Data; +import javax.validation.Valid; +import javax.validation.constraints.NotEmpty; import java.io.Serializable; import java.util.List; @@ -24,6 +26,8 @@ public class TextScanParam implements Serializable { * * @see com.epmet.openapi.scan.common.enu.ImgSceneEnum; */ + @Valid + @NotEmpty(message = "任务列表不能为空") private List scenes; /** diff --git a/epmet-openapi/epmet-openapi-scan/src/main/resources/readme b/epmet-openapi/epmet-openapi-scan/src/main/resources/readme index 5b2e138e3e..7cb6399fe1 100644 --- a/epmet-openapi/epmet-openapi-scan/src/main/resources/readme +++ b/epmet-openapi/epmet-openapi-scan/src/main/resources/readme @@ -1,2 +1,4 @@ -#添加白名单 -sadd epmet:openapi:scan:whitelist "客户端ip地址" \ No newline at end of file +#访问openApi 需要向redis中 添加白名单 +sadd epmet:openapi:scan:whitelist "客户端ip地址" +#eg: +sadd epmet:openapi:scan:whitelist "\"192.168.1.1\"" \ No newline at end of file