Class DigestAuthenticator
java.lang.Object
org.glassfish.jersey.client.authentication.DigestAuthenticator
Implementation of Digest Http Authentication method (RFC 2617).
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static enum(package private) final classDigest scheme POJOprivate static enum -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final intprivate final HttpAuthenticationFilter.Credentialsprivate final Map<URI, DigestAuthenticator.DigestScheme> private static final char[]private static final Patternprivate final SecureRandom -
Constructor Summary
ConstructorsConstructorDescriptionDigestAuthenticator(HttpAuthenticationFilter.Credentials credentials, int limit) Create a new instance initialized from credentials and configuration. -
Method Summary
Modifier and TypeMethodDescriptionprivate static voidappend(StringBuilder sb, String key, String value) Append comma separated key=value token.private static voidappend(StringBuilder sb, String key, String value, boolean useQuote) Append comma separated key=value tokenprivate static StringbytesToHex(byte[] bytes) Convert bytes array to hex string.private 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 StringColon separated value MD5 hash.private DigestAuthenticator.DigestSchemeparseAuthHeaders(List<?> headers) Parse digest header.private StringrandomBytes(int nbBytes) Generate a random sequence of bytes and return its hex representation
-
Field Details
-
HEX_ARRAY
private static final char[] HEX_ARRAY -
KEY_VALUE_PAIR_PATTERN
-
CLIENT_NONCE_BYTE_COUNT
private static final int CLIENT_NONCE_BYTE_COUNT- See Also:
-
randomGenerator
-
credentials
-
digestCache
-
-
Constructor Details
-
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 Details
-
filterRequest
Process request and add authentication information if possible.- Parameters:
request- Request context.- Returns:
trueif authentication information was added.- Throws:
IOException- When error with encryption occurs.
-
filterResponse
public boolean filterResponse(javax.ws.rs.client.ClientRequestContext request, javax.ws.rs.client.ClientResponseContext response) throws 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:
trueif response does not require authentication or if authentication is required, new request was done with digest authentication information and authentication was successful.- Throws:
IOException- When error with encryption occurs.
-
parseAuthHeaders
Parse digest header.- Parameters:
headers- List of header strings- Returns:
- DigestScheme or
nullif no digest header exists. - Throws:
IOException
-
createNextAuthToken
private String createNextAuthToken(DigestAuthenticator.DigestScheme ds, javax.ws.rs.client.ClientRequestContext requestContext, HttpAuthenticationFilter.Credentials credentials) throws IOException Creates digest string including counter.- Parameters:
ds- DigestScheme instancerequestContext- client request context- Returns:
- digest authentication token string
- Throws:
IOException
-
append
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
Append comma separated key=value token. The value gets enclosed in quotes.- Parameters:
sb- string builder instancekey- key stringvalue- value string
-
bytesToHex
Convert bytes array to hex string.- Parameters:
bytes- array of bytes- Returns:
- hex string
-
md5
Colon separated value MD5 hash.- Parameters:
tokens- one or more strings- Returns:
- M5 hash string
- Throws:
IOException
-
randomBytes
Generate a random sequence of bytes and return its hex representation- Parameters:
nbBytes- number of bytes to generate- Returns:
- hex string
-