APIdia Launch Partner
Top Description Fields Constructors Methods
sun.net.www.protocol.http

public abstract Class AuthenticationInfo

extends AuthCacheValue
implements Cloneable
Class Inheritance
All Implemented Interfaces
java.lang.Cloneable
Known Direct Subclasses
sun.net.www.protocol.http.BasicAuthentication, sun.net.www.protocol.http.DigestAuthentication, sun.net.www.protocol.http.NegotiateAuthentication, sun.net.www.protocol.http.ntlm.NTLMAuthentication
Imports
java.io.IOException, java.net.PasswordAuthentication, .URL, java.util.HashMap, .Locale, .Objects, java.util.concurrent.locks.Condition, .ReentrantLock, java.util.function.BiFunction, sun.net.www.HeaderParser

AuthenticationInfo: Encapsulate the information needed to authenticate a user to a server.
Authors
Jon Payne, Herb Jellinek, Bill Foote

Field Summary

Modifier and TypeField and Description
pack-priv AuthScheme
authScheme

The authentication scheme (basic/digest).

pack-priv String
host

The host we're authenticating against.

pack-priv String
path

The shortest path from the URL we authenticated against.

pack-priv int
port

The port on the host we're authenticating against.

pack-priv String
protocol

The protocol/scheme (i.e. http or https ).

public static final char
protected PasswordAuthentication
pack-priv String
realm

The realm we're authenticating against.

private static final Condition
private static final ReentrantLock
private static final HashMap<String, Thread>
requests

requests is used to ensure that interaction with the Authenticator for a particular realm is single threaded.

pack-priv static final boolean
serializeAuth

If true, then simultaneous authentication requests to the same realm/proxy are serialized, in order to avoid a user having to type the same username/passwords repeatedly, via the Authenticator.

public static final char
pack-priv char
type

The type (server/proxy) of authentication this is.

Constructor Summary

AccessConstructor and Description
public
AuthenticationInfo(char type, AuthScheme authScheme, String host, int port, String realm)

Use this constructor only for proxy entries

public
AuthenticationInfo(char type, AuthScheme authScheme, URL url, String realm)

Method Summary

Modifier and TypeMethod and Description
pack-priv void
addToCache(AuthCacheImpl authcache)

Add this authentication to the cache

pack-priv String
cacheKey(boolean
if you want the realm considered. Preemptively setting an authorization is done before the realm is known.
includeRealm
)

Give a key for hash table lookups.

public Object
clone()

Overrides java.lang.Object.clone.

Creates and returns a copy of this object.

public PasswordAuthentication
credentials()

Implements abstract sun.net.www.protocol.http.AuthCacheValue.credentials.

the credentials associated with this authentication

public void
disposeContext()

Releases any system or cryptographic resources.

pack-priv static void
pack-priv static AuthenticationInfo
getAuth(String key, URL url, AuthCacheImpl acache)

Return the AuthenticationInfo object from the cache if it's path is a substring of the supplied URLs path.

pack-priv AuthScheme
getAuthScheme()

Implements abstract sun.net.www.protocol.http.AuthCacheValue.getAuthScheme.

Authentication scheme

public AuthCacheValue.Type
private static AuthenticationInfo
private static AuthenticationInfo
public String
getHeaderName()

Returns: the name of the HTTP header this authentication wants set.

public abstract String

Returns:

the value of the HTTP header this authentication wants set. Used for preemptive authorization.
getHeaderValue
(URL
The URL
url
,
String
The request method
method
)

Calculates and returns the authentication header value based on the stored authentication parameters.

public String
getHost()

Implements abstract sun.net.www.protocol.http.AuthCacheValue.getHost.

name of server/proxy

public String
getPath()

Implements abstract sun.net.www.protocol.http.AuthCacheValue.getPath.

root path of realm or the request path if the root is not known yet.

public int
getPort()

Implements abstract sun.net.www.protocol.http.AuthCacheValue.getPort.

portnumber of server/proxy

public String
pack-priv static AuthenticationInfo
getProxyAuth(String host, int port, AuthCacheImpl acache)

Returns a firewall authentication, for the given host/port.

pack-priv static AuthenticationInfo
pack-priv static String
getProxyAuthKey(String host, int port, String realm, AuthScheme scheme)

Returns a firewall authentication, for the given host/port and realm.

public String
getRealm()

Implements abstract sun.net.www.protocol.http.AuthCacheValue.getRealm.

realm of authentication if known

pack-priv static AuthenticationInfo
getServerAuth(URL url, AuthCacheImpl cache)

Returns info for the URL, for an HTTP server auth.

pack-priv static AuthenticationInfo
pack-priv static String
getServerAuthKey(URL url, String realm, AuthScheme scheme)

Returns info for the URL, for an HTTP server auth.

public abstract boolean
isAuthorizationStale(String header)

Check if the header indicates that the current auth.

pack-priv static String
reducePath(String urlPath)

pack-priv void
removeFromCache(AuthCacheImpl authcache)

