com.funambol.util
Class HttpDigestAuthentication

java.lang.Object
  extended by com.funambol.util.HttpDigestAuthentication
All Implemented Interfaces:
HttpAuthentication

public class HttpDigestAuthentication
extends java.lang.Object
implements HttpAuthentication

An authentication object for http digest authentication.


Constructor Summary
HttpDigestAuthentication(java.lang.String user, java.lang.String pass, java.lang.String authUri)
          Create the digest authentication object with a username, password, and uri.
 
Method Summary
static java.lang.String calculateHa1(java.lang.String username, java.lang.String password, java.lang.String realm)
          Calculate ha1 given a username, realm, and password.
static java.lang.String calculateHa2(java.lang.String uri)
          Calculate ha2 given a uri.
static java.lang.String calculateResponse(java.lang.String ha1, java.lang.String ha2, java.lang.String nonce, java.lang.String qop, java.lang.String cnonce, java.lang.String nc)
          Calculate the response given ha1 and ha2.
static java.lang.String extractDigestProp(java.lang.String str, java.lang.String prop)
          Extract a specific property from a string of property value pairs separated by '='
protected  java.lang.String generateAuthResponseString()
          Generate an authentication response of digest properties and values.
protected  java.lang.String generateAuthResponseString(java.lang.Long seed)
          Generate an authentication response of digest properties and values, given a seed to generate a client nonce.
 boolean getRetryWithAuth()
          Return whether or not to retry requests with authentication information.
 boolean handleAuthentication(HttpConnectionAdapter c)
          Set the authentication property in the given HTTP connection.
protected  boolean processAuthInfo(java.lang.String info)
          Process the given authentication information.
 boolean processHttpError(HttpConnectionAdapter c)
          Check the given connection for a 401 HTTP error and process any authentication information that is present.
 void setPassword(java.lang.String value)
          Set the password for the authentication.
 void setUri(java.lang.String value)
          Set the URI to authenticate against.
 void setUsername(java.lang.String value)
          Set the username of the client being authenticated.
static java.lang.String toHex(byte[] hash)
          Convert a hash to a hexadecimal number.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HttpDigestAuthentication

public HttpDigestAuthentication(java.lang.String user,
                                java.lang.String pass,
                                java.lang.String authUri)
Create the digest authentication object with a username, password, and uri.

Parameters:
username - The username of the client being authenticated
password - The password for the client being authenticated
uri - The uri to authenticate against
Method Detail

extractDigestProp

public static java.lang.String extractDigestProp(java.lang.String str,
                                                 java.lang.String prop)
Extract a specific property from a string of property value pairs separated by '='

Parameters:
str - The string of properties
prop - The property to extract
Returns:
The value of the property, if it exists

toHex

public static final java.lang.String toHex(byte[] hash)
Convert a hash to a hexadecimal number.

Parameters:
hash - The byte array hash to convert
Returns:
The byte array in hexadecimal format

generateAuthResponseString

protected java.lang.String generateAuthResponseString()
Generate an authentication response of digest properties and values.

Returns:
An authentication response.

generateAuthResponseString

protected java.lang.String generateAuthResponseString(java.lang.Long seed)
Generate an authentication response of digest properties and values, given a seed to generate a client nonce.

Returns:
An authentication response

processAuthInfo

protected boolean processAuthInfo(java.lang.String info)
Process the given authentication information.

Parameters:
info - The authentication string of digest properties and values
Returns:
Whether or not the given info contained digest authentication information

handleAuthentication

public boolean handleAuthentication(HttpConnectionAdapter c)
                             throws java.io.IOException
Set the authentication property in the given HTTP connection.

Specified by:
handleAuthentication in interface HttpAuthentication
Parameters:
c - The connection on which the authentication information is being set
Returns:
Whether or not the authentication property was set for the given HTTP connection
Throws:
java.io.IOException

processHttpError

public boolean processHttpError(HttpConnectionAdapter c)
                         throws java.io.IOException
Check the given connection for a 401 HTTP error and process any authentication information that is present.

Specified by:
processHttpError in interface HttpAuthentication
Parameters:
c - The connection to check for and process HTTP errors.
Returns:
Whether or not an error was processed.
Throws:
java.io.IOException

calculateHa1

public static java.lang.String calculateHa1(java.lang.String username,
                                            java.lang.String password,
                                            java.lang.String realm)
Calculate ha1 given a username, realm, and password.

Parameters:
username - The username of the user being authenticated
realm - The authentication realm
password - The password of the user being authenticated
Returns:
A calculated ha1.

calculateHa2

public static java.lang.String calculateHa2(java.lang.String uri)
Calculate ha2 given a uri.

Parameters:
uri - The uri to authenticate against.
Returns:
A calculated ha2

calculateResponse

public static java.lang.String calculateResponse(java.lang.String ha1,
                                                 java.lang.String ha2,
                                                 java.lang.String nonce,
                                                 java.lang.String qop,
                                                 java.lang.String cnonce,
                                                 java.lang.String nc)
Calculate the response given ha1 and ha2.

Parameters:
ha1 - A calculated ha1 value
ha2 - A calculated ha2 value
cnonce - The client nonce
nc - The nonce count
Returns:
A calculated response

getRetryWithAuth

public boolean getRetryWithAuth()
Return whether or not to retry requests with authentication information.

Specified by:
getRetryWithAuth in interface HttpAuthentication
Returns:
Whether or not to retry requests

setUsername

public void setUsername(java.lang.String value)
Set the username of the client being authenticated.

Specified by:
setUsername in interface HttpAuthentication
Parameters:
value - The username to authenticate with

setPassword

public void setPassword(java.lang.String value)
Set the password for the authentication.

Specified by:
setPassword in interface HttpAuthentication
Parameters:
value - The password to authenticate with

setUri

public void setUri(java.lang.String value)
Set the URI to authenticate against.

Specified by:
setUri in interface HttpAuthentication
Parameters:
value - The URI to authenticate against


Copyright © 2001-2009 Funambol.