Package org.apache.hadoop.security
Class Credentials
java.lang.Object
org.apache.hadoop.security.Credentials
- All Implemented Interfaces:
Writable
A class that provides the facilities of reading and writing
secret keys and Tokens.
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionCreate an empty credentials instance.Credentials(Credentials credentials) Create a copy of the given credentials. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddAll(Credentials other) Copy all of the credentials from one credential object into another.voidaddSecretKey(Text alias, byte[] key) Set the key for an alias.voidaddToken(Text alias, Token<? extends TokenIdentifier> t) Add a token in the storage (in memory).Return all the secret key entries in the in-memory map.Collection<Token<? extends TokenIdentifier>>Return all the tokens in the in-memory map.byte[]getSecretKey(Text alias) Returns the key bytes for the alias.Returns an unmodifiable version of the full map of aliases to secret keys.Token<? extends TokenIdentifier>Returns the Token object for the alias.Map<Text,Token<? extends TokenIdentifier>> Returns an unmodifiable version of the full map of aliases to Tokens.voidmergeAll(Credentials other) Copy all of the credentials from one credential object into another.intintvoidreadFields(DataInput in) Loads all the keys.static CredentialsreadTokenStorageFile(File filename, Configuration conf) Convenience method for reading a token storage file and loading its Tokens.static CredentialsreadTokenStorageFile(Path filename, Configuration conf) Convenience method for reading a token storage file and loading its Tokens.voidConvenience method for reading a token from a DataInputStream.voidremoveSecretKey(Text alias) Remove the key for a given alias.voidremoveToken(Text alias) Remove a token from the storage (in memory).voidwrite(DataOutput out) Stores all the keys to DataOutput.voidwriteTokenStorageFile(Path filename, Configuration conf) voidwriteTokenStorageFile(Path filename, Configuration conf, Credentials.SerializedFormat format) voidvoid
-
Constructor Details
-
Credentials
public Credentials()Create an empty credentials instance. -
Credentials
Create a copy of the given credentials.- Parameters:
credentials- to copy
-
-
Method Details
-
getToken
Returns the Token object for the alias.- Parameters:
alias- the alias for the Token- Returns:
- token for this alias
-
addToken
Add a token in the storage (in memory).- Parameters:
alias- the alias for the keyt- the token object
-
removeToken
Remove a token from the storage (in memory).- Parameters:
alias- the alias for the key
-
getAllTokens
Return all the tokens in the in-memory map.- Returns:
- all the tokens in the in-memory map.
-
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
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
Set the key for an alias.- Parameters:
alias- the alias for the keykey- the key bytes
-
removeSecretKey
Remove the key for a given alias.- Parameters:
alias- the alias for the key
-
getAllSecretKeys
Return all the secret key entries in the in-memory map.- Returns:
- Text List.
-
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
Convenience method for reading a token from a DataInputStream.- Parameters:
in- DataInputStream.- Throws:
IOException- raised on errors performing I/O.
-
writeTokenStorageToStream
- Throws:
IOException
-
writeTokenStorageToStream
public void writeTokenStorageToStream(DataOutputStream os, Credentials.SerializedFormat format) throws IOException - Throws:
IOException
-
writeTokenStorageFile
- Throws:
IOException
-
writeTokenStorageFile
public void writeTokenStorageFile(Path filename, Configuration conf, Credentials.SerializedFormat format) throws IOException - Throws:
IOException
-
write
Stores all the keys to DataOutput.- Specified by:
writein interfaceWritable- Parameters:
out- DataOutput.- Throws:
IOException- raised on errors performing I/O.
-
readFields
Loads all the keys.- Specified by:
readFieldsin interfaceWritable- Parameters:
in- DataInput.- Throws:
IOException- raised on errors performing I/O.
-
addAll
Copy all of the credentials from one credential object into another. Existing secrets and tokens are overwritten.- Parameters:
other- the credentials to copy
-
mergeAll
Copy all of the credentials from one credential object into another. Existing secrets and tokens are not overwritten.- Parameters:
other- the credentials to copy
-