Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ public boolean beforeProcess(Exchange exchange, Processor processor, NamedNode d
ChainElementType chainElementType = ChainElementType.fromString(
dbgProperties.getElementProperty(nodeId).get(ChainProperties.ELEMENT_TYPE));

Map<String, String> headersForLogging = Collections.emptyMap();
Map<String, String> headersForLogging = new HashMap<>();
Map<String, SessionElementProperty> exchangePropertiesForLogging = Collections.emptyMap();
String bodyForLogging = null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@

import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import javax.annotation.Nullable;

@Slf4j
Expand All @@ -60,6 +62,8 @@ public class ChainLogger {
public static final String MDC_TRACE_ID = "trace_id";
public static final String MDC_SNAP_ID = "span_id";

private static final Set<String> SENSITIVE_KEYS = Set.of("username", "password");

private final TracingService tracingService;
private final Optional<OriginatingBusinessIdProvider> originatingBusinessIdProvider;

Expand Down Expand Up @@ -103,6 +107,8 @@ public void logBeforeProcess(
String nodeId
) {
bodyForLogging = DebuggerUtils.chooseLogPayload(exchange, bodyForLogging, dbgProperties);
exchangePropertiesForLogging = filterExchangeProperties(exchangePropertiesForLogging);
headersForLogging.replace("Authorization", CamelConstants.MASKING_TEMPLATE);
if (dbgProperties.getRuntimeProperties(exchange).getLogLoggingLevel().isInfoLevel()) {
ChainElementType type = ChainElementType.fromString(
dbgProperties.getElementProperty(nodeId).get(
Expand Down Expand Up @@ -514,4 +520,18 @@ private String constructExtendedLogMessage(Long responseTime, String direction)

return String.format("[responseTime=%-4s] [direction=%-8s]", responseTimeStr, direction);
}

public Map<String, SessionElementProperty> filterExchangeProperties(Map<String, SessionElementProperty> props) {

return props.entrySet().stream()
.filter(entry -> {
String key = entry.getKey();
if (key == null) {
return false;
}
String lowerKey = key.toLowerCase();
return SENSITIVE_KEYS.stream().noneMatch(lowerKey::contains);
})
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package org.qubership.integration.platform.engine.service.debugger.logging;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.qubership.integration.platform.engine.model.SessionElementProperty;

import java.util.HashMap;
import java.util.Map;
import java.util.Optional;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class ChainLoggerTest {

Check warning on line 14 in src/test/java/org/qubership/integration/platform/engine/service/debugger/logging/ChainLoggerTest.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this 'public' modifier.

See more on https://sonarcloud.io/project/issues?id=Netcracker_qubership-integration-engine&issues=AZ5ADyLVdH3L69zJNO5r&open=AZ5ADyLVdH3L69zJNO5r&pullRequest=540

private ChainLogger chainLogger;

@BeforeEach
void setUp() {
chainLogger = new ChainLogger(null, Optional.empty());
}

@Test
void shouldFilterSensitiveExchangeProperties() {
Map<String, SessionElementProperty> props = new HashMap<>();
props.put("dbaas_password", new SessionElementProperty("java.lang.String", "secret"));
props.put("dbaas_username", new SessionElementProperty("java.lang.String", "secret"));
props.put("namespace", new SessionElementProperty("java.lang.String", "qa08"));
Map<String, SessionElementProperty> filteredExchangeProperties = chainLogger.filterExchangeProperties(props);
assertFalse(filteredExchangeProperties.containsKey("dbaas_password"));
assertFalse(filteredExchangeProperties.containsKey("dbaas_username"));
assertTrue(filteredExchangeProperties.containsKey("namespace"));
}
}
Loading