From e0781254700957adad953e7693f029c7078ebd1b Mon Sep 17 00:00:00 2001 From: "Michelle.Chung" <1242874891@qq.com> Date: Mon, 24 Jul 2023 08:52:37 +0800 Subject: [PATCH] =?UTF-8?q?update=20=E6=9B=B4=E6=96=B0=20GlobalLogFilter#f?= =?UTF-8?q?ilter=20=E6=A0=B9=E6=8D=AE=E8=AF=B7=E6=B1=82=E5=A4=B4=E5=88=A4?= =?UTF-8?q?=E6=96=AD=E5=8A=A0=E5=AF=86=E5=8F=82=E6=95=B0=20;?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../properties/ApiDecryptProperties.java | 28 +++++++++++++++++++ .../gateway/filter/GlobalLogFilter.java | 13 +++++++-- 2 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 ruoyi-gateway/src/main/java/org/dromara/gateway/config/properties/ApiDecryptProperties.java diff --git a/ruoyi-gateway/src/main/java/org/dromara/gateway/config/properties/ApiDecryptProperties.java b/ruoyi-gateway/src/main/java/org/dromara/gateway/config/properties/ApiDecryptProperties.java new file mode 100644 index 00000000..c038bd4f --- /dev/null +++ b/ruoyi-gateway/src/main/java/org/dromara/gateway/config/properties/ApiDecryptProperties.java @@ -0,0 +1,28 @@ +package org.dromara.gateway.config.properties; + +import lombok.Data; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.cloud.context.config.annotation.RefreshScope; +import org.springframework.stereotype.Component; + +/** + * api解密属性配置类 + * @author wdhcr + */ +@Data +@Component +@RefreshScope +@ConfigurationProperties(prefix = "api-decrypt") +public class ApiDecryptProperties { + + /** + * 加密开关 + */ + private Boolean enabled; + + /** + * 头部标识 + */ + private String headerFlag; + +} diff --git a/ruoyi-gateway/src/main/java/org/dromara/gateway/filter/GlobalLogFilter.java b/ruoyi-gateway/src/main/java/org/dromara/gateway/filter/GlobalLogFilter.java index 648394e2..2c776513 100644 --- a/ruoyi-gateway/src/main/java/org/dromara/gateway/filter/GlobalLogFilter.java +++ b/ruoyi-gateway/src/main/java/org/dromara/gateway/filter/GlobalLogFilter.java @@ -1,7 +1,9 @@ package org.dromara.gateway.filter; import cn.hutool.core.map.MapUtil; +import cn.hutool.core.util.ObjectUtil; import org.dromara.common.json.utils.JsonUtils; +import org.dromara.gateway.config.properties.ApiDecryptProperties; import org.dromara.gateway.config.properties.CustomGatewayProperties; import org.dromara.gateway.utils.WebFluxUtils; import lombok.extern.slf4j.Slf4j; @@ -28,6 +30,8 @@ public class GlobalLogFilter implements GlobalFilter, Ordered { @Autowired private CustomGatewayProperties customGatewayProperties; + @Autowired + private ApiDecryptProperties apiDecryptProperties; private static final String START_TIME = "startTime"; @@ -42,8 +46,13 @@ public class GlobalLogFilter implements GlobalFilter, Ordered { // 打印请求参数 if (WebFluxUtils.isJsonRequest(exchange)) { - String jsonParam = WebFluxUtils.resolveBodyFromCacheRequest(exchange); - log.info("[PLUS]开始请求 => URL[{}],参数类型[json],参数:[{}]", url, jsonParam); + if (apiDecryptProperties.getEnabled() + && ObjectUtil.isNotNull(request.getHeaders().getFirst(apiDecryptProperties.getHeaderFlag()))) { + log.info("[PLUS]开始请求 => URL[{}],参数类型[encrypt]", url); + } else { + String jsonParam = WebFluxUtils.resolveBodyFromCacheRequest(exchange); + log.info("[PLUS]开始请求 => URL[{}],参数类型[json],参数:[{}]", url, jsonParam); + } } else { MultiValueMap parameterMap = request.getQueryParams(); if (MapUtil.isNotEmpty(parameterMap)) {