public class AuthenticatedURL extends Object
AuthenticatedURL
class enables the use of the JDK URL
class
against HTTP endpoints protected with the AuthenticationFilter
.
The authentication mechanisms supported by default are Hadoop Simple authentication
(also known as pseudo authentication) and Kerberos SPNEGO authentication.
Additional authentication mechanisms can be supported via Authenticator
implementations.
The default Authenticator
is the KerberosAuthenticator
class which supports
automatic fallback from Kerberos SPNEGO to Hadoop Simple authentication.
AuthenticatedURL
instances are not thread-safe.
The usage pattern of the AuthenticatedURL
is:
// establishing an initial connection URL url = new URL("http://foo:8080/bar"); AuthenticatedURL.Token token = new AuthenticatedURL.Token(); AuthenticatedURL aUrl = new AuthenticatedURL(); HttpURLConnection conn = new AuthenticatedURL(url, token).openConnection(); .... // use the 'conn' instance .... // establishing a follow up connection using a token from the previous connection HttpURLConnection conn = new AuthenticatedURL(url, token).openConnection(); .... // use the 'conn' instance ....
限定符和类型 | 类和说明 |
---|---|
static class |
AuthenticatedURL.Token
Client side authentication token.
|
限定符和类型 | 字段和说明 |
---|---|
static String |
AUTH_COOKIE
Name of the HTTP cookie used for the authentication token between the client and the server.
|
构造器和说明 |
---|
AuthenticatedURL()
Creates an
AuthenticatedURL . |
AuthenticatedURL(Authenticator authenticator)
Creates an
AuthenticatedURL . |
限定符和类型 | 方法和说明 |
---|---|
static void |
extractToken(HttpURLConnection conn,
AuthenticatedURL.Token token)
Helper method that extracts an authentication token received from a connection.
|
static Class<? extends Authenticator> |
getDefaultAuthenticator()
Returns the default
Authenticator class to use when an AuthenticatedURL instance
is created without specifying an authenticator. |
static void |
injectToken(HttpURLConnection conn,
AuthenticatedURL.Token token)
Helper method that injects an authentication token to send with a connection.
|
HttpURLConnection |
openConnection(URL url,
AuthenticatedURL.Token token)
Returns an authenticated
HttpURLConnection . |
static void |
setDefaultAuthenticator(Class<? extends Authenticator> authenticator)
Sets the default
Authenticator class to use when an AuthenticatedURL instance
is created without specifying an authenticator. |
public AuthenticatedURL()
AuthenticatedURL
.public AuthenticatedURL(Authenticator authenticator)
AuthenticatedURL
.authenticator
- the Authenticator
instance to use, if null
a KerberosAuthenticator
is used.public static void setDefaultAuthenticator(Class<? extends Authenticator> authenticator)
Authenticator
class to use when an AuthenticatedURL
instance
is created without specifying an authenticator.authenticator
- the authenticator class to use as default.public static Class<? extends Authenticator> getDefaultAuthenticator()
Authenticator
class to use when an AuthenticatedURL
instance
is created without specifying an authenticator.public HttpURLConnection openConnection(URL url, AuthenticatedURL.Token token) throws IOException, AuthenticationException
HttpURLConnection
.url
- the URL to connect to. Only HTTP/S URLs are supported.token
- the authentication token being used for the user.HttpURLConnection
.IOException
- if an IO error occurred.AuthenticationException
- if an authentication exception occurred.public static void injectToken(HttpURLConnection conn, AuthenticatedURL.Token token)
conn
- connection to inject the authentication token into.token
- authentication token to inject.public static void extractToken(HttpURLConnection conn, AuthenticatedURL.Token token) throws IOException, AuthenticationException
Authenticator
implementations.conn
- connection to extract the authentication token from.token
- the authentication token.IOException
- if an IO error occurred.AuthenticationException
- if an authentication exception occurred.Copyright © 2009 The Apache Software Foundation