public final class WwwAuthenticateHeader
extends java.lang.Object
WWW-Authenticate
headers.
The WWW-Authenticate
header is described in
Section 4.1 of RFC 7235. It can
contain one or more challenges and it can appear multiple times in each response.
Example: The following header:
WWW-Authenticate: Newauth realm="apps", type=1, title="Login to \"apps\"", Basic realm="simple"contains two challenges,
Newauth realm="apps", type=1, title="Login to \"apps\""
and
Basic realm="simple"
.
This class is not specific for digest authentication. It returns the challenges as strings and can extract challenges of any type.
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
HTTP_HEADER_WWW_AUTHENTICATE
Name of the HTTP response header WWW-Authenticate.
|
Modifier and Type | Method and Description |
---|---|
static java.util.List<java.lang.String> |
extractChallenges(java.net.HttpURLConnection connection)
Extracts challenges from an HTTP response.
|
static java.util.List<java.lang.String> |
extractChallenges(java.lang.Iterable<java.lang.String> wwwAuthenticateHeaders)
Extracts challenges from a set of
WWW-Authenticate HTTP headers. |
static <T extends java.lang.Iterable<java.lang.String>> |
extractChallenges(java.util.Map<java.lang.String,T> headers)
Extracts challenges from a map of HTTP headers.
|
static java.util.List<java.lang.String> |
extractChallenges(java.lang.String wwwAuthenticateHeader)
Extracts challenges from a
WWW-Authenticate header. |
public static final java.lang.String HTTP_HEADER_WWW_AUTHENTICATE
public static java.util.List<java.lang.String> extractChallenges(java.net.HttpURLConnection connection) throws ChallengeParseException
connection
- the connection the response will be read fromChallengeParseException
- if the challenges are malformed and could not be
parsedpublic static <T extends java.lang.Iterable<java.lang.String>> java.util.List<java.lang.String> extractChallenges(java.util.Map<java.lang.String,T> headers) throws ChallengeParseException
A note about the map representing the headers: header names are case insensitive in HTTP. This
means that the WWW-Authenticate
header can be represented in multiple
ways (WWW-Authenticate
, www-authenticate
, etc), even in the same
HTTP response. This method makes no assumption about the case of the headers, but two keys
in the map must not be equal if case is disregarded, that is, all case variations of
WWW-Authenticate
must be collected with the same key. Incidentally, this is
what is returned by HttpURLConnection.getHeaderFields()
.
headers
- the headers, as a map where the keys are header names and values are
iterables where each element is a header value stringChallengeParseException
- if the challenges are malformed and could not be
parsedpublic static java.util.List<java.lang.String> extractChallenges(java.lang.Iterable<java.lang.String> wwwAuthenticateHeaders) throws ChallengeParseException
WWW-Authenticate
HTTP headers.wwwAuthenticateHeaders
- the header valuesChallengeParseException
- if the challenges are malformed and could not be
parsedpublic static java.util.List<java.lang.String> extractChallenges(java.lang.String wwwAuthenticateHeader) throws ChallengeParseException
WWW-Authenticate
header.wwwAuthenticateHeader
- the header valueChallengeParseException
- if the challenges are malformed and could not be
parsed