Class RedactedHeaders

java.lang.Object
org.apache.juneau.http.RedactedHeaders

public final class RedactedHeaders extends Object
Utility for masking the values of header names that commonly carry account credentials (bearer tokens, session cookies, API keys, and the like) before they are written somewhere observable, such as a log line or an echoed-back response body.

Matching is always case-insensitive, mirroring HTTP header-name semantics.

// Default set: mask only the well-known credential-bearing headers. String masked = RedactedHeaders.redact("authorization", "Bearer abc123"); // masked == "[REDACTED]" String kept = RedactedHeaders.redact("User-Agent", "curl/8.0"); // kept == "curl/8.0"

Callers that need a different or extended header set (for example, an additional internal-trace header) can pass their own name collection to the two-argument overloads rather than being limited to DEFAULT.

Since:
10.0.0
  • Field Details

    • REDACTED

      public static final String REDACTED
      Sentinel value substituted for a masked header value.
      See Also:
    • DEFAULT

      public static final Set<String> DEFAULT
      Canonical set of header names commonly used to carry credentials, matched case-insensitively.
  • Method Details

    • isSensitive

      public static boolean isSensitive(String name)
      Returns true if the given header name is in DEFAULT (case-insensitive).
      Parameters:
      name - The header name to test. Can be null (returns false).
      Returns:
      true if the name matches one of DEFAULT, case-insensitively.
    • isSensitive

      public static boolean isSensitive(String name, Collection<String> names)
      Returns true if the given header name matches one of names, case-insensitively.
      Parameters:
      name - The header name to test. Can be null (returns false).
      names - The candidate header names. Can be null or empty (returns false). null elements are ignored.
      Returns:
      true if name matches one of names, case-insensitively.
    • redact

      public static String redact(String name, String value)
      Masks value with REDACTED if name is in DEFAULT (case-insensitive); otherwise returns value unchanged.
      Parameters:
      name - The header name. Can be null (never matches; value is returned as-is).
      value - The header value to mask. Can be null.
      Returns:
      REDACTED if name is sensitive, else value.
    • redact

      public static String redact(String name, String value, Collection<String> names)
      Masks value with REDACTED if name matches one of names (case-insensitive); otherwise returns value unchanged.
      Parameters:
      name - The header name. Can be null (never matches; value is returned as-is).
      value - The header value to mask. Can be null.
      names - The candidate header names. Can be null or empty (nothing is masked).
      Returns:
      REDACTED if name matches one of names, else value.