/** Print out a Credentials object. * @param creds the Credentials object to be printed out. * @param alias print only tokens matching alias (null matches all). * @param out print to this stream. * @throws IOException */ public static void printCredentials( Credentials creds, Text alias, PrintStream out) throws IOException { boolean tokenHeader = true; String fmt = "%-24s %-20s %-15s %-12s %s%n"; for (Token<?> token : creds.getAllTokens()) { if (matchAlias(token, alias)) { if (tokenHeader) { out.printf(fmt, "Token kind", "Service", "Renewer", "Exp date", "URL enc token"); out.println(StringUtils.repeat("-", 80)); tokenHeader = false; } AbstractDelegationTokenIdentifier id = (AbstractDelegationTokenIdentifier) token.decodeIdentifier(); out.printf(fmt, token.getKind(), token.getService(), (id != null) ? id.getRenewer() : NA_STRING, (id != null) ? formatDate(id.getMaxDate()) : NA_STRING, token.encodeToUrlString()); } } }
if (id.getMaxDate() < now) { throw new InvalidToken(renewer + " tried to renew an expired token " + formatTokenId(id) + " max expiration date: " + Time.formatTime(id.getMaxDate()) + " currentTime: " + Time.formatTime(now)); + formatTokenId(id) + " with wrong password"); long renewTime = Math.min(id.getMaxDate(), now + tokenRenewInterval); String trackingId = getTrackingIdIfEnabled(id); DelegationTokenInformation info = new DelegationTokenInformation(renewTime,
/** * Get the expiry time of a token. * @param token token to examine * @return the time in milliseconds after which the token is invalid. * @throws IOException */ public static long getTokenExpiryTime(Token token) throws IOException { TokenIdentifier identifier = token.decodeIdentifier(); Preconditions.checkState(identifier instanceof AbstractDelegationTokenIdentifier, "Token %s of type: %s has an identifier which cannot be examined: %s", token, token.getClass(), identifier); AbstractDelegationTokenIdentifier id = (AbstractDelegationTokenIdentifier) identifier; return id.getMaxDate(); }
/** * Get the expiry time of a token. * @param token token to examine * @return the time in milliseconds after which the token is invalid. * @throws IOException */ public static long getTokenExpiryTime(Token token) throws IOException { TokenIdentifier identifier = token.decodeIdentifier(); Preconditions.checkState(identifier instanceof AbstractDelegationTokenIdentifier, "Token %s of type: %s has an identifier which cannot be examined: %s", token, token.getClass(), identifier); AbstractDelegationTokenIdentifier id = (AbstractDelegationTokenIdentifier) identifier; return id.getMaxDate(); }
public DelegationTokenToRenew(Collection<ApplicationId> applicationIds, Token<?> token, Configuration conf, long expirationDate, boolean shouldCancelAtEnd, String user) { this.token = token; this.user = user; if (token.getKind().equals(new Text("HDFS_DELEGATION_TOKEN"))) { try { AbstractDelegationTokenIdentifier identifier = (AbstractDelegationTokenIdentifier) token.decodeIdentifier(); maxDate = identifier.getMaxDate(); } catch (IOException e) { throw new YarnRuntimeException(e); } } this.referringAppIds = Collections.synchronizedSet( new HashSet<ApplicationId>(applicationIds)); this.conf = conf; this.expirationDate = expirationDate; this.timerTask = null; this.shouldCancelAtEnd = shouldCancelAtEnd; }
/** * Create a string for people to look at * @param token token to convert to a string form * @return a printable view of the token */ public static String tokenToString(Token<? extends TokenIdentifier> token) { DateFormat df = DateFormat.getDateTimeInstance( DateFormat.SHORT, DateFormat.SHORT); StringBuilder buffer = new StringBuilder(128); buffer.append(token.toString()); try { TokenIdentifier ti = token.decodeIdentifier(); buffer.append("; ").append(ti); if (ti instanceof AbstractDelegationTokenIdentifier) { // details in human readable form, and compensate for information HDFS DT omits AbstractDelegationTokenIdentifier dt = (AbstractDelegationTokenIdentifier) ti; buffer.append("; Renewer: ").append(dt.getRenewer()); buffer.append("; Issued: ") .append(df.format(new Date(dt.getIssueDate()))); buffer.append("; Max Date: ") .append(df.format(new Date(dt.getMaxDate()))); } } catch (IOException e) { //marshall problem; not ours LOG.debug("Failed to decode {}: {}", token, e, e); } return buffer.toString(); }
/** * Create a string for people to look at * @param token token to convert to a string form * @return a printable view of the token */ public static String tokenToString(Token<? extends TokenIdentifier> token) { DateFormat df = DateFormat.getDateTimeInstance( DateFormat.SHORT, DateFormat.SHORT); StringBuilder buffer = new StringBuilder(128); buffer.append(token.toString()); try { TokenIdentifier ti = token.decodeIdentifier(); buffer.append("; ").append(ti); if (ti instanceof AbstractDelegationTokenIdentifier) { // details in human readable form, and compensate for information HDFS DT omits AbstractDelegationTokenIdentifier dt = (AbstractDelegationTokenIdentifier) ti; buffer.append("; Renewer: ").append(dt.getRenewer()); buffer.append("; Issued: ") .append(df.format(new Date(dt.getIssueDate()))); buffer.append("; Max Date: ") .append(df.format(new Date(dt.getMaxDate()))); } } catch (IOException e) { //marshall problem; not ours LOG.debug("Failed to decode {}: {}", token, e, e); } return buffer.toString(); }
public DelegationTokenToRenew(Collection<ApplicationId> applicationIds, Token<?> token, Configuration conf, long expirationDate, boolean shouldCancelAtEnd, String user) { this.token = token; this.user = user; if (token.getKind().equals(new Text("HDFS_DELEGATION_TOKEN"))) { try { AbstractDelegationTokenIdentifier identifier = (AbstractDelegationTokenIdentifier) token.decodeIdentifier(); maxDate = identifier.getMaxDate(); } catch (IOException e) { throw new YarnRuntimeException(e); } } this.referringAppIds = Collections.synchronizedSet( new HashSet<ApplicationId>(applicationIds)); this.conf = conf; this.expirationDate = expirationDate; this.timerTask = null; this.shouldCancelAtEnd = shouldCancelAtEnd; }
public DelegationTokenToRenew(Collection<ApplicationId> applicationIds, Token<?> token, Configuration conf, long expirationDate, boolean shouldCancelAtEnd, String user) { this.token = token; this.user = user; if (token.getKind().equals(HDFS_DELEGATION_KIND)) { try { AbstractDelegationTokenIdentifier identifier = (AbstractDelegationTokenIdentifier) token.decodeIdentifier(); maxDate = identifier.getMaxDate(); } catch (IOException e) { throw new YarnRuntimeException(e); } } this.referringAppIds = Collections.synchronizedSet( new HashSet<ApplicationId>(applicationIds)); this.conf = conf; this.expirationDate = expirationDate; this.timerTask = null; this.shouldCancelAtEnd = shouldCancelAtEnd; }
if (id.getMaxDate() < now) { throw new InvalidToken(renewer + " tried to renew an expired token"); " is trying to renew a token with wrong password"); long renewTime = Math.min(id.getMaxDate(), now + tokenRenewInterval); String trackingId = getTrackingIdIfEnabled(id); DelegationTokenInformation info = new DelegationTokenInformation(renewTime,
if (id.getMaxDate() < now) { throw new InvalidToken(renewer + " tried to renew an expired token"); " is trying to renew a token with wrong password"); long renewTime = Math.min(id.getMaxDate(), now + tokenRenewInterval); String trackingId = getTrackingIdIfEnabled(id); DelegationTokenInformation info = new DelegationTokenInformation(renewTime,
if (id.getMaxDate() < now) { throw new InvalidToken(renewer + " tried to renew an expired token"); " is trying to renew a token with wrong password"); long renewTime = Math.min(id.getMaxDate(), now + tokenRenewInterval); String trackingId = getTrackingIdIfEnabled(id); DelegationTokenInformation info = new DelegationTokenInformation(renewTime,
if (id.getMaxDate() < now) { throw new InvalidToken(renewer + " tried to renew an expired token " + formatTokenId(id) + " max expiration date: " + Time.formatTime(id.getMaxDate()) + " currentTime: " + Time.formatTime(now)); + formatTokenId(id) + " with wrong password"); long renewTime = Math.min(id.getMaxDate(), now + tokenRenewInterval); String trackingId = getTrackingIdIfEnabled(id); DelegationTokenInformation info = new DelegationTokenInformation(renewTime,