Example usage for org.apache.hadoop.security.token.delegation.web DelegationTokenAuthenticatedURL getDelegationToken

List of usage examples for org.apache.hadoop.security.token.delegation.web DelegationTokenAuthenticatedURL getDelegationToken

Introduction

In this page you can find the example usage for org.apache.hadoop.security.token.delegation.web DelegationTokenAuthenticatedURL getDelegationToken.

Prototype

public org.apache.hadoop.security.token.Token<AbstractDelegationTokenIdentifier> getDelegationToken(URL url,
        Token token, String renewer) throws IOException, AuthenticationException 

Source Link

Document

Requests a delegation token using the configured Authenticator for authentication.

Usage

From source file:org.apache.sqoop.client.request.ResourceRequest.java

License:Apache License

public Token<?>[] addDelegationTokens(String strURL, String renewer, Credentials credentials)
        throws IOException {
    Token<?>[] tokens = null;/*from  ww w.  j a  v a2  s. c  om*/
    Text dtService = getDelegationTokenService(strURL);
    Token<?> token = credentials.getToken(dtService);
    if (token == null) {
        URL url = new URL(strURL);
        DelegationTokenAuthenticatedURL authUrl = new DelegationTokenAuthenticatedURL(
                new ConnectionConfigurator() {
                    @Override
                    public HttpURLConnection configure(HttpURLConnection conn) throws IOException {
                        return conn;
                    }
                });
        try {
            token = authUrl.getDelegationToken(url, authToken, renewer);
            if (token != null) {
                credentials.addToken(token.getService(), token);
                tokens = new Token<?>[] { token };
            } else {
                throw new IOException("Got NULL as delegation token");
            }
        } catch (AuthenticationException ex) {
            throw new IOException(ex);
        }
    }
    return tokens;
}