mirror of
https://gitee.com/dromara/RuoYi-Cloud-Plus.git
synced 2025-12-30 01:42:25 +00:00
update 优化 接口访问日志 排除敏感参数输出
This commit is contained in:
@@ -71,4 +71,10 @@ public interface SystemConstants {
|
||||
* 根部门祖级列表
|
||||
*/
|
||||
String ROOT_DEPT_ANCESTORS = "0";
|
||||
|
||||
/**
|
||||
* 排除敏感属性字段
|
||||
*/
|
||||
String[] EXCLUDE_PROPERTIES = { "password", "oldPassword", "newPassword", "confirmPassword" };
|
||||
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package org.dromara.common.sensitive.utils;
|
||||
package org.dromara.common.core.utils;
|
||||
|
||||
import cn.hutool.core.util.DesensitizedUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
@@ -13,6 +13,7 @@ import org.aspectj.lang.annotation.AfterReturning;
|
||||
import org.aspectj.lang.annotation.AfterThrowing;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.annotation.Before;
|
||||
import org.dromara.common.core.constant.SystemConstants;
|
||||
import org.dromara.common.core.utils.ServletUtils;
|
||||
import org.dromara.common.core.utils.SpringUtils;
|
||||
import org.dromara.common.core.utils.StringUtils;
|
||||
@@ -39,12 +40,6 @@ import java.util.*;
|
||||
@AutoConfiguration
|
||||
public class LogAspect {
|
||||
|
||||
/**
|
||||
* 排除敏感属性字段
|
||||
*/
|
||||
public static final String[] EXCLUDE_PROPERTIES = { "password", "oldPassword", "newPassword", "confirmPassword" };
|
||||
|
||||
|
||||
/**
|
||||
* 计时 key
|
||||
*/
|
||||
@@ -161,7 +156,7 @@ public class LogAspect {
|
||||
String params = argsArrayToString(joinPoint.getArgs(), excludeParamNames);
|
||||
operLog.setOperParam(StringUtils.substring(params, 0, 3800));
|
||||
} else {
|
||||
MapUtil.removeAny(paramsMap, EXCLUDE_PROPERTIES);
|
||||
MapUtil.removeAny(paramsMap, SystemConstants.EXCLUDE_PROPERTIES);
|
||||
MapUtil.removeAny(paramsMap, excludeParamNames);
|
||||
operLog.setOperParam(StringUtils.substring(JsonUtils.toJsonString(paramsMap), 0, 3800));
|
||||
}
|
||||
@@ -175,7 +170,7 @@ public class LogAspect {
|
||||
if (ArrayUtil.isEmpty(paramsArray)) {
|
||||
return params.toString();
|
||||
}
|
||||
String[] exclude = ArrayUtil.addAll(excludeParamNames, EXCLUDE_PROPERTIES);
|
||||
String[] exclude = ArrayUtil.addAll(excludeParamNames, SystemConstants.EXCLUDE_PROPERTIES);
|
||||
for (Object o : paramsArray) {
|
||||
if (ObjectUtil.isNotNull(o) && !isFilterObject(o)) {
|
||||
String str = "";
|
||||
|
||||
@@ -3,7 +3,7 @@ package org.dromara.common.sensitive.core;
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.util.DesensitizedUtil;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.dromara.common.sensitive.utils.DesensitizedUtils;
|
||||
import org.dromara.common.core.utils.DesensitizedUtils;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
package org.dromara.gateway.filter;
|
||||
|
||||
import cn.hutool.core.lang.Dict;
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.dromara.common.core.constant.SystemConstants;
|
||||
import org.dromara.common.json.utils.JsonUtils;
|
||||
import org.dromara.gateway.config.properties.ApiDecryptProperties;
|
||||
import org.dromara.gateway.config.properties.CustomGatewayProperties;
|
||||
@@ -17,6 +19,9 @@ import org.springframework.util.MultiValueMap;
|
||||
import org.springframework.web.server.ServerWebExchange;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 全局日志过滤器
|
||||
* <p>
|
||||
@@ -51,11 +56,26 @@ public class GlobalLogFilter implements GlobalFilter, Ordered {
|
||||
log.info("[PLUS]开始请求 => URL[{}],参数类型[encrypt]", url);
|
||||
} else {
|
||||
String jsonParam = WebFluxUtils.resolveBodyFromCacheRequest(exchange);
|
||||
List<Dict> list = new ArrayList<>();
|
||||
if (JsonUtils.isJsonArray(jsonParam)) {
|
||||
List<String> list1 = JsonUtils.parseArray(jsonParam, String.class);
|
||||
for (String str : list1) {
|
||||
Dict map = JsonUtils.parseMap(str);
|
||||
MapUtil.removeAny(map, SystemConstants.EXCLUDE_PROPERTIES);
|
||||
list.add(map);
|
||||
}
|
||||
jsonParam = JsonUtils.toJsonString(list);
|
||||
} else {
|
||||
Dict map = JsonUtils.parseMap(jsonParam);
|
||||
MapUtil.removeAny(map, SystemConstants.EXCLUDE_PROPERTIES);
|
||||
jsonParam = JsonUtils.toJsonString(map);
|
||||
}
|
||||
log.info("[PLUS]开始请求 => URL[{}],参数类型[json],参数:[{}]", url, jsonParam);
|
||||
}
|
||||
} else {
|
||||
MultiValueMap<String, String> parameterMap = request.getQueryParams();
|
||||
if (MapUtil.isNotEmpty(parameterMap)) {
|
||||
MapUtil.removeAny(parameterMap, SystemConstants.EXCLUDE_PROPERTIES);
|
||||
String parameters = JsonUtils.toJsonString(parameterMap);
|
||||
log.info("[PLUS]开始请求 => URL[{}],参数类型[param],参数:[{}]", url, parameters);
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user