Class AuthenticationException
- All Implemented Interfaces:
Serializable,HttpResponseMessage
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:
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:
-
Nested Class Summary
Nested classes/interfaces inherited from class org.apache.juneau.http.response.Unauthorized
Unauthorized.Unmodifiable -
Field Summary
Fields inherited from class org.apache.juneau.http.response.Unauthorized
REASON_PHRASE, STATUS_CODE -
Constructor Summary
ConstructorsConstructorDescriptionConstructor with no message.AuthenticationException(String msg, Object... args) Constructor with aString.format-style message.AuthenticationException(Throwable cause) Constructor with a cause.AuthenticationException(Throwable cause, String msg, Object... args) Constructor with a cause and aString.format-style message. -
Method Summary
Modifier and TypeMethodDescriptionwwwAuthenticate(String value) Sets theWWW-Authenticateresponse header to the supplied challenge string.Methods inherited from class org.apache.juneau.http.response.Unauthorized
unmodifiableMethods inherited from class org.apache.juneau.http.response.BasicHttpException
addHeader, addHeader, equals, freeze, getBody, getFullStackMessage, getHeaders, getLocale, getMessage, getRootCause, getStatusCode, getStatusLine, hashCode, isUnmodifiable, modify, setBody, setContent, setContent, setHeader, setHeader, setHeaders, setHeaders, setLocale, setProtocolVersion, setReasonPhrase, setStatusCode, setStatusLine, toStringMethods inherited from class java.lang.Throwable
addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTraceMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.apache.juneau.http.response.HttpResponseMessage
getFirstHeader, getHeaders
-
Constructor Details
-
AuthenticationException
public AuthenticationException()Constructor with no message. -
AuthenticationException
Constructor with aString.format-style message.- Parameters:
msg- The detail message. May benull . Treated as a format pattern whenargsis non-empty.args- Optional message arguments.
-
AuthenticationException
Constructor with a cause.- Parameters:
cause- The cause. May benull .
-
AuthenticationException
Constructor with a cause and aString.format-style message.- Parameters:
cause- The cause. May benull .msg- The detail message. May benull . Treated as a format pattern whenargsis non-empty.args- Optional message arguments.
-
-
Method Details
-
wwwAuthenticate
Sets theWWW-Authenticateresponse 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- TheWWW-Authenticatechallenge value. Must not benull .- Returns:
- This object.
-