Example usage for org.apache.hadoop.mapreduce.security.token.delegation DelegationTokenIdentifier readFields

List of usage examples for org.apache.hadoop.mapreduce.security.token.delegation DelegationTokenIdentifier readFields

Introduction

In this page you can find the example usage for org.apache.hadoop.mapreduce.security.token.delegation DelegationTokenIdentifier readFields.

Prototype

@Override
    public void readFields(DataInput in) throws IOException 

Source Link

Usage

From source file:org.apache.storm.hive.security.AutoHive.java

License:Apache License

private Token<DelegationTokenIdentifier> getDelegationToken(HiveConf hcatConf, String metaStoreServicePrincipal,
        String topologySubmitterUser) throws IOException {
    LOG.info("Creating delegation tokens for principal={}", metaStoreServicePrincipal);

    HCatClient hcatClient = null;//from   w  w w .  ja va 2 s  .c  om
    try {
        hcatClient = HCatClient.create(hcatConf);
        String delegationToken = hcatClient.getDelegationToken(topologySubmitterUser,
                metaStoreServicePrincipal);
        Token<DelegationTokenIdentifier> delegationTokenId = new Token<DelegationTokenIdentifier>();
        delegationTokenId.decodeFromUrlString(delegationToken);

        DelegationTokenIdentifier d = new DelegationTokenIdentifier();
        d.readFields(new DataInputStream(new ByteArrayInputStream(delegationTokenId.getIdentifier())));
        LOG.info("Created Delegation Token for : " + d.getUser());

        return delegationTokenId;
    } finally {
        if (hcatClient != null)
            hcatClient.close();
    }
}