This is an automated email from the ASF dual-hosted git repository. ashakirin pushed a commit to branch feature/CXF-8099_mask_sensitive_logging_elements in repository https://gitbox.apache.org/repos/asf/cxf.git
The following commit(s) were added to refs/heads/feature/CXF-8099_mask_sensitive_logging_elements by this push: new dfa0f44 CXF-8099: improvements regarding PR comments dfa0f44 is described below commit dfa0f44090a54abe45235554066acbde96f43877 Author: ashakirin <49843238+ashakirin-tal...@users.noreply.github.com> AuthorDate: Sat Jul 4 01:03:43 2020 +0200 CXF-8099: improvements regarding PR comments --- rt/features/logging/pom.xml | 5 ----- .../apache/cxf/ext/logging/AbstractLoggingInterceptor.java | 10 ++++++---- .../java/org/apache/cxf/ext/logging/MaskSensitiveHelper.java | 11 ++++------- 3 files changed, 10 insertions(+), 16 deletions(-) diff --git a/rt/features/logging/pom.xml b/rt/features/logging/pom.xml index aa515f4..0cf823d 100644 --- a/rt/features/logging/pom.xml +++ b/rt/features/logging/pom.xml @@ -39,11 +39,6 @@ <artifactId>slf4j-api</artifactId> </dependency> <dependency> - <groupId>org.apache.commons</groupId> - <artifactId>commons-lang3</artifactId> - </dependency> - - <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-jdk14</artifactId> <scope>test</scope> diff --git a/rt/features/logging/src/main/java/org/apache/cxf/ext/logging/AbstractLoggingInterceptor.java b/rt/features/logging/src/main/java/org/apache/cxf/ext/logging/AbstractLoggingInterceptor.java index 9a452b8..91a4adc 100644 --- a/rt/features/logging/src/main/java/org/apache/cxf/ext/logging/AbstractLoggingInterceptor.java +++ b/rt/features/logging/src/main/java/org/apache/cxf/ext/logging/AbstractLoggingInterceptor.java @@ -19,6 +19,7 @@ package org.apache.cxf.ext.logging; import java.util.List; +import java.util.Optional; import java.util.UUID; import org.apache.cxf.common.util.PropertyUtils; @@ -45,7 +46,7 @@ public abstract class AbstractLoggingInterceptor extends AbstractPhaseIntercepto protected LogEventSender sender; protected final DefaultLogEventMapper eventMapper = new DefaultLogEventMapper(); - private List<String> sensitiveElementNames; + private MaskSensitiveHelper maskSensitiveHelper; public AbstractLoggingInterceptor(String phase, LogEventSender sender) { super(phase); @@ -78,7 +79,7 @@ public abstract class AbstractLoggingInterceptor extends AbstractPhaseIntercepto } public void setSensitiveElementNames(final List<String> sensitiveElementNames) { - this.sensitiveElementNames = sensitiveElementNames; + maskSensitiveHelper = new MaskSensitiveHelper(sensitiveElementNames); } public void setPrettyLogging(boolean prettyLogging) { @@ -115,7 +116,8 @@ public abstract class AbstractLoggingInterceptor extends AbstractPhaseIntercepto } protected String maskSensitiveElements(final Message message, String originalLogString) { - return (new MaskSensitiveHelper(sensitiveElementNames)) - .maskSensitiveElements(message, originalLogString); + return Optional.ofNullable(maskSensitiveHelper) + .map(h -> h.maskSensitiveElements(message, originalLogString)) + .orElse(originalLogString); } } diff --git a/rt/features/logging/src/main/java/org/apache/cxf/ext/logging/MaskSensitiveHelper.java b/rt/features/logging/src/main/java/org/apache/cxf/ext/logging/MaskSensitiveHelper.java index 3130680..4d50da6 100644 --- a/rt/features/logging/src/main/java/org/apache/cxf/ext/logging/MaskSensitiveHelper.java +++ b/rt/features/logging/src/main/java/org/apache/cxf/ext/logging/MaskSensitiveHelper.java @@ -20,11 +20,8 @@ package org.apache.cxf.ext.logging; import java.util.List; -import org.apache.commons.lang3.StringUtils; import org.apache.cxf.message.Message; -import static org.apache.commons.lang3.ObjectUtils.isEmpty; - public class MaskSensitiveHelper { private static final String ELEMENT_NAME_TEMPLATE = "-ELEMENT_NAME-"; private static final String MATCH_PATTERN_XML = "<-ELEMENT_NAME->(.*?)</-ELEMENT_NAME->"; @@ -45,14 +42,14 @@ public class MaskSensitiveHelper { public String maskSensitiveElements( final Message message, final String originalLogString) { - if (isEmpty(sensitiveElementNames)) { + if ((sensitiveElementNames == null) || sensitiveElementNames.isEmpty()) { return originalLogString; } String contentType = (String) message.get(Message.CONTENT_TYPE); - if (StringUtils.containsIgnoreCase(contentType, XML_CONTENT) - || StringUtils.containsIgnoreCase(contentType, HTML_CONTENT)) { + if (contentType.toLowerCase().contains(XML_CONTENT) + || contentType.toLowerCase().contains(HTML_CONTENT)) { return applyExpression(originalLogString, MATCH_PATTERN_XML, REPLACEMENT_PATTERN_XML); - } else if (StringUtils.containsIgnoreCase(contentType, JSON_CONTENT)) { + } else if (contentType.toLowerCase().contains(JSON_CONTENT)) { return applyExpression(originalLogString, MATCH_PATTERN_JSON, REPLACEMENT_PATTERN_JSON); } else { return originalLogString;