Class ProxyDigestAuthenticator

java.lang.Object
org.glassfish.jersey.jdk.connector.internal.ProxyDigestAuthenticator

class ProxyDigestAuthenticator extends Object
Generates a value of Authorization header of HTTP request for Digest Http Authentication scheme (RFC 2617).
  • Field Details

    • CHARACTER_SET

      private static final Charset CHARACTER_SET
      Encoding used for authentication calculations.
    • logger

      private static final Logger logger
    • HEX_ARRAY

      private static final char[] HEX_ARRAY
    • KEY_VALUE_PAIR_PATTERN

      private static final Pattern KEY_VALUE_PAIR_PATTERN
    • CLIENT_NONCE_BYTE_COUNT

      private static final int CLIENT_NONCE_BYTE_COUNT
      See Also:
    • randomGenerator

      private SecureRandom randomGenerator
  • Constructor Details

    • ProxyDigestAuthenticator

      ProxyDigestAuthenticator()
  • Method Details

    • generateAuthorizationHeader

      String generateAuthorizationHeader(URI uri, String method, String authenticateHeader, String userName, String password) throws ProxyAuthenticationException
      Throws:
      ProxyAuthenticationException
    • parseAuthHeaders

      private ProxyDigestAuthenticator.DigestScheme parseAuthHeaders(String authHeader) throws IOException
      Parse digest header.
      Parameters:
      authHeader - value of WWW-Authenticate header
      Returns:
      DigestScheme or null if no digest header exists.
      Throws:
      IOException
    • createNextAuthToken

      private String createNextAuthToken(ProxyDigestAuthenticator.DigestScheme ds, String uri, String method, String userName, String password) throws ProxyAuthenticationException
      Creates digest string including counter.
      Parameters:
      ds - DigestScheme instance
      uri - client request uri
      Returns:
      digest authentication token string
      Throws:
      ProxyAuthenticationException - if MD5 hash fails
    • 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 ProxyAuthenticationException
      Colon separated value MD5 hash.
      Parameters:
      tokens - one or more strings
      Returns:
      M5 hash string
      Throws:
      ProxyAuthenticationException - if MD5 algorithm cannot be instantiated
    • 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