|
|||||||||
| Home >> All >> [ HTTPClient overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
HTTPClient
Class AuthorizationInfo

java.lang.ObjectHTTPClient.AuthorizationInfo
- All Implemented Interfaces:
- java.lang.Cloneable, GlobalConstants
- public class AuthorizationInfo
- extends java.lang.Object
- implements GlobalConstants, java.lang.Cloneable
- extends java.lang.Object
Holds the information for an authorization response.
There are 7 fields which make up this class: host, port, scheme, realm, cookie, params, and extra_info. The host and port select which server the info will be sent to. The realm is server specified string which groups various URLs under a given server together and which is used to select the correct info when a server issues an auth challenge; for schemes which don't use a realm (such as "NTLM", "PEM", and "Kerberos") the realm must be the empty string (""). The scheme is the authorization scheme used (such as "Basic" or "Digest").
There are basically two formats used for the Authorization header, the one used by the "Basic" scheme and derivatives, and the one used by the "Digest" scheme and derivatives. The first form contains just the the scheme and a "cookie":
Authorization: Basic aGVsbG86d29ybGQ=The second form contains the scheme followed by a number of parameters in the form of name=value pairs:
Authorization: Digest username="hello", realm="test", nonce="42", ...The two fields "cookie" and "params" correspond to these two forms. toString() is used by the AuthorizationModule when generating the Authorization header and will format the info accordingly. Note that "cookie" and "params" are mutually exclusive: if the cookie field is non-null then toString() will generate the first form; otherwise it will generate the second form.
In some schemes "extra" information needs to be kept which doesn't appear directly in the Authorization header. An example of this are the A1 and A2 strings in the Digest scheme. Since all elements in the params field will appear in the Authorization header this field can't be used for storing such info. This is what the extra_info field is for. It is an arbitrary object which can be manipulated by the corresponding setExtraInfo() and getExtraInfo() methods, but which will not be printed by toString().
The addXXXAuthorization(), removeXXXAuthorization(), and getAuthorization() methods manipulate and query an internal list of AuthorizationInfo instances. There can be only one instance per host, port, scheme, and realm combination (see equals()).
- Since:
- V0.1
- Version:
- 0.3-2 18/06/1999
| Field Summary | |
private NVPair[] |
auth_params
any parameters |
private static AuthorizationHandler |
AuthHandler
A pointer to the handler to be called when we need authorization info |
static int |
CD_0
|
static int |
CD_CHUNKED
|
static int |
CD_CLOSE
|
static int |
CD_CONTLEN
|
static int |
CD_HDRS
|
static int |
CD_MP_BR
|
static int |
CD_NONE
Content delimiters |
private static java.util.Hashtable |
CntxtList
Holds the list of lists of authorization info structures |
private java.lang.String |
cookie
the string used for the "Basic", "NTLM", and other authorization schemes which don't use parameters |
static boolean |
DebugAll
Debug variables |
static boolean |
DebugAuth
|
static boolean |
DebugConn
|
static boolean |
DebugDemux
|
static boolean |
DebugMods
|
static boolean |
DebugResp
|
static boolean |
DebugSocks
|
static boolean |
DebugURLC
|
private java.lang.Object |
extra_info
additional info which won't be displayed in the toString() |
private java.lang.String |
host
the host (lowercase) |
static int |
HTTP
possible http protocols we (might) handle |
static int |
HTTP_1_0
some known http versions |
static int |
HTTP_1_1
|
static int |
HTTP_NG
|
static int |
HTTPS
|
private java.lang.String[] |
paths
a list of paths where this realm has been known to be required |
private int |
port
the port |
private java.lang.String |
realm
the realm |
private java.lang.String |
scheme
the scheme. |
static int |
SHTTP
|
| Constructor Summary | |
(package private) |
AuthorizationInfo(AuthorizationInfo templ)
Creates a new copy of the given AuthorizationInfo. |
(package private) |
AuthorizationInfo(java.lang.String host,
int port)
Creates an new info structure for the specified host and port. |
|
AuthorizationInfo(java.lang.String host,
int port,
java.lang.String scheme,
java.lang.String realm,
NVPair[] params,
java.lang.Object info)
Creates a new info structure for the specified host and port with the specified scheme, realm, params. |
|
AuthorizationInfo(java.lang.String host,
int port,
java.lang.String scheme,
java.lang.String realm,
java.lang.String cookie)
Creates a new info structure for the specified host and port with the specified scheme, realm and cookie. |
| Method Summary | |
static void |
addAuthorization(AuthorizationInfo auth_info)
Adds an authorization entry to the list using the default context. |
static void |
addAuthorization(AuthorizationInfo auth_info,
java.lang.Object context)
Adds an authorization entry to the list. |
static void |
addAuthorization(java.lang.String host,
int port,
java.lang.String scheme,
java.lang.String realm,
java.lang.String cookie,
NVPair[] params,
java.lang.Object info)
Adds an authorization entry to the list using the default context. |
static void |
addAuthorization(java.lang.String host,
int port,
java.lang.String scheme,
java.lang.String realm,
java.lang.String cookie,
NVPair[] params,
java.lang.Object info,
java.lang.Object context)
Adds an authorization entry to the list. |
static void |
addBasicAuthorization(java.lang.String host,
int port,
java.lang.String realm,
java.lang.String user,
java.lang.String passwd)
Adds an authorization entry for the "Basic" authorization scheme to the list using the default context. |
static void |
addBasicAuthorization(java.lang.String host,
int port,
java.lang.String realm,
java.lang.String user,
java.lang.String passwd,
java.lang.Object context)
Adds an authorization entry for the "Basic" authorization scheme to the list. |
static void |
addDigestAuthorization(java.lang.String host,
int port,
java.lang.String realm,
java.lang.String user,
java.lang.String passwd)
Adds an authorization entry for the "Digest" authorization scheme to the list using the default context. |
static void |
addDigestAuthorization(java.lang.String host,
int port,
java.lang.String realm,
java.lang.String user,
java.lang.String passwd,
java.lang.Object context)
Adds an authorization entry for the "Digest" authorization scheme to the list. |
void |
addPath(java.lang.String resource)
Adds the path from the given resource to our path list. |
java.lang.Object |
clone()
This method may be called to create a new copy of the Object. |
boolean |
equals(java.lang.Object obj)
Two AuthorizationInfos are considered equal if their host, port, scheme and realm match. |
(package private) static AuthorizationInfo |
findBest(RoRequest req)
Tries to find the candidate in the current list of auth info for the given request. |
static AuthorizationHandler |
getAuthHandler()
Get's the current authorization handler. |
(package private) static AuthorizationInfo |
getAuthorization(AuthorizationInfo auth_info,
RoRequest req,
RoResponse resp,
boolean query_auth_h)
Searches for the authorization info using the host, port, scheme and realm from the given info struct. |
static AuthorizationInfo |
getAuthorization(java.lang.String host,
int port,
java.lang.String scheme,
java.lang.String realm)
Searches for the authorization info using the given host, port, scheme and realm. |
(package private) static AuthorizationInfo |
getAuthorization(java.lang.String host,
int port,
java.lang.String scheme,
java.lang.String realm,
boolean query_auth_h)
Searches for the authorization info given a host, port, scheme and realm. |
static AuthorizationInfo |
getAuthorization(java.lang.String host,
int port,
java.lang.String scheme,
java.lang.String realm,
java.lang.Object context)
Searches for the authorization info in the given context using the given host, port, scheme and realm. |
java.lang.String |
getCookie()
Get the cookie |
java.lang.Object |
getExtraInfo()
Get the extra info. |
java.lang.String |
getHost()
Get the host. |
NVPair[] |
getParams()
Get the authentication parameters. |
int |
getPort()
Get the port. |
java.lang.String |
getRealm()
Get the realm. |
java.lang.String |
getScheme()
Get the scheme. |
int |
hashCode()
Produces a hash code based on host, scheme and realm. |
(package private) static AuthorizationInfo[] |
parseAuthString(java.lang.String challenge,
RoRequest req,
RoResponse resp)
Parses the authentication challenge(s) into an array of new info structures for the specified host and port. |
(package private) static AuthorizationInfo |
queryAuthHandler(AuthorizationInfo auth_info,
RoRequest req,
RoResponse resp)
Queries the AuthHandler for authorization info. |
static void |
removeAuthorization(AuthorizationInfo auth_info)
Removes an authorization entry from the list using the default context. |
static void |
removeAuthorization(AuthorizationInfo auth_info,
java.lang.Object context)
Removes an authorization entry from the list. |
static void |
removeAuthorization(java.lang.String host,
int port,
java.lang.String scheme,
java.lang.String realm)
Removes an authorization entry from the list using the default context. |
static void |
removeAuthorization(java.lang.String host,
int port,
java.lang.String scheme,
java.lang.String realm,
java.lang.Object context)
Removes an authorization entry from the list. |
static AuthorizationHandler |
setAuthHandler(AuthorizationHandler handler)
Set's the authorization handler. |
void |
setCookie(java.lang.String cookie)
Set the cookie |
void |
setExtraInfo(java.lang.Object info)
Set the extra info. |
void |
setParams(NVPair[] params)
Set the authentication parameters. |
java.lang.String |
toString()
Constructs a string containing the authorization info. |
| Methods inherited from class java.lang.Object |
finalize, getClass, notify, notifyAll, wait, wait, wait |
| Field Detail |
CntxtList
private static java.util.Hashtable CntxtList
- Holds the list of lists of authorization info structures
AuthHandler
private static AuthorizationHandler AuthHandler
- A pointer to the handler to be called when we need authorization info
host
private java.lang.String host
- the host (lowercase)
port
private int port
- the port
scheme
private java.lang.String scheme
- the scheme. (e.g. "Basic")
Note: don't lowercase because some buggy servers use a case-sensitive
match
realm
private java.lang.String realm
- the realm
cookie
private java.lang.String cookie
- the string used for the "Basic", "NTLM", and other authorization
schemes which don't use parameters
auth_params
private NVPair[] auth_params
- any parameters
extra_info
private java.lang.Object extra_info
- additional info which won't be displayed in the toString()
paths
private java.lang.String[] paths
- a list of paths where this realm has been known to be required
DebugAll
public static final boolean DebugAll
- Debug variables
- See Also:
- Constant Field Values
DebugConn
public static final boolean DebugConn
- See Also:
- Constant Field Values
DebugResp
public static final boolean DebugResp
- See Also:
- Constant Field Values
DebugDemux
public static final boolean DebugDemux
- See Also:
- Constant Field Values
DebugAuth
public static final boolean DebugAuth
- See Also:
- Constant Field Values
DebugSocks
public static final boolean DebugSocks
- See Also:
- Constant Field Values
DebugMods
public static final boolean DebugMods
- See Also:
- Constant Field Values
DebugURLC
public static final boolean DebugURLC
- See Also:
- Constant Field Values
HTTP
public static final int HTTP
- possible http protocols we (might) handle
- See Also:
- Constant Field Values
HTTPS
public static final int HTTPS
- See Also:
- Constant Field Values
SHTTP
public static final int SHTTP
- See Also:
- Constant Field Values
HTTP_NG
public static final int HTTP_NG
- See Also:
- Constant Field Values
HTTP_1_0
public static final int HTTP_1_0
- some known http versions
- See Also:
- Constant Field Values
HTTP_1_1
public static final int HTTP_1_1
- See Also:
- Constant Field Values
CD_NONE
public static final int CD_NONE
- Content delimiters
- See Also:
- Constant Field Values
CD_HDRS
public static final int CD_HDRS
- See Also:
- Constant Field Values
CD_0
public static final int CD_0
- See Also:
- Constant Field Values
CD_CLOSE
public static final int CD_CLOSE
- See Also:
- Constant Field Values
CD_CONTLEN
public static final int CD_CONTLEN
- See Also:
- Constant Field Values
CD_CHUNKED
public static final int CD_CHUNKED
- See Also:
- Constant Field Values
CD_MP_BR
public static final int CD_MP_BR
- See Also:
- Constant Field Values
| Constructor Detail |
AuthorizationInfo
AuthorizationInfo(java.lang.String host, int port)
- Creates an new info structure for the specified host and port.
AuthorizationInfo
public AuthorizationInfo(java.lang.String host, int port, java.lang.String scheme, java.lang.String realm, NVPair[] params, java.lang.Object info)
- Creates a new info structure for the specified host and port with the
specified scheme, realm, params. The cookie is set to null.
AuthorizationInfo
public AuthorizationInfo(java.lang.String host, int port, java.lang.String scheme, java.lang.String realm, java.lang.String cookie)
- Creates a new info structure for the specified host and port with the
specified scheme, realm and cookie. The params is set to a zero-length
array, and the extra_info is set to null.
AuthorizationInfo
AuthorizationInfo(AuthorizationInfo templ)
- Creates a new copy of the given AuthorizationInfo.
| Method Detail |
setAuthHandler
public static AuthorizationHandler setAuthHandler(AuthorizationHandler handler)
- Set's the authorization handler. This handler is called whenever
the server requests authorization and no entry for the requested
scheme and realm can be found in the list. The handler must implement
the AuthorizationHandler interface.
If no handler is set then a default handler is used. This handler currently only handles the "Basic" scheme and brings up a popup which prompts for the username and password.
The default handler can be disabled by setting the auth handler to null.
getAuthHandler
public static AuthorizationHandler getAuthHandler()
- Get's the current authorization handler.
getAuthorization
public static AuthorizationInfo getAuthorization(java.lang.String host, int port, java.lang.String scheme, java.lang.String realm)
- Searches for the authorization info using the given host, port,
scheme and realm. The context is the default context.
getAuthorization
public static AuthorizationInfo getAuthorization(java.lang.String host, int port, java.lang.String scheme, java.lang.String realm, java.lang.Object context)
- Searches for the authorization info in the given context using the
given host, port, scheme and realm.
queryAuthHandler
static AuthorizationInfo queryAuthHandler(AuthorizationInfo auth_info, RoRequest req, RoResponse resp) throws AuthSchemeNotImplException
- Queries the AuthHandler for authorization info. It also adds this
info to the list.
getAuthorization
static AuthorizationInfo getAuthorization(AuthorizationInfo auth_info, RoRequest req, RoResponse resp, boolean query_auth_h) throws AuthSchemeNotImplException
- Searches for the authorization info using the host, port, scheme and
realm from the given info struct. If not found it queries the
AuthHandler (if set).
getAuthorization
static AuthorizationInfo getAuthorization(java.lang.String host, int port, java.lang.String scheme, java.lang.String realm, boolean query_auth_h) throws AuthSchemeNotImplException
- Searches for the authorization info given a host, port, scheme and
realm. Queries the AuthHandler if not found in list.
addAuthorization
public static void addAuthorization(AuthorizationInfo auth_info)
- Adds an authorization entry to the list using the default context.
If an entry for the specified scheme and realm already exists then
its cookie and params are replaced with the new data.
addAuthorization
public static void addAuthorization(AuthorizationInfo auth_info, java.lang.Object context)
- Adds an authorization entry to the list. If an entry for the
specified scheme and realm already exists then its cookie and
params are replaced with the new data.
addAuthorization
public static void addAuthorization(java.lang.String host, int port, java.lang.String scheme, java.lang.String realm, java.lang.String cookie, NVPair[] params, java.lang.Object info)
- Adds an authorization entry to the list using the default context.
If an entry for the specified scheme and realm already exists then
its cookie and params are replaced with the new data.
addAuthorization
public static void addAuthorization(java.lang.String host, int port, java.lang.String scheme, java.lang.String realm, java.lang.String cookie, NVPair[] params, java.lang.Object info, java.lang.Object context)
- Adds an authorization entry to the list. If an entry for the
specified scheme and realm already exists then its cookie and
params are replaced with the new data.
addBasicAuthorization
public static void addBasicAuthorization(java.lang.String host, int port, java.lang.String realm, java.lang.String user, java.lang.String passwd)
- Adds an authorization entry for the "Basic" authorization scheme to
the list using the default context. If an entry already exists for
the "Basic" scheme and the specified realm then it is overwritten.
addBasicAuthorization
public static void addBasicAuthorization(java.lang.String host, int port, java.lang.String realm, java.lang.String user, java.lang.String passwd, java.lang.Object context)
- Adds an authorization entry for the "Basic" authorization scheme to
the list. If an entry already exists for the "Basic" scheme and the
specified realm then it is overwritten.
addDigestAuthorization
public static void addDigestAuthorization(java.lang.String host, int port, java.lang.String realm, java.lang.String user, java.lang.String passwd)
- Adds an authorization entry for the "Digest" authorization scheme to
the list using the default context. If an entry already exists for the
"Digest" scheme and the specified realm then it is overwritten.
addDigestAuthorization
public static void addDigestAuthorization(java.lang.String host, int port, java.lang.String realm, java.lang.String user, java.lang.String passwd, java.lang.Object context)
- Adds an authorization entry for the "Digest" authorization scheme to
the list. If an entry already exists for the "Digest" scheme and the
specified realm then it is overwritten.
removeAuthorization
public static void removeAuthorization(AuthorizationInfo auth_info)
- Removes an authorization entry from the list using the default context.
If no entry for the specified host, port, scheme and realm exists then
this does nothing.
removeAuthorization
public static void removeAuthorization(AuthorizationInfo auth_info, java.lang.Object context)
- Removes an authorization entry from the list. If no entry for the
specified host, port, scheme and realm exists then this does nothing.
removeAuthorization
public static void removeAuthorization(java.lang.String host, int port, java.lang.String scheme, java.lang.String realm)
- Removes an authorization entry from the list using the default context.
If no entry for the specified host, port, scheme and realm exists then
this does nothing.
removeAuthorization
public static void removeAuthorization(java.lang.String host, int port, java.lang.String scheme, java.lang.String realm, java.lang.Object context)
- Removes an authorization entry from the list. If no entry for the
specified host, port, scheme and realm exists then this does nothing.
findBest
static AuthorizationInfo findBest(RoRequest req)
- Tries to find the candidate in the current list of auth info for the
given request. The paths associated with each auth info are examined,
and the one with either the nearest direct parent or child is chosen.
This is used for preemptively sending auth info.
addPath
public void addPath(java.lang.String resource)
- Adds the path from the given resource to our path list. The path
list is used for deciding when to preemptively send auth info.
parseAuthString
static AuthorizationInfo[] parseAuthString(java.lang.String challenge, RoRequest req, RoResponse resp) throws java.net.ProtocolException
- Parses the authentication challenge(s) into an array of new info
structures for the specified host and port.
getHost
public final java.lang.String getHost()
- Get the host.
getPort
public final int getPort()
- Get the port.
getScheme
public final java.lang.String getScheme()
- Get the scheme.
getRealm
public final java.lang.String getRealm()
- Get the realm.
getCookie
public final java.lang.String getCookie()
- Get the cookie
- Since:
- V0.3-1
setCookie
public final void setCookie(java.lang.String cookie)
- Set the cookie
- Since:
- V0.3-1
getParams
public final NVPair[] getParams()
- Get the authentication parameters.
setParams
public final void setParams(NVPair[] params)
- Set the authentication parameters.
getExtraInfo
public final java.lang.Object getExtraInfo()
- Get the extra info.
setExtraInfo
public final void setExtraInfo(java.lang.Object info)
- Set the extra info.
toString
public java.lang.String toString()
- Constructs a string containing the authorization info. The format
is that of the http Authorization header.
hashCode
public int hashCode()
- Produces a hash code based on host, scheme and realm. Port is not
included for simplicity (and because it probably won't make much
difference). Used in the AuthorizationInfo.AuthList hash table.
equals
public boolean equals(java.lang.Object obj)
- Two AuthorizationInfos are considered equal if their host, port,
scheme and realm match. Used in the AuthorizationInfo.AuthList hash
table.
clone
public java.lang.Object clone()
- Description copied from class:
java.lang.Object - This method may be called to create a new copy of the
Object. The typical behavior is as follows:
o == o.clone()is falseo.getClass() == o.clone().getClass()is trueo.equals(o)is true
However, these are not strict requirements, and may be violated if necessary. Of the three requirements, the last is the most commonly violated, particularly if the subclass does not override Object.equals(Object)>
Object.equals(Object)55 .If the Object you call clone() on does not implement java.lang.Cloneable (which is a placeholder interface), then a CloneNotSupportedException is thrown. Notice that Object does not implement Cloneable; this method exists as a convenience for subclasses that do.
Object's implementation of clone allocates space for the new Object using the correct class, without calling any constructors, and then fills in all of the new field values with the old field values. Thus, it is a shallow copy. However, subclasses are permitted to make a deep copy.
All array types implement Cloneable, and override this method as follows (it should never fail):
public Object clone() { try { super.clone(); } catch (CloneNotSupportedException e) { throw new InternalError(e.getMessage()); } }
|
|||||||||
| Home >> All >> [ HTTPClient overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
JAVADOC
HTTPClient.AuthorizationInfo