Example usage for org.apache.hadoop.security.token.delegation AbstractDelegationTokenIdentifier getMaxDate

List of usage examples for org.apache.hadoop.security.token.delegation AbstractDelegationTokenIdentifier getMaxDate

Introduction

In this page you can find the example usage for org.apache.hadoop.security.token.delegation AbstractDelegationTokenIdentifier getMaxDate.

Prototype

public long getMaxDate() 

Source Link

Usage

From source file:org.apache.slider.core.launch.CredentialUtils.java

License:Apache License

/**
 * Create a string for people to look at
 * @param token token to convert to a string form
 * @return a printable view of the token
 *//*from www .j a  v  a 2s  .  c om*/
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();
}

From source file:org.apache.slider.core.launch.CredentialUtils.java

License:Apache License

/**
 * Get the expiry time of a token./*from w w w  .  j av a2 s  . c o m*/
 * @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();
}