@Provider public class HttpDigestAuthFilter extends Object implements javax.ws.rs.client.ClientRequestFilter, javax.ws.rs.client.ClientResponseFilter
This filter is the main class that adds a support for Http Digest Authentication on the client.
In order to use this filter, create an instance of the filter and register it to the client.
Example:
// create a filter instance and initiate it with username and password
final HttpDigestAuthFilter digestFilter = new HttpDigestAuthFilter("adam", "pwd87654");
// register the filter into the client (in this case using ClientBuilder)
Client client = ClientBuilder.newBuilder().register(digestFilter).build();
// make request (authentication will be managed by filter during the request if needed)
final Response response = client.target("http://example.com/users/adam/age").request().get();
Filter firstly tries to perform request without authentication. If authentication is needed and
401 status code is returned, filter use information from WWW-Authenticate header to
construct the digest header and retries the request with Authentication header. The
Authentication header will be stored for the current URI and used next time with nonce
value increased (if nonce is defined). The number of cached URIs can be defined by a
property ClientProperties.DIGESTAUTH_URI_CACHE_SIZELIMIT.
Note: The filter must be registered only into the Client. Filter will not work
correctly when it is registered to WebTarget, Invocation.Builder or
Invocation.
| Constructor and Description |
|---|
HttpDigestAuthFilter(String username,
String password)
Create a new HTTP Basic Authentication filter using provided
username
and password string credentials. |
public HttpDigestAuthFilter(String username, String password)
username
and password string credentials. The string password will be internally
stored as a byte array, so that using this constructor does introduce the security risk
of keeping password as a reference to String.username - user namepassword - passwordpublic void filter(javax.ws.rs.client.ClientRequestContext requestContext)
throws IOException
filter in interface javax.ws.rs.client.ClientRequestFilterIOExceptionpublic void filter(javax.ws.rs.client.ClientRequestContext requestContext,
javax.ws.rs.client.ClientResponseContext responseContext)
throws IOException
filter in interface javax.ws.rs.client.ClientResponseFilterIOExceptionCopyright © 2007-2013, Oracle and/or its affiliates. All Rights Reserved. Use is subject to license terms.