Package org.apache.hadoop.security

Class Credentials

java.lang.Object
org.apache.hadoop.security.Credentials
All Implemented Interfaces:
Writable

@Public @Evolving public class Credentials extends Object implements Writable
A class that provides the facilities of reading and writing secret keys and Tokens.
  • Constructor Details

    • Credentials

      public Credentials()
      Create an empty credentials instance.
    • Credentials

      public Credentials(Credentials credentials)
      Create a copy of the given credentials.
      Parameters:
      credentials - to copy
  • Method Details

    • getToken

      public Token<? extends TokenIdentifier> getToken(Text alias)
      Returns the Token object for the alias.
      Parameters:
      alias - the alias for the Token
      Returns:
      token for this alias
    • addToken

      public void addToken(Text alias, Token<? extends TokenIdentifier> t)
      Add a token in the storage (in memory).
      Parameters:
      alias - the alias for the key
      t - the token object
    • removeToken

      public void removeToken(Text alias)
      Remove a token from the storage (in memory).
      Parameters:
      alias - the alias for the key
    • getAllTokens

      public Collection<Token<? extends TokenIdentifier>> getAllTokens()
      Return all the tokens in the in-memory map.
      Returns:
      all the tokens in the in-memory map.
    • getTokenMap

      public Map<Text,Token<? extends TokenIdentifier>> getTokenMap()
      Returns an unmodifiable version of the full map of aliases to Tokens.
      Returns:
      TokenMap.
    • numberOfTokens

      public int numberOfTokens()
      Returns:
      number of Tokens in the in-memory map
    • getSecretKey

      public byte[] getSecretKey(Text alias)
      Returns the key bytes for the alias.
      Parameters:
      alias - the alias for the key
      Returns:
      key for this alias
    • numberOfSecretKeys

      public int numberOfSecretKeys()
      Returns:
      number of keys in the in-memory map
    • addSecretKey

      public void addSecretKey(Text alias, byte[] key)
      Set the key for an alias.
      Parameters:
      alias - the alias for the key
      key - the key bytes
    • removeSecretKey

      public void removeSecretKey(Text alias)
      Remove the key for a given alias.
      Parameters:
      alias - the alias for the key
    • getAllSecretKeys

      public List<Text> getAllSecretKeys()
      Return all the secret key entries in the in-memory map.
      Returns:
      Text List.
    • getSecretKeyMap

      public Map<Text,byte[]> getSecretKeyMap()
      Returns an unmodifiable version of the full map of aliases to secret keys.
      Returns:
      SecretKeyMap.
    • readTokenStorageFile

      public static Credentials readTokenStorageFile(Path filename, Configuration conf) throws IOException
      Convenience method for reading a token storage file and loading its Tokens.
      Parameters:
      filename - filename.
      conf - configuration.
      Returns:
      Credentials.
      Throws:
      IOException - raised on errors performing I/O.
    • readTokenStorageFile

      public static Credentials readTokenStorageFile(File filename, Configuration conf) throws IOException
      Convenience method for reading a token storage file and loading its Tokens.
      Parameters:
      filename - filename.
      conf - configuration.
      Returns:
      Token.
      Throws:
      IOException - raised on errors performing I/O.
    • readTokenStorageStream

      public void readTokenStorageStream(DataInputStream in) throws IOException
      Convenience method for reading a token from a DataInputStream.
      Parameters:
      in - DataInputStream.
      Throws:
      IOException - raised on errors performing I/O.
    • writeTokenStorageToStream

      public void writeTokenStorageToStream(DataOutputStream os) throws IOException
      Throws:
      IOException
    • writeTokenStorageToStream

      public void writeTokenStorageToStream(DataOutputStream os, Credentials.SerializedFormat format) throws IOException
      Throws:
      IOException
    • writeTokenStorageFile

      public void writeTokenStorageFile(Path filename, Configuration conf) throws IOException
      Throws:
      IOException
    • writeTokenStorageFile

      public void writeTokenStorageFile(Path filename, Configuration conf, Credentials.SerializedFormat format) throws IOException
      Throws:
      IOException
    • write

      public void write(DataOutput out) throws IOException
      Stores all the keys to DataOutput.
      Specified by:
      write in interface Writable
      Parameters:
      out - DataOutput.
      Throws:
      IOException - raised on errors performing I/O.
    • readFields

      public void readFields(DataInput in) throws IOException
      Loads all the keys.
      Specified by:
      readFields in interface Writable
      Parameters:
      in - DataInput.
      Throws:
      IOException - raised on errors performing I/O.
    • addAll

      public void addAll(Credentials other)
      Copy all of the credentials from one credential object into another. Existing secrets and tokens are overwritten.
      Parameters:
      other - the credentials to copy
    • mergeAll

      public void mergeAll(Credentials other)
      Copy all of the credentials from one credential object into another. Existing secrets and tokens are not overwritten.
      Parameters:
      other - the credentials to copy