Class DelegationTokenAuthenticatedURL
DelegationTokenAuthenticatedURL is a
AuthenticatedURL sub-class with built-in Hadoop Delegation Token
functionality.
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 DelegationTokenAuthenticator implementations.
The default DelegationTokenAuthenticator is the KerberosDelegationTokenAuthenticator class which supports
automatic fallback from Kerberos SPNEGO to Hadoop Simple authentication via
the PseudoDelegationTokenAuthenticator class.
AuthenticatedURL instances are not thread-safe.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classClient side authentication token that handles Delegation Tokens. -
Field Summary
Fields inherited from class org.apache.hadoop.security.authentication.client.AuthenticatedURL
AUTH_COOKIE -
Constructor Summary
ConstructorsConstructorDescriptionCreates anDelegationTokenAuthenticatedURL.DelegationTokenAuthenticatedURL(org.apache.hadoop.security.authentication.client.ConnectionConfigurator connConfigurator) Creates anDelegationTokenAuthenticatedURLusing the defaultDelegationTokenAuthenticatorclass.DelegationTokenAuthenticatedURL(DelegationTokenAuthenticator authenticator) Creates anDelegationTokenAuthenticatedURL.DelegationTokenAuthenticatedURL(DelegationTokenAuthenticator authenticator, org.apache.hadoop.security.authentication.client.ConnectionConfigurator connConfigurator) Creates anDelegationTokenAuthenticatedURL. -
Method Summary
Modifier and TypeMethodDescriptionvoidCancels a delegation token from the server end-point.voidcancelDelegationToken(URL url, DelegationTokenAuthenticatedURL.Token token, String doAsUser) Cancels a delegation token from the server end-point.static Class<? extends DelegationTokenAuthenticator>Returns the defaultDelegationTokenAuthenticatorclass to use when anDelegationTokenAuthenticatedURLinstance is created without specifying one.getDelegationToken(URL url, DelegationTokenAuthenticatedURL.Token token, String renewer) Requests a delegation token using the configuredAuthenticatorfor authentication.getDelegationToken(URL url, DelegationTokenAuthenticatedURL.Token token, String renewer, String doAsUser) Requests a delegation token using the configuredAuthenticatorfor authentication.openConnection(URL url, org.apache.hadoop.security.authentication.client.AuthenticatedURL.Token token) Returns an authenticatedHttpURLConnection, it uses a Delegation Token only if the given auth token is an instance ofDelegationTokenAuthenticatedURL.Tokenand it contains a Delegation Token, otherwise use the configuredDelegationTokenAuthenticatorto authenticate the connection.openConnection(URL url, DelegationTokenAuthenticatedURL.Token token) Returns an authenticatedHttpURLConnection.openConnection(URL url, DelegationTokenAuthenticatedURL.Token token, String doAs) Returns an authenticatedHttpURLConnection.longRenews a delegation token from the server end-point using the configuredAuthenticatorfor authentication.longrenewDelegationToken(URL url, DelegationTokenAuthenticatedURL.Token token, String doAsUser) Renews a delegation token from the server end-point using the configuredAuthenticatorfor authentication.Token<? extends TokenIdentifier>selectDelegationToken(URL url, Credentials creds) Select a delegation token from all tokens in credentials, based on url.static voidsetDefaultDelegationTokenAuthenticator(Class<? extends DelegationTokenAuthenticator> authenticator) Sets the defaultDelegationTokenAuthenticatorclass to use when anDelegationTokenAuthenticatedURLinstance is created without specifying one.protected voidsetUseQueryStringForDelegationToken(boolean useQueryString) Deprecated.booleanReturns if delegation token is transmitted as a HTTP header.Methods inherited from class org.apache.hadoop.security.authentication.client.AuthenticatedURL
extractToken, getAuthenticator, getDefaultAuthenticator, injectToken, setDefaultAuthenticator
-
Constructor Details
-
DelegationTokenAuthenticatedURL
public DelegationTokenAuthenticatedURL()Creates anDelegationTokenAuthenticatedURL.An instance of the default
DelegationTokenAuthenticatorwill be used. -
DelegationTokenAuthenticatedURL
Creates anDelegationTokenAuthenticatedURL.- Parameters:
authenticator- theDelegationTokenAuthenticatorinstance to use, ifnullthe default one will be used.
-
DelegationTokenAuthenticatedURL
public DelegationTokenAuthenticatedURL(org.apache.hadoop.security.authentication.client.ConnectionConfigurator connConfigurator) Creates anDelegationTokenAuthenticatedURLusing the defaultDelegationTokenAuthenticatorclass.- Parameters:
connConfigurator- a connection configurator.
-
DelegationTokenAuthenticatedURL
public DelegationTokenAuthenticatedURL(DelegationTokenAuthenticator authenticator, org.apache.hadoop.security.authentication.client.ConnectionConfigurator connConfigurator) Creates anDelegationTokenAuthenticatedURL.- Parameters:
authenticator- theDelegationTokenAuthenticatorinstance to use, ifnullthe default one will be used.connConfigurator- a connection configurator.
-
-
Method Details
-
setDefaultDelegationTokenAuthenticator
public static void setDefaultDelegationTokenAuthenticator(Class<? extends DelegationTokenAuthenticator> authenticator) Sets the defaultDelegationTokenAuthenticatorclass to use when anDelegationTokenAuthenticatedURLinstance is created without specifying one. The default class isKerberosDelegationTokenAuthenticator- Parameters:
authenticator- the authenticator class to use as default.
-
getDefaultDelegationTokenAuthenticator
public static Class<? extends DelegationTokenAuthenticator> getDefaultDelegationTokenAuthenticator()Returns the defaultDelegationTokenAuthenticatorclass to use when anDelegationTokenAuthenticatedURLinstance is created without specifying one.The default class is
KerberosDelegationTokenAuthenticator- Returns:
- the delegation token authenticator class to use as default.
-
setUseQueryStringForDelegationToken
Deprecated.Sets if delegation token should be transmitted in the URL query string. By default it is transmitted using theDelegationTokenAuthenticator.DELEGATION_TOKEN_HEADERHTTP header.This method is provided to enable WebHDFS backwards compatibility.
- Parameters:
useQueryString-TRUEif the token is transmitted in the URL query string,FALSEif the delegation token is transmitted using theDelegationTokenAuthenticator.DELEGATION_TOKEN_HEADERHTTP header.
-
useQueryStringForDelegationToken
public boolean useQueryStringForDelegationToken()Returns if delegation token is transmitted as a HTTP header.- Returns:
TRUEif the token is transmitted in the URL query string,FALSEif the delegation token is transmitted using theDelegationTokenAuthenticator.DELEGATION_TOKEN_HEADERHTTP header.
-
openConnection
public HttpURLConnection openConnection(URL url, org.apache.hadoop.security.authentication.client.AuthenticatedURL.Token token) throws IOException, org.apache.hadoop.security.authentication.client.AuthenticationException Returns an authenticatedHttpURLConnection, it uses a Delegation Token only if the given auth token is an instance ofDelegationTokenAuthenticatedURL.Tokenand it contains a Delegation Token, otherwise use the configuredDelegationTokenAuthenticatorto authenticate the connection.- Overrides:
openConnectionin classorg.apache.hadoop.security.authentication.client.AuthenticatedURL- 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.org.apache.hadoop.security.authentication.client.AuthenticationException- if an authentication exception occurred.
-
openConnection
public HttpURLConnection openConnection(URL url, DelegationTokenAuthenticatedURL.Token token) throws IOException, org.apache.hadoop.security.authentication.client.AuthenticationException Returns an authenticatedHttpURLConnection. If the Delegation Token is present, it will be used taking precedence over the configuredAuthenticator.- 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.org.apache.hadoop.security.authentication.client.AuthenticationException- if an authentication exception occurred.
-
openConnection
public HttpURLConnection openConnection(URL url, DelegationTokenAuthenticatedURL.Token token, String doAs) throws IOException, org.apache.hadoop.security.authentication.client.AuthenticationException Returns an authenticatedHttpURLConnection. If the Delegation Token is present, it will be used taking precedence over the configuredAuthenticator. If thedoAsparameter is not NULL, the request will be done on behalf of the specifieddoAsuser.- Parameters:
url- the URL to connect to. Only HTTP/S URLs are supported.token- the authentication token being used for the user.doAs- user to do the the request on behalf of, if NULL the request is as self.- Returns:
- an authenticated
HttpURLConnection. - Throws:
IOException- if an IO error occurred.org.apache.hadoop.security.authentication.client.AuthenticationException- if an authentication exception occurred.
-
selectDelegationToken
Select a delegation token from all tokens in credentials, based on url.- Parameters:
url- url.creds- credentials.- Returns:
- token.
-
getDelegationToken
public Token<AbstractDelegationTokenIdentifier> getDelegationToken(URL url, DelegationTokenAuthenticatedURL.Token token, String renewer) throws IOException, org.apache.hadoop.security.authentication.client.AuthenticationException Requests a delegation token using the configuredAuthenticatorfor authentication.- Parameters:
url- the URL to get the delegation token from. Only HTTP/S URLs are supported.token- the authentication token being used for the user where the Delegation token will be stored.renewer- the renewer user.- Returns:
- a delegation token.
- Throws:
IOException- if an IO error occurred.org.apache.hadoop.security.authentication.client.AuthenticationException- if an authentication exception occurred.
-
getDelegationToken
public Token<AbstractDelegationTokenIdentifier> getDelegationToken(URL url, DelegationTokenAuthenticatedURL.Token token, String renewer, String doAsUser) throws IOException, org.apache.hadoop.security.authentication.client.AuthenticationException Requests a delegation token using the configuredAuthenticatorfor authentication.- Parameters:
url- the URL to get the delegation token from. Only HTTP/S URLs are supported.token- the authentication token being used for the user where the Delegation token will be stored.renewer- the renewer user.doAsUser- the user to do as, which will be the token owner.- Returns:
- a delegation token.
- Throws:
IOException- if an IO error occurred.org.apache.hadoop.security.authentication.client.AuthenticationException- if an authentication exception occurred.
-
renewDelegationToken
public long renewDelegationToken(URL url, DelegationTokenAuthenticatedURL.Token token) throws IOException, org.apache.hadoop.security.authentication.client.AuthenticationException Renews a delegation token from the server end-point using the configuredAuthenticatorfor authentication.- Parameters:
url- the URL to renew the delegation token from. Only HTTP/S URLs are supported.token- the authentication token with the Delegation Token to renew.- Returns:
- delegation token long value.
- Throws:
IOException- if an IO error occurred.org.apache.hadoop.security.authentication.client.AuthenticationException- if an authentication exception occurred.
-
renewDelegationToken
public long renewDelegationToken(URL url, DelegationTokenAuthenticatedURL.Token token, String doAsUser) throws IOException, org.apache.hadoop.security.authentication.client.AuthenticationException Renews a delegation token from the server end-point using the configuredAuthenticatorfor authentication.- Parameters:
url- the URL to renew the delegation token from. Only HTTP/S URLs are supported.token- the authentication token with the Delegation Token to renew.doAsUser- the user to do as, which will be the token owner.- Returns:
- delegation token long value.
- Throws:
IOException- if an IO error occurred.org.apache.hadoop.security.authentication.client.AuthenticationException- if an authentication exception occurred.
-
cancelDelegationToken
public void cancelDelegationToken(URL url, DelegationTokenAuthenticatedURL.Token token) throws IOException Cancels a delegation token from the server end-point. It does not require being authenticated by the configuredAuthenticator.- Parameters:
url- the URL to cancel the delegation token from. Only HTTP/S URLs are supported.token- the authentication token with the Delegation Token to cancel.- Throws:
IOException- if an IO error occurred.
-
cancelDelegationToken
public void cancelDelegationToken(URL url, DelegationTokenAuthenticatedURL.Token token, String doAsUser) throws IOException Cancels a delegation token from the server end-point. It does not require being authenticated by the configuredAuthenticator.- Parameters:
url- the URL to cancel the delegation token from. Only HTTP/S URLs are supported.token- the authentication token with the Delegation Token to cancel.doAsUser- the user to do as, which will be the token owner.- Throws:
IOException- if an IO error occurred.
-