Remove this authentication from the cache

private static AuthenticationInfo
private static void
public abstract void
setHeaders(HttpURLConnection
The connection to apply the header(s) to
conn
,
HeaderParser
A source of header values for this connection, if needed.
p
,
String
The raw header field (if needed)
raw
)

Set header(s) on the given connection.

public abstract boolean
supportsPreemptiveAuthorization()

Returns: true if this authentication supports preemptive authorization

protected boolean

Returns:

true by default.
useAuthCache
()

Whether we should cache this instance in the AuthCache.

Field Detail

authSchemeback to summary
pack-priv AuthScheme authScheme

The authentication scheme (basic/digest). Also used for key lookup

hostback to summary
pack-priv String host

The host we're authenticating against.

pathback to summary
pack-priv String path

The shortest path from the URL we authenticated against.

portback to summary
pack-priv int port

The port on the host we're authenticating against.

protocolback to summary
pack-priv String protocol

The protocol/scheme (i.e. http or https ). Need to keep the caches logically separate for the two protocols. This field is only used when constructed with a URL (the normal case for server authentication) For proxy authentication the protocol is not relevant.

PROXY_AUTHENTICATIONback to summary
public static final char PROXY_AUTHENTICATION
pwback to summary
protected PasswordAuthentication pw
realmback to summary
pack-priv String realm

The realm we're authenticating against.

requestFinishedback to summary
private static final Condition requestFinished
requestLockback to summary
private static final ReentrantLock requestLock
requestsback to summary
private static final HashMap<String, Thread> requests

requests is used to ensure that interaction with the Authenticator for a particular realm is single threaded. i.e. if multiple threads need to get credentials from the user at the same time, then all but the first will block until the first completes its authentication.

serializeAuthback to summary
pack-priv static final boolean serializeAuth

If true, then simultaneous authentication requests to the same realm/proxy are serialized, in order to avoid a user having to type the same username/passwords repeatedly, via the Authenticator. Default is false, which means that this behavior is switched off.

SERVER_AUTHENTICATIONback to summary
public static final char SERVER_AUTHENTICATION
typeback to summary
pack-priv char type

The type (server/proxy) of authentication this is. Used for key lookup

Constructor Detail

AuthenticationInfoback to summary
public AuthenticationInfo(char type, AuthScheme authScheme, String host, int port, String realm)

Use this constructor only for proxy entries

AuthenticationInfoback to summary
public AuthenticationInfo(char type, AuthScheme authScheme, URL url, String realm)

Method Detail

addToCacheback to summary
pack-priv void addToCache(AuthCacheImpl authcache)

Add this authentication to the cache

cacheKeyback to summary
pack-priv String cacheKey(boolean includeRealm)

Give a key for hash table lookups.

Parameters
includeRealm:boolean

if you want the realm considered. Preemptively setting an authorization is done before the realm is known.

cloneback to summary
public Object clone()

Overrides java.lang.Object.clone.

Doc from java.lang.Object.clone.

Creates and returns a copy of this object. The precise meaning of "copy" may depend on the class of the object. The general intent is that, for any object x, the expression:

x.clone() != x
will be true, and that the expression:
x.clone().getClass() == x.getClass()
will be true, but these are not absolute requirements. While it is typically the case that:
x.clone().equals(x)
will be true, this is not an absolute requirement.

By convention, the returned object should be obtained by calling super.clone. If a class and all of its superclasses (except Object) obey this convention, it will be the case that x.clone().getClass() == x.getClass().

By convention, the object returned by this method should be independent of this object (which is being cloned). To achieve this independence, it may be necessary to modify one or more fields of the object returned by super.clone before returning it. Typically, this means copying any mutable objects that comprise the internal "deep structure" of the object being cloned and replacing the references to these objects with references to the copies. If a class contains only primitive fields or references to immutable objects, then it is usually the case that no fields in the object returned by super.clone need to be modified.

credentialsback to summary
public PasswordAuthentication credentials()

Implements abstract sun.net.www.protocol.http.AuthCacheValue.credentials.

Doc from sun.net.www.protocol.http.AuthCacheValue.credentials.

the credentials associated with this authentication

disposeContextback to summary
public void disposeContext()

Releases any system or cryptographic resources. It is up to implementors to override disposeContext() to take necessary action.

endAuthRequestback to summary
pack-priv static void endAuthRequest(String key)
getAuthback to summary
pack-priv static AuthenticationInfo getAuth(String key, URL url, AuthCacheImpl acache)

Return the AuthenticationInfo object from the cache if it's path is a substring of the supplied URLs path.

getAuthSchemeback to summary
pack-priv AuthScheme getAuthScheme()

Implements abstract sun.net.www.protocol.http.AuthCacheValue.getAuthScheme.

Doc from sun.net.www.protocol.http.AuthCacheValue.getAuthScheme.

Authentication scheme

getAuthTypeback to summary
public AuthCacheValue.Type getAuthType()

Implements abstract sun.net.www.protocol.http.AuthCacheValue.getAuthType.

