Class ProxyAuthorization.Builder

java.lang.Object
org.apache.juneau.http.header.ProxyAuthorization.Builder
Enclosing class:
ProxyAuthorization

public static class ProxyAuthorization.Builder extends Object
Fluent builder for assembling an HTTP Proxy-Authorization credentials value.

Composes the scheme 1*SP ( token68 / #auth-param ) credentials form defined by RFC 7235 ยง4.4. The basic(String, String) and bearer(String) presets render the opaque token68 form; the digest() preset enables the typed Digest auth-params, which apply the correct quoting (quoted-string vs token). param(String, String) is a generic escape hatch so new params never require an API change. Setting a scheme preset or token(String) clears any previously-registered auth-params and vice versa, so a built value carries either a token68 or an auth-param list, never both.

Example:

String value = ProxyAuthorization.create() .digest() .username("Mufasa") .realm("http-auth@example.org") .uri("/dir/index.html") .qop("auth") .nc("00000001") .response("8ca523f5e9506fed4657c9700eebdbec") .build(); // => "Digest username=\"Mufasa\", realm=\"...\", uri=\"/dir/index.html\", qop=auth, nc=00000001, response=\"...\""

See Also:
Since:
10.0.0
  • Constructor Details

  • Method Details

    • scheme

      Sets the authentication scheme (e.g. "Basic", "Bearer", "Digest").
      Parameters:
      value - The scheme name. Must not be null or blank.
      Returns:
      This object.
      Throws:
      IllegalArgumentException - If value is null or blank.
    • basic

      public ProxyAuthorization.Builder basic(String user, String password)
      Sets Basic credentials by base64-encoding user:password as the token68 form.
      Parameters:
      user - The username. Must not be null.
      password - The password. Must not be null.
      Returns:
      This object.
    • bearer

      Sets Bearer credentials with the supplied token as the token68 form.
      Parameters:
      token - The bearer token. Must not be null.
      Returns:
      This object.
    • digest

      Sets the scheme to Digest (typed Digest auth-params can then be chained).
      Returns:
      This object.
    • token

      Sets the opaque token68 credentials form, clearing any auth-params.
      Parameters:
      value - The token68 value. Must not be null.
      Returns:
      This object.
    • username

      Sets the username auth-param (rendered as a quoted-string).
      Parameters:
      value - The username. Must not be null.
      Returns:
      This object.
    • realm

      Sets the realm auth-param (rendered as a quoted-string).
      Parameters:
      value - The realm. Must not be null.
      Returns:
      This object.
    • nonce

      Sets the nonce auth-param (rendered as a quoted-string).
      Parameters:
      value - The server nonce echoed back from the challenge. Must not be null.
      Returns:
      This object.
    • uri

      Sets the uri auth-param (rendered as a quoted-string).
      Parameters:
      value - The effective request URI. Must not be null.
      Returns:
      This object.
    • response

      Sets the response auth-param (rendered as a quoted-string).
      Parameters:
      value - The computed digest response. Must not be null.
      Returns:
      This object.
    • cnonce

      Sets the cnonce auth-param (rendered as a quoted-string).
      Parameters:
      value - The client nonce. Must not be null.
      Returns:
      This object.
    • opaque

      Sets the opaque auth-param (rendered as a quoted-string).
      Parameters:
      value - The opaque value echoed back from the challenge. Must not be null.
      Returns:
      This object.
    • algorithm

      Sets the algorithm auth-param (rendered as a bare token, unquoted).
      Parameters:
      value - The algorithm (e.g. "MD5", "SHA-256"). Must not be null.
      Returns:
      This object.
    • qop

      Sets the qop auth-param (rendered as a bare token, unquoted; a single value in credentials).
      Parameters:
      value - The quality-of-protection token (e.g. "auth"). Must not be null.
      Returns:
      This object.
    • nc

      Sets the nc (nonce-count) auth-param (rendered as a bare token, unquoted).
      Parameters:
      value - The 8-digit hex nonce-count (e.g. "00000001"). Must not be null.
      Returns:
      This object.
    • param

      Generic escape hatch for setting any auth-param by name, rendered as a quoted-string.

      Replaces any previously-registered value for the same param while preserving its original position, and clears any previously-set token68.

      Parameters:
      name - The auth-param name. Must not be null or blank.
      value - The auth-param value (quoted automatically). Must not be null.
      Returns:
      This object.
      Throws:
      IllegalArgumentException - If name is null or blank.
    • build

      public String build()
      Builds the rendered Proxy-Authorization credentials value.

      Returns an empty string when no scheme has been registered.

      Returns:
      The header value. Never null.
    • toHeader

      Builds a ProxyAuthorization header bean directly from this builder.
      Returns:
      A ProxyAuthorization carrying build(). Never null.
    • toString

      public String toString()
      Overrides:
      toString in class Object