All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.truelayer.java.http.interceptors.logging.SensitiveHeaderGuard Maven / Gradle / Ivy

There is a newer version: 16.0.0
Show newest version
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); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy