Spring boot 屏蔽日志文件中的密码、信用卡信息
我需要屏蔽日志文件中的几个字段。 比如信用卡信息或密码。 我们有什么直接的方法吗? 或者我们必须为日志字段编写的任何代码段来屏蔽这些信用卡信息,以便在日志文件中显示这些信息。 例子: CreditcardNo:411111111应在日志文件中显示为**********1111 密码Password123应以密码形式出现在日志中***********Spring boot 屏蔽日志文件中的密码、信用卡信息,spring-boot,log4j,Spring Boot,Log4j,我需要屏蔽日志文件中的几个字段。 比如信用卡信息或密码。 我们有什么直接的方法吗? 或者我们必须为日志字段编写的任何代码段来屏蔽这些信用卡信息,以便在日志文件中显示这些信息。 例子: CreditcardNo:411111111应在日志文件中显示为**********1111 密码Password123应以密码形式出现在日志中*********** <groupId>com.github.spartatech</groupId> <artifactId>spr
<groupId>com.github.spartatech</groupId>
<artifactId>spring-ws-utils</artifactId>
我使用log4j将信息写入日志。对于使用spring ws的SOAP Web服务,我使用了lib:
<groupId>com.github.spartatech</groupId>
<artifactId>spring-ws-utils</artifactId>
com.github.spartatech
春季天气预报
要使用它,您应该配置一个拦截器来屏蔽字段。屏蔽是使用XSLT完成的。其工作方式是(本例使用SpringXML协同配置,但也可以使用基于Java的配置进行配置):
<groupId>com.github.spartatech</groupId>
<artifactId>spring-ws-utils</artifactId>
配置spring ws拦截器:
<groupId>com.github.spartatech</groupId>
<artifactId>spring-ws-utils</artifactId>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:sws="http://www.springframework.org/schema/web-services"
xsi:schemaLocation="
http://www.springframework.org/schema/web-services http://www.springframework.org/schema/web-services/web-services-2.0.xsd
>
...
<sws:interceptors>
<bean class="org.sparta.springwsutils.PayloadTransformedLoggingInterceptor">
<property name="xslt" value="classpath:xslt/maskInput.xslt"/>
</bean>
</sws:interceptors>
您可以通过从log4j切换到Logback并配置日志模式来屏蔽Spring Boot记录的敏感数据
<groupId>com.github.spartatech</groupId>
<artifactId>spring-ws-utils</artifactId>
使用Logback。这是一个
<groupId>com.github.spartatech</groupId>
<artifactId>spring-ws-utils</artifactId>
在应用程序.properties
中定义logging.pattern.file
,使用替换每个密码出现的掩码:
<groupId>com.github.spartatech</groupId>
<artifactId>spring-ws-utils</artifactId>
- e、 g.
logging.pattern.file=%d%replace(%m){“password='.*',“password='xxx'.}
- 对于默认的Spring Boot logback文件模式]它将是:
logging.pattern.file=%d{yyyyy-MM-dd HH:MM:ss.SSS}${LOG\u LEVEL\u模式:-%5p}${PID:-}-[%t]-[%t]-40.40logger{39}:%replace(%m){“password='.'.'''xxx'}%n${LOG\u EXCEPTION\u-CONVERSION\u-WORD wEx}
请显示一些如何记录这些字符串的代码。最简单的方法就是首先从日志中删除这些信息(也可能从任何toString方法中排除它们)。这些数据可以作为终点的参数,将由Log4J记录器记录。请参阅