wt.httpgw
Class AuthHandler

java.lang.Object
  extended bywt.httpgw.AuthHandler
All Implemented Interfaces:
HTTPClient.AuthorizationHandler

public class AuthHandler
extends Object
implements HTTPClient.AuthorizationHandler

A simple authorization handler that throws up a message box requesting both a username and password. This is default authorization handler. Currently only handles the authentication types "Basic" and "SOCKS5" (used for the SocksClient and not part of HTTP per se). This code is heavily based on 'MyAuthHandler' -- a part of the HTTPClient package.


Field Summary
private  BasicAuthBox inp
           
private  String password
           
private static String RESOURCE
           
private  String userName
           
 
Constructor Summary
AuthHandler()
           
 
Method Summary
static String ByteToHex(byte[] hash)
          Turns array of bytes into string representing each byte as unsigned hex number.
private static String calc_digest(HTTPClient.RoRequest req, String A1_hash, String nonce)
          Calculates the digest of the request body.
 HTTPClient.AuthorizationInfo fixupAuthInfo(HTTPClient.AuthorizationInfo info, HTTPClient.RoRequest req, HTTPClient.AuthorizationInfo challenge, HTTPClient.RoResponse resp)
          For Digest authentication we need to set the uri, response and opaque parameters.
 HTTPClient.AuthorizationInfo getAuthorization(HTTPClient.AuthorizationInfo challenge, HTTPClient.RoRequest req, HTTPClient.RoResponse resp)
          returns the requested authorization, or null if none was given.
private static void handle_digest(HTTPClient.AuthorizationInfo prev, HTTPClient.Response resp, HTTPClient.RoRequest req)
          Handle digest field of the Authentication-Info response header.
private static void handle_discard(HTTPClient.AuthorizationInfo prev, HTTPClient.HttpHeaderElement discard)
          Handle discard token
private static void handle_nextnonce(HTTPClient.AuthorizationInfo prev, HTTPClient.HttpHeaderElement nextnonce)
          Handle nextnonce field.
 void handleAuthHeaders(HTTPClient.Response resp, HTTPClient.RoRequest req, HTTPClient.AuthorizationInfo prev, HTTPClient.AuthorizationInfo prxy)
          We handle the "Authentication-info" and "Proxy-Authentication-info" headers here.
private static void handleAuthInfo(String auth_info, String prxy_info, HTTPClient.AuthorizationInfo prev, HTTPClient.AuthorizationInfo prxy, HTTPClient.Response resp, HTTPClient.RoRequest req, boolean in_headers)
           
 void handleAuthTrailers(HTTPClient.Response resp, HTTPClient.RoRequest req, HTTPClient.AuthorizationInfo prev, HTTPClient.AuthorizationInfo prxy)
          We handle the "Authentication-info" and "Proxy-Authentication-info" trailers here.
(package private) static HTTPClient.NVPair[] resizeArray(HTTPClient.NVPair[] src, int new_size)
           
 void setPassword(String password)
           
 void setUserName(String user_name)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

inp

private BasicAuthBox inp

RESOURCE

private static final String RESOURCE
See Also:
Constant Field Values

userName

private String userName

password

private String password
Constructor Detail

AuthHandler

public AuthHandler()
Method Detail

setUserName

public void setUserName(String user_name)

setPassword

public void setPassword(String password)

fixupAuthInfo

public HTTPClient.AuthorizationInfo fixupAuthInfo(HTTPClient.AuthorizationInfo info,
                                                  HTTPClient.RoRequest req,
                                                  HTTPClient.AuthorizationInfo challenge,
                                                  HTTPClient.RoResponse resp)
                                           throws HTTPClient.AuthSchemeNotImplException
For Digest authentication we need to set the uri, response and opaque parameters. For "Basic" and "SOCKS5" nothing is done.

Specified by:
fixupAuthInfo in interface HTTPClient.AuthorizationHandler
Throws:
HTTPClient.AuthSchemeNotImplException

getAuthorization

public HTTPClient.AuthorizationInfo getAuthorization(HTTPClient.AuthorizationInfo challenge,
                                                     HTTPClient.RoRequest req,
                                                     HTTPClient.RoResponse resp)
                                              throws HTTPClient.AuthSchemeNotImplException
returns the requested authorization, or null if none was given.

Specified by:
getAuthorization in interface HTTPClient.AuthorizationHandler
Parameters:
challenge - the parsed challenge from the server.
req - the request which solicited this response
resp - the full response received
Returns:
a structure containing the necessary authorization info, or null
Throws:
HTTPClient.AuthSchemeNotImplException - if the authentication scheme in the challenge cannot be handled.

handleAuthHeaders

public void handleAuthHeaders(HTTPClient.Response resp,
                              HTTPClient.RoRequest req,
                              HTTPClient.AuthorizationInfo prev,
                              HTTPClient.AuthorizationInfo prxy)
                       throws IOException
We handle the "Authentication-info" and "Proxy-Authentication-info" headers here.

Specified by:
handleAuthHeaders in interface HTTPClient.AuthorizationHandler
Throws:
IOException

handleAuthTrailers

public void handleAuthTrailers(HTTPClient.Response resp,
                               HTTPClient.RoRequest req,
                               HTTPClient.AuthorizationInfo prev,
                               HTTPClient.AuthorizationInfo prxy)
                        throws IOException
We handle the "Authentication-info" and "Proxy-Authentication-info" trailers here.

Specified by:
handleAuthTrailers in interface HTTPClient.AuthorizationHandler
Throws:
IOException

handleAuthInfo

private static void handleAuthInfo(String auth_info,
                                   String prxy_info,
                                   HTTPClient.AuthorizationInfo prev,
                                   HTTPClient.AuthorizationInfo prxy,
                                   HTTPClient.Response resp,
                                   HTTPClient.RoRequest req,
                                   boolean in_headers)
                            throws HTTPClient.ParseException,
                                   IOException
Throws:
HTTPClient.ParseException
IOException

handle_nextnonce

private static void handle_nextnonce(HTTPClient.AuthorizationInfo prev,
                                     HTTPClient.HttpHeaderElement nextnonce)
Handle nextnonce field.


handle_digest

private static void handle_digest(HTTPClient.AuthorizationInfo prev,
                                  HTTPClient.Response resp,
                                  HTTPClient.RoRequest req)
                           throws IOException
Handle digest field of the Authentication-Info response header.

Throws:
IOException

calc_digest

private static String calc_digest(HTTPClient.RoRequest req,
                                  String A1_hash,
                                  String nonce)
Calculates the digest of the request body.


handle_discard

private static void handle_discard(HTTPClient.AuthorizationInfo prev,
                                   HTTPClient.HttpHeaderElement discard)
Handle discard token


resizeArray

static final HTTPClient.NVPair[] resizeArray(HTTPClient.NVPair[] src,
                                             int new_size)

ByteToHex

public static String ByteToHex(byte[] hash)
Turns array of bytes into string representing each byte as unsigned hex number.

Parameters:
hash - Array of bytes to convert to hex-string
Returns:
Generated hex string