public abstract class AbstractCredentialStore extends Object implements CredentialStore
Modifier and Type | Field and Description |
---|---|
protected static String |
DEFAULT_STORE_TYPE |
Constructor and Description |
---|
AbstractCredentialStore() |
Modifier and Type | Method and Description |
---|---|
protected void |
addCredential(KeyStore keyStore,
String alias,
Credential credential)
Adds a new credential to the supplied KeyStore
The supplied key will be converted into UTF-8 bytes before being stored.
|
void |
addCredential(String alias,
Credential credential)
Adds a new credential to this CredentialStore
The supplied key will be converted into UTF-8 bytes before being stored.
|
boolean |
containsCredential(String alias)
Tests this CredentialStore for the existence of a credential with the specified alias
This implementation is thread-safe, allowing one thread at a time to access the credential store.
|
protected Credential |
getCredential(KeyStore keyStore,
String alias)
Retrieves the specified credential from a KeyStore
|
Credential |
getCredential(String alias)
Retrieves the specified credential from this CredentialStore
This implementation is thread-safe, allowing one thread at a time to access the credential store.
|
protected Lock |
getLock()
Gets the lock object used to protect access to the credential store
|
Set<String> |
listCredentials()
Returns a list of the alias names for the credentials stored in the CredentialStore
This implementation is thread-safe, allowing one thread at a time to access the credential store.
|
protected abstract KeyStore |
loadCredentialStore()
Calls the implementation-specific facility to load the KeyStore
|
protected KeyStore |
loadKeyStore(InputStream inputStream,
String keyStoreType)
Loads a KeyStore from an InputStream
Implementations are expected to call this to load the relevant KeyStore data from the
InputStream of some storage facility.
|
protected abstract void |
persistCredentialStore(KeyStore keyStore)
Calls the implementation-specific facility to persist the KeyStore
|
void |
removeCredential(String alias)
Removes the specified credential from this CredentialStore
This implementation is thread-safe, allowing one thread at a time to access the credential store.
|
void |
setMasterKeyService(MasterKeyService masterKeyService)
Sets the MasterKeyService for this CredentialStore
|
protected byte[] |
toBytes(char[] chars)
Converts an array of characters to an array of bytes by encoding each character into UTF-8 bytes.
|
protected char[] |
toChars(byte[] bytes)
Converts an array of bytes to an array of character by decoding the bytes using the UTF-8
character set.
|
protected void |
writeKeyStore(KeyStore keyStore,
OutputStream outputStream)
Writes a KeyStore to an OutputStream
Implementations are expected to call this to write the relevant KeyStore data to the
OutputStream of some storage facility.
|
protected static final String DEFAULT_STORE_TYPE
public void addCredential(String alias, Credential credential) throws org.apache.ambari.server.AmbariException
addCredential
in interface CredentialStore
alias
- a string declaring the alias (or name) of the credentialcredential
- the credential to storeorg.apache.ambari.server.AmbariException
- if an error occurs while storing the new credentialpublic Credential getCredential(String alias) throws org.apache.ambari.server.AmbariException
getCredential
in interface CredentialStore
alias
- a string declaring the alias (or name) of the credentialorg.apache.ambari.server.AmbariException
- if an error occurs while retrieving the new credentialpublic void removeCredential(String alias) throws org.apache.ambari.server.AmbariException
removeCredential
in interface CredentialStore
alias
- a string declaring the alias (or name) of the credentialorg.apache.ambari.server.AmbariException
- if an error occurs while removing the new credentialpublic Set<String> listCredentials() throws org.apache.ambari.server.AmbariException
listCredentials
in interface CredentialStore
org.apache.ambari.server.AmbariException
- if an error occurs while searching forthe credentialpublic boolean containsCredential(String alias) throws org.apache.ambari.server.AmbariException
containsCredential
in interface CredentialStore
alias
- a string declaring the alias (or name) of the credentialorg.apache.ambari.server.AmbariException
- if an error occurs while searching forthe credentialpublic void setMasterKeyService(MasterKeyService masterKeyService)
CredentialStore
setMasterKeyService
in interface CredentialStore
masterKeyService
- the MasterKeyServiceprotected void addCredential(KeyStore keyStore, String alias, Credential credential) throws org.apache.ambari.server.AmbariException
keyStore
- the KeyStorealias
- a string declaring the alias (or name) of the credentialcredential
- the credential to storeorg.apache.ambari.server.AmbariException
- if an error occurs while storing the new credentialprotected Credential getCredential(KeyStore keyStore, String alias) throws org.apache.ambari.server.AmbariException
keyStore
- the KeyStorealias
- a string declaring the alias (or name) of the credentialorg.apache.ambari.server.AmbariException
- if an error occurs while retrieving the new credentialprotected abstract void persistCredentialStore(KeyStore keyStore) throws org.apache.ambari.server.AmbariException
keyStore
- the KeyStore to persistorg.apache.ambari.server.AmbariException
- if an error occurs while persisting the key store dataprotected abstract KeyStore loadCredentialStore() throws org.apache.ambari.server.AmbariException
org.apache.ambari.server.AmbariException
- if an error occurs while loading the key store dataprotected Lock getLock()
protected KeyStore loadKeyStore(InputStream inputStream, String keyStoreType) throws org.apache.ambari.server.AmbariException
inputStream
- the InputStream to read the data fromkeyStoreType
- the type of key store data expectedorg.apache.ambari.server.AmbariException
- if an error occurs while loading the key store data from the InputStreamprotected void writeKeyStore(KeyStore keyStore, OutputStream outputStream) throws org.apache.ambari.server.AmbariException
keyStore
- the KeyStore to writeoutputStream
- the OutputStream to write the data intoorg.apache.ambari.server.AmbariException
- if an error occurs while writing the key store dataprotected byte[] toBytes(char[] chars)
chars
- the array of chars to convertprotected char[] toChars(byte[] bytes)
bytes
- the array of bytes to convertCopyright © 2022 Apache Software Foundation. All rights reserved.