Class AuthenticatedURL
java.lang.Object
org.apache.hadoop.security.authentication.client.AuthenticatedURL
The
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().openConnection(url, token);
....
// use the 'conn' instance
....
// establishing a follow up connection using a token from the previous connection
HttpURLConnection conn = new AuthenticatedURL().openConnection(url, token);
....
// use the 'conn' instance
....
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classClient side authentication token. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringName of the HTTP cookie used for the authentication token between the client and the server. -
Constructor Summary
ConstructorsConstructorDescriptionCreates anAuthenticatedURL.AuthenticatedURL(Authenticator authenticator) Creates anAuthenticatedURL.AuthenticatedURL(Authenticator authenticator, ConnectionConfigurator connConfigurator) Creates anAuthenticatedURL. -
Method Summary
Modifier and TypeMethodDescriptionstatic voidextractToken(HttpURLConnection conn, AuthenticatedURL.Token token) Helper method that extracts an authentication token received from a connection.protected AuthenticatorReturns theAuthenticatorinstance used by theAuthenticatedURL.static Class<? extends Authenticator>Returns the defaultAuthenticatorclass to use when anAuthenticatedURLinstance is created without specifying an authenticator.static voidinjectToken(HttpURLConnection conn, AuthenticatedURL.Token token) Helper method that injects an authentication token to send with a connection.openConnection(URL url, AuthenticatedURL.Token token) Returns an authenticatedHttpURLConnection.static voidsetDefaultAuthenticator(Class<? extends Authenticator> authenticator) Sets the defaultAuthenticatorclass to use when anAuthenticatedURLinstance is created without specifying an authenticator.
-
Field Details
-
AUTH_COOKIE
Name of the HTTP cookie used for the authentication token between the client and the server.- See Also:
-
-
Constructor Details
-
AuthenticatedURL
public AuthenticatedURL()Creates anAuthenticatedURL. -
AuthenticatedURL
Creates anAuthenticatedURL.- Parameters:
authenticator- theAuthenticatorinstance to use, ifnullaKerberosAuthenticatoris used.
-
AuthenticatedURL
Creates anAuthenticatedURL.- Parameters:
authenticator- theAuthenticatorinstance to use, ifnullaKerberosAuthenticatoris used.connConfigurator- a connection configurator.
-
-
Method Details
-
setDefaultAuthenticator
Sets the defaultAuthenticatorclass to use when anAuthenticatedURLinstance is created without specifying an authenticator.- Parameters:
authenticator- the authenticator class to use as default.
-
getDefaultAuthenticator
Returns the defaultAuthenticatorclass to use when anAuthenticatedURLinstance is created without specifying an authenticator.- Returns:
- the authenticator class to use as default.
-
getAuthenticator
Returns theAuthenticatorinstance used by theAuthenticatedURL.- Returns:
- the
Authenticatorinstance
-
openConnection
public HttpURLConnection openConnection(URL url, AuthenticatedURL.Token token) throws IOException, AuthenticationException Returns an authenticatedHttpURLConnection.- Parameters:
url- the URL to connect to. Only HTTP/S URLs are supported.token- the authentication token being used for the user.- Returns:
- an authenticated
HttpURLConnection. - Throws:
IOException- if an IO error occurred.AuthenticationException- if an authentication exception occurred.
-
injectToken
Helper method that injects an authentication token to send with a connection. Callers should prefer usingAuthenticatedURL.Token.openConnection(URL, ConnectionConfigurator)which automatically manages authentication tokens.- Parameters:
conn- connection to inject the authentication token into.token- authentication token to inject.
-
extractToken
public static void extractToken(HttpURLConnection conn, AuthenticatedURL.Token token) throws IOException, AuthenticationException Helper method that extracts an authentication token received from a connection.This method is used by
Authenticatorimplementations.- Parameters:
conn- connection to extract the authentication token from.token- the authentication token.- Throws:
IOException- if an IO error occurred.AuthenticationException- if an authentication exception occurred.
-