From 43eb8f060415b36735ddc502a53c2dc502011231 Mon Sep 17 00:00:00 2001 From: fshenye <512914587@qq.com> Date: Thu, 20 Oct 2022 16:24:02 +0800 Subject: [PATCH] =?UTF-8?q?1.=20IP=E7=99=BD=E5=90=8D=E5=8D=9504?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sh/stc/sict/cloud/common/gateway/config/WhitIPConfig.java | 1 + .../sict/cloud/common/gateway/filter/RequestGlobalFilter.java | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/cloud-common/cloud-common-gateway/src/main/java/cn/sh/stc/sict/cloud/common/gateway/config/WhitIPConfig.java b/cloud-common/cloud-common-gateway/src/main/java/cn/sh/stc/sict/cloud/common/gateway/config/WhitIPConfig.java index 2dcf103..d580df2 100644 --- a/cloud-common/cloud-common-gateway/src/main/java/cn/sh/stc/sict/cloud/common/gateway/config/WhitIPConfig.java +++ b/cloud-common/cloud-common-gateway/src/main/java/cn/sh/stc/sict/cloud/common/gateway/config/WhitIPConfig.java @@ -20,5 +20,6 @@ import java.util.List; @ConditionalOnExpression("!'${whiteip}'.isEmpty()") @ConfigurationProperties(prefix = "whiteip") public class WhitIPConfig { + private Boolean limitFlag; private List whites = new ArrayList<>(); } diff --git a/cloud-common/cloud-common-gateway/src/main/java/cn/sh/stc/sict/cloud/common/gateway/filter/RequestGlobalFilter.java b/cloud-common/cloud-common-gateway/src/main/java/cn/sh/stc/sict/cloud/common/gateway/filter/RequestGlobalFilter.java index 6cf236a..ca5e212 100644 --- a/cloud-common/cloud-common-gateway/src/main/java/cn/sh/stc/sict/cloud/common/gateway/filter/RequestGlobalFilter.java +++ b/cloud-common/cloud-common-gateway/src/main/java/cn/sh/stc/sict/cloud/common/gateway/filter/RequestGlobalFilter.java @@ -67,7 +67,7 @@ public class RequestGlobalFilter implements GlobalFilter, Ordered { String ip = WebUtils.getIP(request); log.error("RemoteAddress ===================> {}", request.getRemoteAddress()); try { - if (!IPStrUtil.matches(ip, whitIPConfig.getWhites())) { + if (whitIPConfig.getLimitFlag() && !IPStrUtil.matches(ip, whitIPConfig.getWhites())) { ServerHttpResponse response = exchange.getResponse(); response.setStatusCode(HttpStatus.PRECONDITION_REQUIRED); response.getHeaders().set("Content-type", "application/json; charset=utf-8"); -- 2.22.0