Class DigestAuthenticator
- java.lang.Object
-
- org.glassfish.jersey.client.authentication.DigestAuthenticator
-
final class DigestAuthenticator extends java.lang.ObjectImplementation of Digest Http Authentication method (RFC 2617).
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static classDigestAuthenticator.Algorithm(package private) classDigestAuthenticator.DigestSchemeDigest scheme POJOprivate static classDigestAuthenticator.QOP
-
Field Summary
Fields Modifier and Type Field Description private static intCLIENT_NONCE_BYTE_COUNTprivate HttpAuthenticationFilter.Credentialscredentialsprivate java.util.Map<java.net.URI,DigestAuthenticator.DigestScheme>digestCacheprivate static char[]HEX_ARRAYprivate static java.util.regex.PatternKEY_VALUE_PAIR_PATTERNprivate java.security.SecureRandomrandomGenerator
-
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 voidappend(java.lang.StringBuilder sb, java.lang.String key, java.lang.String value)Append comma separated key=value token.private static voidappend(java.lang.StringBuilder sb, java.lang.String key, java.lang.String value, boolean useQuote)Append comma separated key=value tokenprivate static java.lang.StringbytesToHex(byte[] bytes)Convert bytes array to hex string.private java.lang.StringcreateNextAuthToken(DigestAuthenticator.DigestScheme ds, javax.ws.rs.client.ClientRequestContext requestContext, HttpAuthenticationFilter.Credentials credentials)Creates digest string including counter.(package private) booleanfilterRequest(javax.ws.rs.client.ClientRequestContext request)Process request and add authentication information if possible.booleanfilterResponse(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.Stringmd5(java.lang.String... tokens)Colon separated value MD5 hash.private DigestAuthenticator.DigestSchemeparseAuthHeaders(java.util.List<?> headers)Parse digest header.private java.lang.StringrandomBytes(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 benullif 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.IOExceptionProcess request and add authentication information if possible.- Parameters:
request- Request context.- Returns:
trueif 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.IOExceptionProcess 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:
trueif 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
nullif 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.IOExceptionColon 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
-
-