mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-10-14 02:05:12 +08:00
#556 日志信息中如果含有secret值的,将其值隐藏掉
This commit is contained in:
@@ -109,6 +109,11 @@
|
||||
<artifactId>jetty-servlet</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.assertj</groupId>
|
||||
<artifactId>assertj-guava</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
@@ -0,0 +1,24 @@
|
||||
package me.chanjar.weixin.common.util;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 数据处理工具类
|
||||
* Created by BinaryWang on 2018/5/8.
|
||||
* </pre>
|
||||
*
|
||||
* @author <a href="https://github.com/binarywang">Binary Wang</a>
|
||||
*/
|
||||
public class DataUtils {
|
||||
/**
|
||||
* 将数据中包含的secret字符使用星号替换,防止日志打印时被输出
|
||||
*/
|
||||
public static <E> E handleDataWithSecret(E data) {
|
||||
E dataForLog = data;
|
||||
if(data instanceof String && StringUtils.contains((String)data, "&secret=")){
|
||||
dataForLog = (E) StringUtils.replaceAll((String)data,"&secret=\\w+&","&secret=******&");
|
||||
}
|
||||
return dataForLog;
|
||||
}
|
||||
}
|
@@ -0,0 +1,23 @@
|
||||
package me.chanjar.weixin.common.util;
|
||||
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.testng.Assert.*;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* Created by BinaryWang on 2018/5/8.
|
||||
* </pre>
|
||||
*
|
||||
* @author <a href="https://github.com/binarywang">Binary Wang</a>
|
||||
*/
|
||||
public class DataUtilsTest {
|
||||
|
||||
@Test
|
||||
public void testHandleDataWithSecret() {
|
||||
String data = "js_code=001tZveq0SMoiq1AEXeq0ECJeq0tZveZ&secret=5681022fa1643845392367ea88888888&grant_type=authorization_code&appid=wxe156d4848d999999";
|
||||
final String s = DataUtils.handleDataWithSecret(data);
|
||||
assertThat(s).contains("&secret=******&");
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user