final class DigestAuthenticator
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
(package private) static class |
DigestAuthenticator.Algorithm |
(package private) class |
DigestAuthenticator.DigestScheme
Digest scheme POJO
|
private static class |
DigestAuthenticator.QOP |
Modifier and Type | Field and Description |
---|---|
private static int |
CLIENT_NONCE_BYTE_COUNT |
private HttpAuthenticationFilter.Credentials |
credentials |
private java.util.Map<java.net.URI,DigestAuthenticator.DigestScheme> |
digestCache |
private static char[] |
HEX_ARRAY |
private static java.util.regex.Pattern |
KEY_VALUE_PAIR_PATTERN |
private java.security.SecureRandom |
randomGenerator |
Constructor and Description |
---|
DigestAuthenticator(HttpAuthenticationFilter.Credentials credentials,
int limit)
Create a new instance initialized from credentials and configuration.
|
Modifier and Type | Method and Description |
---|---|
private static void |
append(java.lang.StringBuilder sb,
java.lang.String key,
java.lang.String value)
Append comma separated key=value token.
|
private static void |
append(java.lang.StringBuilder sb,
java.lang.String key,
java.lang.String value,
boolean useQuote)
Append comma separated key=value token
|
private static java.lang.String |
bytesToHex(byte[] bytes)
Convert bytes array to hex string.
|
private java.lang.String |
createNextAuthToken(DigestAuthenticator.DigestScheme ds,
javax.ws.rs.client.ClientRequestContext requestContext,
HttpAuthenticationFilter.Credentials credentials)
Creates digest string including counter.
|
(package private) boolean |
filterRequest(javax.ws.rs.client.ClientRequestContext request)
Process request and add authentication information if possible.
|
boolean |
filterResponse(javax.ws.rs.client.ClientRequestContext request,
javax.ws.rs.client.ClientResponseContext response)
Process response and repeat the request if digest authentication is requested.
|
private static java.lang.String |
md5(java.lang.String... tokens)
Colon separated value MD5 hash.
|
private DigestAuthenticator.DigestScheme |
parseAuthHeaders(java.util.List<?> headers)
Parse digest header.
|
private java.lang.String |
randomBytes(int nbBytes)
Generate a random sequence of bytes and return its hex representation
|
private static final char[] HEX_ARRAY
private static final java.util.regex.Pattern KEY_VALUE_PAIR_PATTERN
private static final int CLIENT_NONCE_BYTE_COUNT
private final java.security.SecureRandom randomGenerator
private final HttpAuthenticationFilter.Credentials credentials
private final java.util.Map<java.net.URI,DigestAuthenticator.DigestScheme> digestCache
DigestAuthenticator(HttpAuthenticationFilter.Credentials credentials, int limit)
credentials
- Credentials. Can be null
if there are no default credentials.limit
- Maximum number of URIs that should be kept in the cache containing URIs and their
DigestAuthenticator.DigestScheme
.boolean filterRequest(javax.ws.rs.client.ClientRequestContext request) throws java.io.IOException
request
- Request context.true
if authentication information was added.java.io.IOException
- When error with encryption occurs.public boolean filterResponse(javax.ws.rs.client.ClientRequestContext request, javax.ws.rs.client.ClientResponseContext response) throws java.io.IOException
request
- Request context.response
- Response context (will be updated with newest response data if the request was repeated).true
if response does not require authentication or if authentication is required,
new request was done with digest authentication information and authentication was successful.java.io.IOException
- When error with encryption occurs.private DigestAuthenticator.DigestScheme parseAuthHeaders(java.util.List<?> headers) throws java.io.IOException
headers
- List of header stringsnull
if no digest header exists.java.io.IOException
private java.lang.String createNextAuthToken(DigestAuthenticator.DigestScheme ds, javax.ws.rs.client.ClientRequestContext requestContext, HttpAuthenticationFilter.Credentials credentials) throws java.io.IOException
ds
- DigestScheme instancerequestContext
- client request contextjava.io.IOException
private static void append(java.lang.StringBuilder sb, java.lang.String key, java.lang.String value, boolean useQuote)
sb
- string builder instancekey
- key stringvalue
- value stringuseQuote
- true if value needs to be enclosed in quotesprivate static void append(java.lang.StringBuilder sb, java.lang.String key, java.lang.String value)
sb
- string builder instancekey
- key stringvalue
- value stringprivate static java.lang.String bytesToHex(byte[] bytes)
bytes
- array of bytesprivate static java.lang.String md5(java.lang.String... tokens) throws java.io.IOException
tokens
- one or more stringsjava.io.IOException
private java.lang.String randomBytes(int nbBytes)
nbBytes
- number of bytes to generate