Class DigestAuthenticator
- java.lang.Object
-
- org.glassfish.jersey.client.authentication.DigestAuthenticator
-
final class DigestAuthenticator extends java.lang.Object
Implementation of Digest Http Authentication method (RFC 2617).
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static class
DigestAuthenticator.Algorithm
(package private) class
DigestAuthenticator.DigestScheme
Digest scheme POJOprivate static class
DigestAuthenticator.QOP
-
Field Summary
Fields Modifier and Type Field 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 Summary
Constructors Constructor Description DigestAuthenticator(HttpAuthenticationFilter.Credentials credentials, int limit)
Create a new instance initialized from credentials and configuration.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method 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 tokenprivate 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
-
-
-
Field Detail
-
HEX_ARRAY
private static final char[] HEX_ARRAY
-
KEY_VALUE_PAIR_PATTERN
private static final java.util.regex.Pattern KEY_VALUE_PAIR_PATTERN
-
CLIENT_NONCE_BYTE_COUNT
private static final int CLIENT_NONCE_BYTE_COUNT
- See Also:
- Constant Field Values
-
randomGenerator
private final java.security.SecureRandom randomGenerator
-
credentials
private final HttpAuthenticationFilter.Credentials credentials
-
digestCache
private final java.util.Map<java.net.URI,DigestAuthenticator.DigestScheme> digestCache
-
-
Constructor Detail
-
DigestAuthenticator
DigestAuthenticator(HttpAuthenticationFilter.Credentials credentials, int limit)
Create a new instance initialized from credentials and configuration.- Parameters:
credentials
- Credentials. Can benull
if there are no default credentials.limit
- Maximum number of URIs that should be kept in the cache containing URIs and theirDigestAuthenticator.DigestScheme
.
-
-
Method Detail
-
filterRequest
boolean filterRequest(javax.ws.rs.client.ClientRequestContext request) throws java.io.IOException
Process request and add authentication information if possible.- Parameters:
request
- Request context.- Returns:
true
if authentication information was added.- Throws:
java.io.IOException
- When error with encryption occurs.
-
filterResponse
public boolean filterResponse(javax.ws.rs.client.ClientRequestContext request, javax.ws.rs.client.ClientResponseContext response) throws java.io.IOException
Process response and repeat the request if digest authentication is requested. When request is repeated the response will be modified to contain new response information.- Parameters:
request
- Request context.response
- Response context (will be updated with newest response data if the request was repeated).- Returns:
true
if response does not require authentication or if authentication is required, new request was done with digest authentication information and authentication was successful.- Throws:
java.io.IOException
- When error with encryption occurs.
-
parseAuthHeaders
private DigestAuthenticator.DigestScheme parseAuthHeaders(java.util.List<?> headers) throws java.io.IOException
Parse digest header.- Parameters:
headers
- List of header strings- Returns:
- DigestScheme or
null
if no digest header exists. - Throws:
java.io.IOException
-
createNextAuthToken
private java.lang.String createNextAuthToken(DigestAuthenticator.DigestScheme ds, javax.ws.rs.client.ClientRequestContext requestContext, HttpAuthenticationFilter.Credentials credentials) throws java.io.IOException
Creates digest string including counter.- Parameters:
ds
- DigestScheme instancerequestContext
- client request context- Returns:
- digest authentication token string
- Throws:
java.io.IOException
-
append
private static void append(java.lang.StringBuilder sb, java.lang.String key, java.lang.String value, boolean useQuote)
Append comma separated key=value token- Parameters:
sb
- string builder instancekey
- key stringvalue
- value stringuseQuote
- true if value needs to be enclosed in quotes
-
append
private static void append(java.lang.StringBuilder sb, java.lang.String key, java.lang.String value)
Append comma separated key=value token. The value gets enclosed in quotes.- Parameters:
sb
- string builder instancekey
- key stringvalue
- value string
-
bytesToHex
private static java.lang.String bytesToHex(byte[] bytes)
Convert bytes array to hex string.- Parameters:
bytes
- array of bytes- Returns:
- hex string
-
md5
private static java.lang.String md5(java.lang.String... tokens) throws java.io.IOException
Colon separated value MD5 hash.- Parameters:
tokens
- one or more strings- Returns:
- M5 hash string
- Throws:
java.io.IOException
-
randomBytes
private java.lang.String randomBytes(int nbBytes)
Generate a random sequence of bytes and return its hex representation- Parameters:
nbBytes
- number of bytes to generate- Returns:
- hex string
-
-