Class AuthenticationException

All Implemented Interfaces:
Serializable, HttpResponseMessage

Specialization of Unauthorized thrown by BearerTokenGuard, ApiKeyGuard, and user-supplied TokenValidator / ApiKeyStore implementations to signal AuthN failure.

Behaves like a plain 401 Unauthorized from the wire's perspective — same status code, same reason phrase, same JSON / problem-details body shape — but adds a typed wwwAuthenticate(String) fluent setter that returns AuthenticationException (instead of the generic BasicHttpException returned by the inherited setHeader(...) chain) so authoring AuthN guards stays terse:

throw new AuthenticationException("Bearer token missing") .wwwAuthenticate("Bearer realm=\"api\"");

The WWW-Authenticate response header is mandated by RFC 7235 §4.1 for every 401 response — clients use the challenge string to discover which authentication schemes the server supports and to format their next request. AuthN guards in this package set it on every rejection.

See Also:
Since:
10.0.0
See Also:
  • Constructor Details

    • AuthenticationException

      Constructor with no message.
    • AuthenticationException

      public AuthenticationException(String msg, Object... args)
      Constructor with a String.format-style message.
      Parameters:
      msg - The detail message. May be null. Treated as a format pattern when args is non-empty.
      args - Optional message arguments.
    • AuthenticationException

      Constructor with a cause.
      Parameters:
      cause - The cause. May be null.
    • AuthenticationException

      public AuthenticationException(Throwable cause, String msg, Object... args)
      Constructor with a cause and a String.format-style message.
      Parameters:
      cause - The cause. May be null.
      msg - The detail message. May be null. Treated as a format pattern when args is non-empty.
      args - Optional message arguments.
  • Method Details

    • wwwAuthenticate

      Sets the WWW-Authenticate response header to the supplied challenge string.

      Per RFC 7235 §4.1, the challenge identifies the authentication scheme(s) the server accepts and any scheme-specific parameters (e.g. realm). Examples:

      • Bearer realm="api"
      • Bearer realm="api", error="invalid_token", error_description="The access token expired"
      • ApiKey realm="api"
      Parameters:
      value - The WWW-Authenticate challenge value. Must not be null.
      Returns:
      This object.