public KerberosWebHDFSConnection2(String httpfsUrl, String principal, String password) { this.httpfsUrl = httpfsUrl; this.principal = principal; this.password = password; Configuration conf = new Configuration(); conf.addResource("conf/hdfs-site.xml"); conf.addResource("conf/core-site.xml"); newToken = new AuthenticatedURL.Token(); KerberosAuthenticator ka = new KerberosAuthenticator(); ConnectionConfigurator connectionConfigurator = new SSLFactory(SSLFactory.Mode.CLIENT,conf); ka.setConnectionConfigurator(connectionConfigurator); try{ URL url = new URL(httpfsUrl); ka.authenticate(url,newToken); }catch(Exception e){ e.printStackTrace(); } this.authenticatedURL = new AuthenticatedURL(ka,connectionConfigurator); // this.authenticatedURL = new AuthenticatedURL( // new KerberosAuthenticator2(principal, password)); }
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; }
public static synchronized Token generateToken(String srvUrl, String princ,String passwd) { try { HttpURLConnection conn = authenticatedURL.openConnection(new URL(srvUrl),newToken); conn.connect(); conn.disconnect(); } catch (Exception ex) { logger.error(ex.getMessage()); logger.error("[" + princ + ":" + passwd + "]@" + srvUrl, ex); } return newToken; }
/** * <b>GETHOMEDIRECTORY</b> * * curl -i "http://<HOST>:<PORT>/webhdfs/v1/?op=GETHOMEDIRECTORY" * * @return * @throws MalformedURLException * @throws IOException * @throws AuthenticationException */ public String getHomeDirectory() throws MalformedURLException, IOException, AuthenticationException { // ensureValidToken(); Configuration conf = new Configuration(); conf.addResource("conf/hdfs-site.xml"); conf.addResource("conf/core-site.xml"); UserGroupInformation.setConfiguration(conf); UserGroupInformation.loginUserFromPassword("hdfs", "123456"); FileSystem fs = FileSystem.get(conf); System.out.println(fs.getDelegationToken("hdfs")); Token token0 = new AuthenticatedURL.Token("HAAEaGRmcwRoZGZzAIoBWOLlnNuKAVkG8iDbbwgU246eZ3EbfUsfNlF4F0xoew3LW3QSV0VCSERGUyBkZWxlZ2F0aW9uEDE3Mi4xNi4yLjk2OjgwMjA"); System.out.println(token0.toString()); System.out.println(fs.getDelegationToken("hdfs").encodeToUrlString()); HttpURLConnection connection = authenticatedURL.openConnection(new URL( new URL(httpfsUrl), "/webhdfs/v1/?op=GETDELEGATIONTOKEN"), token); HttpURLConnection conn = authenticatedURL.openConnection(new URL( new URL(httpfsUrl), "/webhdfs/v1/?delegation=HAAEaGRmcwRoZGZzAIoBWOLlnNuKAVkG8iDbbwgU246eZ3EbfUsfNlF4F0xoew3LW3QSV0VCSERGUyBkZWxlZ2F0aW9uEDE3Mi4xNi4yLjk2OjgwMjA&op=GETHOMEDIRECTORY"), token0); conn.connect(); connection.connect(); String ss = result(connection,true); System.out.println(ss); String resp = result(conn, true); conn.disconnect(); return resp; }
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; }
public static synchronized Token generateToken(String srvUrl, String princ, String passwd , String servicePrincpal) { AuthenticatedURL.Token newToken = new AuthenticatedURL.Token(); try { HttpURLConnection conn = new AuthenticatedURL(new KerberosAuthenticator2(princ, passwd,servicePrincpal)) .openConnection(new URL(new URL(srvUrl),"/webhdfs/v1/?op=homedir"), newToken); conn.connect(); conn.disconnect(); } catch (Exception ex) { logger.error(ex.getMessage()); logger.error("[" + princ + ": password ]@" + srvUrl, ex); } return newToken; }