Doc from sun.net.www.protocol.http.AuthCacheValue.getAuthType.

Proxy or Server

getCachedProxyAuthback to summary
private static AuthenticationInfo getCachedProxyAuth(String key, AuthCacheImpl acache)
getCachedServerAuthback to summary
private static AuthenticationInfo getCachedServerAuth(String key, AuthCacheImpl cache)
getHeaderNameback to summary
public String getHeaderName()
Returns:String

the name of the HTTP header this authentication wants set. This is used for preemptive authorization.

getHeaderValueback to summary
public abstract String getHeaderValue(URL url, String method)

Calculates and returns the authentication header value based on the stored authentication parameters. If the calculation does not depend on the URL or the request method then these parameters are ignored.

Parameters
url:URL

The URL

method:String

The request method

Returns:String

the value of the HTTP header this authentication wants set. Used for preemptive authorization.

getHostback to summary
public String getHost()

Implements abstract sun.net.www.protocol.http.AuthCacheValue.getHost.

Doc from sun.net.www.protocol.http.AuthCacheValue.getHost.

name of server/proxy

getPathback to summary
public String getPath()

Implements abstract sun.net.www.protocol.http.AuthCacheValue.getPath.

Doc from sun.net.www.protocol.http.AuthCacheValue.getPath.

root path of realm or the request path if the root is not known yet.

getPortback to summary
public int getPort()

Implements abstract sun.net.www.protocol.http.AuthCacheValue.getPort.

Doc from sun.net.www.protocol.http.AuthCacheValue.getPort.

portnumber of server/proxy

getProtocolSchemeback to summary
public String getProtocolScheme()

Implements abstract sun.net.www.protocol.http.AuthCacheValue.getProtocolScheme.

Doc from sun.net.www.protocol.http.AuthCacheValue.getProtocolScheme.

returns http or https

getProxyAuthback to summary
pack-priv static AuthenticationInfo getProxyAuth(String host, int port, AuthCacheImpl acache)

Returns a firewall authentication, for the given host/port. Used for preemptive header-setting. Note, the protocol field is always blank for proxies.

getProxyAuthback to summary
pack-priv static AuthenticationInfo getProxyAuth(String key, AuthCacheImpl acache)
getProxyAuthKeyback to summary
pack-priv static String getProxyAuthKey(String host, int port, String realm, AuthScheme scheme)

Returns a firewall authentication, for the given host/port and realm. Used in response to a challenge. Note, the protocol field is always blank for proxies.

getRealmback to summary
public String getRealm()

Implements abstract sun.net.www.protocol.http.AuthCacheValue.getRealm.

Doc from sun.net.www.protocol.http.AuthCacheValue.getRealm.

realm of authentication if known

getServerAuthback to summary
pack-priv static AuthenticationInfo getServerAuth(URL url, AuthCacheImpl cache)

Returns info for the URL, for an HTTP server auth. Used when we don't yet know the realm (i.e. when we're preemptively setting the auth).

getServerAuthback to summary
pack-priv static AuthenticationInfo getServerAuth(String key, AuthCacheImpl cache)
getServerAuthKeyback to summary
pack-priv static String getServerAuthKey(URL url, String realm, AuthScheme scheme)

Returns info for the URL, for an HTTP server auth. Used when we do know the realm (i.e. when we're responding to a challenge). In this case we do not use the path because the protection space is identified by the host:port:realm only

isAuthorizationStaleback to summary
public abstract boolean isAuthorizationStale(String header)

Check if the header indicates that the current auth. parameters are stale. If so, then replace the relevant field with the new value and return true. Otherwise return false. returning true means the request can be retried with the same userid/password returning false means we have to go back to the user to ask for a new username password.

reducePathback to summary
pack-priv static String reducePath(String urlPath)
removeFromCacheback to summary
pack-priv void removeFromCache(AuthCacheImpl authcache)

Remove this authentication from the cache

requestAuthenticationback to summary
private static AuthenticationInfo requestAuthentication(String key, AuthCacheImpl acache, BiFunction<String, AuthCacheImpl, AuthenticationInfo> cachefunc)
requestCompletedback to summary
private static void requestCompleted(String key)
setHeadersback to summary
public abstract void setHeaders(HttpURLConnection conn, HeaderParser p, String raw) throws IOException

Set header(s) on the given connection. Subclasses must override This will only be called for definitive (i.e. non-preemptive) authorization.

Parameters
conn:HttpURLConnection

The connection to apply the header(s) to

p:HeaderParser

A source of header values for this connection, if needed.

raw:String

The raw header field (if needed)

Exceptions
IOException:
if no headers were set
supportsPreemptiveAuthorizationback to summary
public abstract boolean supportsPreemptiveAuthorization()
Returns:boolean

true if this authentication supports preemptive authorization

useAuthCacheback to summary
protected boolean useAuthCache()

Whether we should cache this instance in the AuthCache. This method returns true by default. Subclasses may override this method to add additional restrictions.

Returns:boolean

true by default.