com.truelayer.java.http.interceptors.logging.SensitiveHeaderGuard Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of truelayer-java Show documentation
Show all versions of truelayer-java Show documentation
TrueLayer Java SDK for https://truelayer.com
package com.truelayer.java.http.interceptors.logging;
import static org.apache.commons.lang3.ObjectUtils.isEmpty;
import com.truelayer.java.Constants;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import okhttp3.Headers;
import okhttp3.internal.http2.Header;
public class SensitiveHeaderGuard {
protected static final String SENSITIVE_HEADER_MASK = "***";
public List getSanitizedHeaders(Headers headers) {
if (isEmpty(headers)) {
return Collections.emptyList();
}
List sanitizedHeaders = new ArrayList<>();
headers.toMultimap()
.forEach((headerName, headerValues) -> sanitizedHeaders.add(new Header(
headerName,
isSensitiveHeader(headerName) ? SENSITIVE_HEADER_MASK : String.join(",", headerValues))));
return Collections.unmodifiableList(sanitizedHeaders);
}
protected boolean isSensitiveHeader(String headerName) {
return headerName.equalsIgnoreCase(Constants.HeaderNames.AUTHORIZATION)
|| headerName.equalsIgnoreCase(Constants.HeaderNames.COOKIE);
}
}