Class DigestAuthenticator

java.lang.Object
org.glassfish.jersey.client.authentication.DigestAuthenticator

final class DigestAuthenticator extends Object
Implementation of Digest Http Authentication method (RFC 2617).
  • Field Details

  • Constructor Details

    • DigestAuthenticator

      DigestAuthenticator(HttpAuthenticationFilter.Credentials credentials, int limit)
      Create a new instance initialized from credentials and configuration.
      Parameters:
      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.
  • Method Details

    • filterRequest

      boolean filterRequest(javax.ws.rs.client.ClientRequestContext request) throws IOException
      Process request and add authentication information if possible.
      Parameters:
      request - Request context.
      Returns:
      true if 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:
      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:
      IOException - When error with encryption occurs.
    • parseAuthHeaders

      private DigestAuthenticator.DigestScheme parseAuthHeaders(List<?> headers) throws IOException
      Parse digest header.
      Parameters:
      headers - List of header strings
      Returns:
      DigestScheme or null if 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 instance
      requestContext - client request context
      Returns:
      digest authentication token string
      Throws:
      IOException
    • append

      private static void append(StringBuilder sb, String key, String value, boolean useQuote)
      Append comma separated key=value token
      Parameters:
      sb - string builder instance
      key - key string
      value - value string
      useQuote - true if value needs to be enclosed in quotes
    • append

      private static void append(StringBuilder sb, String key, String value)
      Append comma separated key=value token. The value gets enclosed in quotes.
      Parameters:
      sb - string builder instance
      key - key string
      value - value string
    • bytesToHex

      private static String bytesToHex(byte[] bytes)
      Convert bytes array to hex string.
      Parameters:
      bytes - array of bytes
      Returns:
      hex string
    • md5

      private static String md5(String... tokens) throws IOException
      Colon separated value MD5 hash.
      Parameters:
      tokens - one or more strings
      Returns:
      M5 hash string
      Throws:
      IOException
    • randomBytes

      private 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