Example usage for org.apache.hadoop.security.authentication.client AuthenticatedURL AuthenticatedURL

List of usage examples for org.apache.hadoop.security.authentication.client AuthenticatedURL AuthenticatedURL

Introduction

In this page you can find the example usage for org.apache.hadoop.security.authentication.client AuthenticatedURL AuthenticatedURL.

Prototype

public AuthenticatedURL(Authenticator authenticator, ConnectionConfigurator connConfigurator) 

Source Link

Document

Creates an AuthenticatedURL.

Usage

From source file:io.hops.merge.SecurityUtil2.java

License:Apache License

/**
 * Open a (if need be) secure connection to a URL in a secure environment
 * that is using SPNEGO to authenticate its URLs. All Namenode and Secondary
 * Namenode URLs that are protected via SPNEGO should be accessed via this
 * method./* w w w.  jav  a  2s .c  o  m*/
 *
 * @param url
 *     to authenticate via SPNEGO.
 * @return A connection that has been authenticated via SPNEGO
 * @throws IOException
 *     If unable to authenticate via SPNEGO
 */
public static URLConnection openSecureHttpConnection(URL url) throws IOException {
    if (!HttpConfig2.isSecure() && !UserGroupInformation.isSecurityEnabled()) {
        return url.openConnection();
    }

    AuthenticatedURL.Token token = new AuthenticatedURL.Token();
    try {
        return new AuthenticatedURL(null, sslFactory).openConnection(url, token);
    } catch (AuthenticationException e) {
        throw new IOException("Exception trying to open authenticated connection to " + url, e);
    }
}

From source file:org.apache.slider.core.restclient.SliderURLConnectionFactory.java

License:Apache License

/**
 * Opens a url with read and connect timeouts
 *
 * @param url//  w  w w  .ja v  a2s . co m
 *          URL to open
 * @param isSpnego
 *          whether the url should be authenticated via SPNEGO
 * @return URLConnection
 * @throws IOException
 * @throws AuthenticationException
 */
public URLConnection openConnection(URL url, boolean isSpnego) throws IOException, AuthenticationException {
    if (isSpnego) {
        log.debug("open AuthenticatedURL connection {}", url);
        UserGroupInformation.getCurrentUser().checkTGTAndReloginFromKeytab();
        final AuthenticatedURL.Token authToken = new AuthenticatedURL.Token();
        return new AuthenticatedURL(new KerberosUgiAuthenticator(), connConfigurator).openConnection(url,
                authToken);
    } else {
        log.debug("open URL connection {}", url);
        URLConnection connection = url.openConnection();
        if (connection instanceof HttpURLConnection) {
            connConfigurator.configure((HttpURLConnection) connection);
        }
        return connection;
    }
}