printUsage(System.out); System.exit(0); if (commandCount > 1) { System.err.println("ERROR: Only specify cancel, renew or print."); printUsage(System.err); printUsage(System.err);
@Override public Object run() throws Exception { if (print) { printTokens(conf, tokenFile, verbose); } else if (cancel) { cancelTokens(conf, tokenFile); } else if (renew) { renewTokens(conf, tokenFile); } else { // otherwise we are fetching FileSystem fs = getFileSystem(conf, webUrl); saveDelegationToken(conf, fs, renewer, tokenFile); } return null; } });
@Override public Long run() throws Exception { InetSocketAddress serviceAddr = SecurityUtil .getTokenServiceAddr(token); return DelegationTokenFetcher.renewDelegationToken(connectionFactory, DFSUtil.createUri(getUnderlyingProtocol(), serviceAddr), (Token<DelegationTokenIdentifier>) token); } });
@Override public Void run() throws Exception { InetSocketAddress serviceAddr = SecurityUtil .getTokenServiceAddr(token); DelegationTokenFetcher.cancelDelegationToken(connectionFactory, DFSUtil.createUri(getUnderlyingProtocol(), serviceAddr), (Token<DelegationTokenIdentifier>) token); return null; } });
BufferedReader in = null; try { connection = run(factory, new URL(buf.toString())); in = new BufferedReader(new InputStreamReader( connection.getInputStream(), Charsets.UTF_8)); } catch (IOException ie) { LOG.info("error in renew over HTTP", ie); IOException e = getExceptionFromResponse(connection);
DelegationTokenFetcher.main(new String[] { "-fs", uri.toString(), tokenFile }); Path p = new Path(fileSys.getWorkingDirectory(), tokenFile); assertTrue(!itr.hasNext()); DelegationTokenFetcher.main(new String[] { "-fs", uri.toString(), "--print", tokenFile }); DelegationTokenFetcher.main(new String[] { "-fs", uri.toString(), "--renew", tokenFile }); DelegationTokenFetcher.main(new String[] { "-fs", uri.toString(), "--cancel", tokenFile }); verify(dfs).renewDelegationToken(eq(t));
/** * Cancel a Delegation Token. * @param nnAddr the NameNode's address * @param tok the token to cancel * @throws IOException * @throws AuthenticationException */ static public void cancelDelegationToken(URLConnectionFactory factory, URI nnAddr, Token<DelegationTokenIdentifier> tok) throws IOException, AuthenticationException { StringBuilder buf = new StringBuilder(nnAddr.toString()) .append(CancelDelegationTokenServlet.PATH_SPEC).append("?") .append(CancelDelegationTokenServlet.TOKEN).append("=") .append(tok.encodeToUrlString()); HttpURLConnection conn = run(factory, new URL(buf.toString())); conn.disconnect(); }
@Override public Token<?> run() throws IOException { Credentials c; try { c = DelegationTokenFetcher.getDTfromRemote(connectionFactory, nnUri, renewer, proxyUser); } catch (IOException e) { if (e.getCause() instanceof ConnectException) { LOG.warn("Couldn't connect to " + nnUri + ", assuming security is disabled"); return null; } if (LOG.isDebugEnabled()) { LOG.debug("Exception getting delegation token", e); } throw e; } for (Token<? extends TokenIdentifier> t : c.getAllTokens()) { if(LOG.isDebugEnabled()) { LOG.debug("Got dt for " + getUri() + ";t.service=" +t.getService()); } return t; } return null; } });
private static HttpURLConnection run(URLConnectionFactory factory, URL url) throws IOException, AuthenticationException { HttpURLConnection conn = null; try { conn = (HttpURLConnection) factory.openConnection(url, true); if (conn.getResponseCode() != HttpURLConnection.HTTP_OK) { String msg = conn.getResponseMessage(); throw new IOException("Error when dealing remote token: " + msg); } } catch (IOException ie) { LOG.info("Error when dealing remote token:", ie); IOException e = getExceptionFromResponse(conn); if (e != null) { LOG.info("rethrowing exception from HTTP request: " + e.getLocalizedMessage()); throw e; } throw ie; } return conn; } }
@Override public Long run() throws Exception { InetSocketAddress serviceAddr = SecurityUtil .getTokenServiceAddr(token); return DelegationTokenFetcher.renewDelegationToken(connectionFactory, DFSUtil.createUri(getUnderlyingProtocol(), serviceAddr), (Token<DelegationTokenIdentifier>) token); } });
@Override public Void run() throws Exception { InetSocketAddress serviceAddr = SecurityUtil .getTokenServiceAddr(token); DelegationTokenFetcher.cancelDelegationToken(connectionFactory, DFSUtil.createUri(getUnderlyingProtocol(), serviceAddr), (Token<DelegationTokenIdentifier>) token); return null; } });
BufferedReader in = null; try { connection = run(factory, new URL(buf.toString())); in = new BufferedReader(new InputStreamReader( connection.getInputStream(), Charsets.UTF_8)); } catch (IOException ie) { LOG.info("error in renew over HTTP", ie); IOException e = getExceptionFromResponse(connection);
/** * try to fetch token without http server with IOException */ @Test public void testTokenFetchFail() throws Exception { try { DelegationTokenFetcher.main(new String[] { "-webservice=" + serviceUrl, tokenFile }); fail("Token fetcher shouldn't start in absense of NN"); } catch (IOException ex) { } }
/** * Cancel a Delegation Token. * @param nnAddr the NameNode's address * @param tok the token to cancel * @throws IOException * @throws AuthenticationException */ static public void cancelDelegationToken(URLConnectionFactory factory, URI nnAddr, Token<DelegationTokenIdentifier> tok) throws IOException, AuthenticationException { StringBuilder buf = new StringBuilder(nnAddr.toString()) .append(CancelDelegationTokenServlet.PATH_SPEC).append("?") .append(CancelDelegationTokenServlet.TOKEN).append("=") .append(tok.encodeToUrlString()); HttpURLConnection conn = run(factory, new URL(buf.toString())); conn.disconnect(); }
Credentials creds = getDTfromRemote(connectionFactory, new URI( webUrl), renewer, null); creds.writeTokenStorageFile(tokenFile, conf);
private static HttpURLConnection run(URLConnectionFactory factory, URL url) throws IOException, AuthenticationException { HttpURLConnection conn = null; try { conn = (HttpURLConnection) factory.openConnection(url, true); if (conn.getResponseCode() != HttpURLConnection.HTTP_OK) { String msg = conn.getResponseMessage(); throw new IOException("Error when dealing remote token: " + msg); } } catch (IOException ie) { LOG.info("Error when dealing remote token:", ie); IOException e = getExceptionFromResponse(conn); if (e != null) { LOG.info("rethrowing exception from HTTP request: " + e.getLocalizedMessage()); throw e; } throw ie; } return conn; } }
/** * try to fetch token without http server with IOException */ @Test public void testTokenRenewFail() throws AuthenticationException { try { DelegationTokenFetcher.renewDelegationToken(connectionFactory, serviceUrl, testToken); fail("Token fetcher shouldn't be able to renew tokens in absense of NN"); } catch (IOException ex) { } }
/** * */ @Test public void testCancelTokenFromHttp() throws IOException, AuthenticationException { bootstrap = startHttpServer(httpPort, testToken, serviceUrl); DelegationTokenFetcher.cancelDelegationToken(connectionFactory, serviceUrl, testToken); if (assertionError != null) throw assertionError; }
printUsage(System.out); System.exit(0); && print) { System.err.println("ERROR: Only specify cancel, renew or print."); printUsage(System.err); printUsage(System.err);
private static void expectDelegationTokenFetcherExit(String[] args) { try { DelegationTokenFetcher.main(args); fail("should call exit"); } catch (ExitException e) { ExitUtil.resetFirstExitException(); } catch (Exception ex) { fail("expectDelegationTokenFetcherExit ex error " + ex); } }