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

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

Introduction

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

Prototype

public DelegationTokenAuthenticatedURL(ConnectionConfigurator connConfigurator) 

Source Link

Document

Creates an DelegationTokenAuthenticatedURL using the default DelegationTokenAuthenticator class.

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  w ww . ja  va2 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;
}