org.apache.commons.httpclient.auth
Class DigestScheme

java.lang.Object
  |
  +--org.apache.commons.httpclient.auth.AuthSchemeBase
        |
        +--org.apache.commons.httpclient.auth.RFC2617Scheme
              |
              +--org.apache.commons.httpclient.auth.DigestScheme

public class DigestScheme
extends RFC2617Scheme

Digest authentication scheme as defined in RFC 2617.

Author:
Remy Maucherat, Rodney Waldhoff, Jeff Dever, Ortwin Gl?ck, Sean C. Sullivan, Adrian Sutton, Mike Bowler, Oleg Kalnichevski

Constructor Summary
DigestScheme(java.lang.String challenge)
          Constructor for the digest authentication scheme.
 
Method Summary
 java.lang.String authenticate(Credentials credentials, java.lang.String method, java.lang.String uri)
          Produces a digest authorization string for the given set of Credentials, method name and URI.
static java.lang.String authenticate(UsernamePasswordCredentials credentials, java.util.Map params)
          Produces a digest authorization string for the given set of UsernamePasswordCredentials and authetication parameters.
static java.lang.String createCnonce()
          Creates a random cnonce value based on the current time.
static java.lang.String createDigest(java.lang.String uname, java.lang.String pwd, java.util.Map params)
          Creates an MD5 response digest.
static java.lang.String createDigestHeader(java.lang.String uname, java.util.Map params, java.lang.String digest)
          Creates digest-response header as defined in RFC2617.
 java.lang.String getID()
          Gets an ID based upon the realm and the nonce value.
 java.lang.String getSchemeName()
          Returns textual designation of the digest authentication scheme.
 
Methods inherited from class org.apache.commons.httpclient.auth.RFC2617Scheme
getParameter, getParameters, getRealm
 
Methods inherited from class org.apache.commons.httpclient.auth.AuthSchemeBase
equals, hashCode, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DigestScheme

public DigestScheme(java.lang.String challenge)
             throws MalformedChallengeException
Constructor for the digest authentication scheme.
Parameters:
challenge - The authentication challenge
Throws:
MalformedChallengeException - is thrown if the authentication challenge is malformed
Method Detail

getID

public java.lang.String getID()
Gets an ID based upon the realm and the nonce value. This ensures that requests to the same realm with different nonce values will succeed. This differentiation allows servers to request re-authentication using a fresh nonce value.
Overrides:
getID in class RFC2617Scheme
Returns:
the realm plus the nonce value, if present

getSchemeName

public java.lang.String getSchemeName()
Returns textual designation of the digest authentication scheme.
Returns:
digest

authenticate

public java.lang.String authenticate(Credentials credentials,
                                     java.lang.String method,
                                     java.lang.String uri)
                              throws AuthenticationException
Produces a digest authorization string for the given set of Credentials, method name and URI.
Parameters:
credentials - A set of credentials to be used for athentication
method - the name of the method that requires authorization.
uri - The URI for which authorization is needed.
Returns:
a digest authorization string
Throws:
AuthenticationException - if authorization string cannot be generated due to an authentication failure
See Also:
HttpMethod.getName(), HttpMethod.getPath()

authenticate

public static java.lang.String authenticate(UsernamePasswordCredentials credentials,
                                            java.util.Map params)
                                     throws AuthenticationException
Produces a digest authorization string for the given set of UsernamePasswordCredentials and authetication parameters.
Parameters:
credentials - Credentials to create the digest with
params - The authetication parameters. The following parameters are expected: uri, realm, nonce, nc, cnonce, qop, methodname.
Returns:
a digest authorization string
Throws:
AuthenticationException - if authorization string cannot be generated due to an authentication failure

createDigest

public static java.lang.String createDigest(java.lang.String uname,
                                            java.lang.String pwd,
                                            java.util.Map params)
                                     throws AuthenticationException
Creates an MD5 response digest.
Parameters:
uname - Username
pwd - Password
params - The parameters necessary to construct the digest. The following parameters are expected: uri, realm, nonce, nc, cnonce, qop, methodname.
Returns:
The created digest as string. This will be the response tag's value in the Authentication HTTP header.
Throws:
AuthenticationException - when MD5 is an unsupported algorithm

createDigestHeader

public static java.lang.String createDigestHeader(java.lang.String uname,
                                                  java.util.Map params,
                                                  java.lang.String digest)
Creates digest-response header as defined in RFC2617.
Parameters:
uname - Username
params - The parameters necessary to construct the digest header. The following parameters are expected: uri, realm, nonce, nc, cnonce, qop, methodname.
digest - The response tag's value as String.
Returns:
The digest-response as String.

createCnonce

public static java.lang.String createCnonce()
                                     throws AuthenticationException
Creates a random cnonce value based on the current time.
Returns:
The cnonce value as String.
Throws:
AuthenticationException - if MD5 algorithm is not supported.


Copyright © 2001-2004 Apache Software Foundation. All Rights Reserved.