Example usage for org.apache.hadoop.hdfs.security.token.block BlockTokenIdentifier getBytes

List of usage examples for org.apache.hadoop.hdfs.security.token.block BlockTokenIdentifier getBytes

Introduction

In this page you can find the example usage for org.apache.hadoop.hdfs.security.token.block BlockTokenIdentifier getBytes.

Prototype

@Override
    public byte[] getBytes() 

Source Link

Usage

From source file:io.hops.metadata.security.token.block.NameNodeBlockTokenSecretManager.java

License:Apache License

@Override
protected byte[] createPassword(BlockTokenIdentifier identifier) {
    BlockKey key;//from  w w w . jav a 2 s . c  o  m
    try {
        key = getBlockKeyByType(BlockKey.KeyType.CurrKey);
    } catch (IOException ex) {
        throw new IllegalStateException("currentKey hasn't been initialized. [" + ex.getMessage() + "]");
    }
    if (key == null) {
        throw new IllegalStateException("currentKey hasn't been initialized.");
    }
    identifier.setExpiryDate(Time.now() + tokenLifetime);
    identifier.setKeyId(key.getKeyId());
    if (LOG.isDebugEnabled()) {
        LOG.debug("Generating block token for " + identifier.toString());
    }
    return createPassword(identifier.getBytes(), key.getKey());
}

From source file:io.hops.metadata.security.token.block.NameNodeBlockTokenSecretManager.java

License:Apache License

@Override
public byte[] retrievePassword(BlockTokenIdentifier identifier) throws InvalidToken {
    if (isExpired(identifier.getExpiryDate())) {
        throw new InvalidToken("Block token with " + identifier.toString() + " is expired.");
    }/*from   ww w  .j  ava2  s  .com*/
    BlockKey key = null;
    try {
        key = getBlockKeyById(identifier.getKeyId());
    } catch (IOException ex) {
    }

    if (key == null) {
        throw new InvalidToken("Can't re-compute password for " + identifier.toString()
                + ", since the required block key (keyID=" + identifier.getKeyId() + ") doesn't exist.");
    }
    return createPassword(identifier.getBytes(), key.getKey());
}