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 edce9a3  CXF-8099: refactored header replacing
edce9a3 is described below

commit edce9a39c0d0c87e1691e0fcf5d357623d0ae2b3
Author: ashakirin <[email protected]>
AuthorDate: Wed Jul 22 01:30:47 2020 +0200

    CXF-8099: refactored header replacing
---
 .../cxf/ext/logging/AbstractLoggingInterceptor.java       |  4 ++--
 .../cxf/ext/logging/event/DefaultLogEventMapper.java      | 15 +++++++--------
 2 files changed, 9 insertions(+), 10 deletions(-)

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 6cd825f..e12cc9a 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
@@ -83,8 +83,8 @@ public abstract class AbstractLoggingInterceptor extends 
AbstractPhaseIntercepto
         maskSensitiveHelper.addSensitiveElementNames(sensitiveElementNames);
     }
 
-    public void addSensitiveProtocolHeaderNames(final Set<String> 
sensitiveProtocolHeaderNames) {
-        this.sensitiveProtocolHeaderNames.addAll(sensitiveProtocolHeaderNames);
+    public void addSensitiveProtocolHeaderNames(final Set<String> 
protocolHeaderNames) {
+        this.sensitiveProtocolHeaderNames.addAll(protocolHeaderNames);
     }
 
     public void setPrettyLogging(boolean prettyLogging) {
diff --git 
a/rt/features/logging/src/main/java/org/apache/cxf/ext/logging/event/DefaultLogEventMapper.java
 
b/rt/features/logging/src/main/java/org/apache/cxf/ext/logging/event/DefaultLogEventMapper.java
index c568453..78f4782 100644
--- 
a/rt/features/logging/src/main/java/org/apache/cxf/ext/logging/event/DefaultLogEventMapper.java
+++ 
b/rt/features/logging/src/main/java/org/apache/cxf/ext/logging/event/DefaultLogEventMapper.java
@@ -86,7 +86,8 @@ public class DefaultLogEventMapper {
         event.setContentType(safeGet(message, Message.CONTENT_TYPE));
 
         Map<String, String> headerMap = getHeaders(message);
-        event.setHeaders(maskHeaders(headerMap, sensitiveProtocolHeaders));
+        maskHeaders(headerMap, sensitiveProtocolHeaders);
+        event.setHeaders(headerMap);
 
         event.setAddress(getAddress(message, event));
 
@@ -97,15 +98,13 @@ public class DefaultLogEventMapper {
         return event;
     }
 
-    private Map<String, String> maskHeaders(
+    private void maskHeaders(
             final Map<String, String> headerMap,
             final Set<String> sensitiveHeaderNames) {
-        final Map<String, String> maskedHeaderMap = new HashMap<>();
-        headerMap.keySet().forEach(h -> {
-            maskedHeaderMap.put(h, sensitiveHeaderNames.contains(h)
-                    ? MASKED_HEADER_VALUE : headerMap.get(h));
-        });
-        return maskedHeaderMap;
+        sensitiveHeaderNames.stream()
+                .forEach(h -> {
+                    headerMap.computeIfPresent(h, (key, value) -> 
MASKED_HEADER_VALUE);
+                });
     }
 
     private String getPrincipal(Message message) {

Reply via email to