public static synchronized Token generateToken(String srvUrl, String princ, String passwd) { AuthenticatedURL.Token newToken = new AuthenticatedURL.Token(); Authenticator authenticator = new PseudoAuthenticator(princ); try { String spec = MessageFormat.format( "/webhdfs/v1/?op=GETHOMEDIRECTORY&user.name={0}", princ); HttpURLConnection conn = new AuthenticatedURL(authenticator) .openConnection(new URL(new URL(srvUrl), spec), newToken); conn.connect(); conn.disconnect(); } catch (Exception ex) { logger.error(ex.getMessage()); logger.error("[" + princ + ":" + passwd + "]@" + srvUrl, ex); } return newToken; }
public static synchronized Token generateToken(String srvUrl, String princ, String passwd) { AuthenticatedURL.Token newToken = new AuthenticatedURL.Token(); Authenticator authenticator = new PseudoAuthenticator2(princ); try { String spec = MessageFormat.format( "/webhdfs/v1/?op=GETHOMEDIRECTORY&user.name={0}", princ); HttpURLConnection conn = new AuthenticatedURL(authenticator) .openConnection(new URL(new URL(srvUrl), spec), newToken); conn.connect(); conn.disconnect(); } catch (Exception ex) { logger.error(ex.getMessage()); logger.error("[" + princ + ":" + passwd + "]@" + srvUrl, ex); // WARN // throws MalformedURLException, IOException, // AuthenticationException, InterruptedException } return newToken; }
/** * Convenience method that creates a <code>HttpURLConnection</code> for the specified URL. * <p/> * This methods performs and injects any needed authentication credentials. * * @param url url to connect to. * @param method the HTTP method. * * @return a <code>HttpURLConnection</code> for the HttpFSServer server, authenticated and ready to use for * the specified path and file system operation. * * @throws IOException thrown if an IO error occurrs. */ private HttpURLConnection getConnection(URL url, String method) throws IOException { Class<? extends Authenticator> klass = getConf().getClass("httpfs.authenticator.class", HttpFSKerberosAuthenticator.class, Authenticator.class); Authenticator authenticator = ReflectionUtils.newInstance(klass, getConf()); try { HttpURLConnection conn = new AuthenticatedURL(authenticator).openConnection(url, authToken); conn.setRequestMethod(method); if (method.equals(HTTP_POST) || method.equals(HTTP_PUT)) { conn.setDoOutput(true); } return conn; } catch (Exception ex) { throw new IOException(ex); } }
/** * Convenience method that creates a <code>HttpURLConnection</code> for the * specified URL. * <p/> * This methods performs and injects any needed authentication credentials. * * @param url * url to connect to. * @param method * the HTTP method. * @return a <code>HttpURLConnection</code> for the HttpFSServer server, * authenticated and ready to use for * the specified path and file system operation. * @throws IOException * thrown if an IO error occurrs. */ private HttpURLConnection getConnection(URL url, String method) throws IOException { Class<? extends Authenticator> klass = getConf() .getClass("httpfs.authenticator.class", HttpFSKerberosAuthenticator.class, Authenticator.class); Authenticator authenticator = ReflectionUtils.newInstance(klass, getConf()); try { HttpURLConnection conn = new AuthenticatedURL(authenticator).openConnection(url, authToken); conn.setRequestMethod(method); if (method.equals(HTTP_POST) || method.equals(HTTP_PUT)) { conn.setDoOutput(true); } return conn; } catch (Exception ex) { throw new IOException(ex); } }
public KerberosDelegationTokenAuthenticator() { super(new KerberosAuthenticator() { @Override protected Authenticator getFallBackAuthenticator() { return new PseudoDelegationTokenAuthenticator(); } }); }
@Override protected Authenticator getFallBackAuthenticator() { return new PseudoAuthenticator() { @Override protected String getUserName() { try { return UserGroupInformation.getLoginUser().getUserName(); } catch (IOException e) { throw new SecurityException("Failed to obtain current username", e); } } }; }
public static synchronized Token generateToken(String srvUrl, String princ, String passwd, AuthenticationType authenticationType) { AuthenticatedURL.Token newToken = new AuthenticatedURL.Token(); Authenticator authenticator = null; String spec; if (authenticationType == AuthenticationType.KERBEROS) { authenticator = new KerberosAuthenticator2(princ,passwd); spec = "/webhdfs/v1/?op=GETHOMEDIRECTORY"; } else { authenticator = new PseudoAuthenticator2(princ); spec = MessageFormat.format("/webhdfs/v1/?op=GETHOMEDIRECTORY&user.name={0}", princ); } try { HttpURLConnection conn = new AuthenticatedURL(authenticator).openConnection(new URL(new URL(srvUrl), spec), newToken); conn.connect(); conn.disconnect(); } catch (Exception ex) { logger.error(ex.getMessage()); logger.error("[" + princ + ":" + passwd + "]@" + srvUrl, ex); // WARN // throws IOException, // AuthenticationException, InterruptedException } return newToken; }
private static Authenticator getTokenAuthenticator() throws TezException { String authenticatorClazzName; if (UserGroupInformation.isSecurityEnabled()) { authenticatorClazzName = KERBEROS_DELEGATION_TOKEN_AUTHENTICATOR_CLAZZ_NAME; } else { authenticatorClazzName = PSEUDO_DELEGATION_TOKEN_AUTHENTICATOR_CLAZZ_NAME; } return ReflectionUtils.createClazzInstance(authenticatorClazzName); }
public TokenAuthenticatedURLConnectionFactory(ConnectionConfigurator connConfigurator, Authenticator authenticator, UserGroupInformation authUgi, String doAsUser) throws TezException { this.connConfigurator = connConfigurator; this.authenticator = authenticator; this.authUgi = authUgi; this.doAsUser = doAsUser; this.token = ReflectionUtils.createClazzInstance( DELEGATION_TOKEN_AUTHENTICATED_URL_TOKEN_CLASS_NAME, null, null); }
public DelegationTokenAuthenticator(Authenticator authenticator) { this.authenticator = authenticator; }
/** * If the specified URL does not support SPNEGO authentication, a fallback * {@link Authenticator} will be used. * <p/> * This implementation returns a {@link PseudoAuthenticator}. * * @return the fallback {@link Authenticator}. */ protected Authenticator getFallBackAuthenticator() { return new PseudoAuthenticator(); }
/** * Returns the fallback authenticator if the server does not use * Kerberos SPNEGO HTTP authentication. * * @return a {@link HttpFSPseudoAuthenticator} instance. */ @Override protected Authenticator getFallBackAuthenticator() { return new HttpFSPseudoAuthenticator(); }