Package org.forgerock.audit.secure
Class KeyStoreHandlerDecorator
- java.lang.Object
-
- org.forgerock.audit.secure.KeyStoreHandlerDecorator
-
- All Implemented Interfaces:
KeyStoreHandler
public class KeyStoreHandlerDecorator extends Object implements KeyStoreHandler
Decorate aKeyStoreHandler
in order to add some commons utility methods to read or write keystore's entries.
-
-
Constructor Summary
Constructors Constructor Description KeyStoreHandlerDecorator(KeyStoreHandler delegate)
Constructs a new KeyStoreHandlerDecorator.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description String
getLocation()
Returns the path to the keystore.String
getPassword()
Returns the password.KeyStore
getStore()
Get the keystore.String
getType()
Returns the type of the keystore.PrivateKey
readPrivateKeyFromKeyStore(String alias)
Get a private key for the alias using the default password fromgetPassword()
.PrivateKey
readPrivateKeyFromKeyStore(String alias, String password)
Get the private key with the given alias.PublicKey
readPublicKeyFromKeyStore(String alias)
Get the public key with the given alias.SecretKey
readSecretKeyFromKeyStore(String alias)
Get the secret key with the given alias using the default password fromgetPassword()
.SecretKey
readSecretKeyFromKeyStore(String alias, String password)
Get the secret key with the given alias.void
setStore(KeyStore keystore)
Sets the keystore.void
store()
Saves the keystore.void
writeToKeyStore(SecretKey secretKey, String alias)
Writes to the secret storage using the same password than the KeyStoreHandler.void
writeToKeyStore(SecretKey secretKey, String alias, String password)
Writes to the secret storage.
-
-
-
Constructor Detail
-
KeyStoreHandlerDecorator
public KeyStoreHandlerDecorator(KeyStoreHandler delegate)
Constructs a new KeyStoreHandlerDecorator.- Parameters:
delegate
- the KeyStoreHandler to decorate.
-
-
Method Detail
-
writeToKeyStore
public void writeToKeyStore(SecretKey secretKey, String alias) throws SecureStorageException
Writes to the secret storage using the same password than the KeyStoreHandler.- Parameters:
secretKey
- The data to be written to the secret storagealias
- The kind of cryptoMaterial, whether it is a signature or a key- Throws:
SecureStorageException
- if it fails to write secret data from secret store
-
writeToKeyStore
public void writeToKeyStore(SecretKey secretKey, String alias, String password) throws SecureStorageException
Writes to the secret storage.- Parameters:
secretKey
- The data to be written to the secret storagealias
- The kind of cryptoMaterial, whether it is a signature or a keypassword
- The password to read the key- Throws:
SecureStorageException
- if it fails to write secret data from secret store
-
readPublicKeyFromKeyStore
public PublicKey readPublicKeyFromKeyStore(String alias) throws SecureStorageException
Get the public key with the given alias.- Parameters:
alias
- The alias.- Returns:
- The key.
- Throws:
SecureStorageException
- If the key could not be read.
-
readPrivateKeyFromKeyStore
public PrivateKey readPrivateKeyFromKeyStore(String alias) throws SecureStorageException
Get a private key for the alias using the default password fromgetPassword()
.- Parameters:
alias
- The alias.- Returns:
- The key.
- Throws:
SecureStorageException
- If the key could not be read.
-
readPrivateKeyFromKeyStore
public PrivateKey readPrivateKeyFromKeyStore(String alias, String password) throws SecureStorageException
Get the private key with the given alias.- Parameters:
alias
- The alias.password
- The password to use to access the keystore.- Returns:
- The key.
- Throws:
SecureStorageException
- If the key could not be read.
-
readSecretKeyFromKeyStore
public SecretKey readSecretKeyFromKeyStore(String alias) throws SecureStorageException
Get the secret key with the given alias using the default password fromgetPassword()
.- Parameters:
alias
- The alias.- Returns:
- The key.
- Throws:
SecureStorageException
- If the key could not be read.
-
readSecretKeyFromKeyStore
public SecretKey readSecretKeyFromKeyStore(String alias, String password) throws SecureStorageException
Get the secret key with the given alias.- Parameters:
alias
- The alias.password
- The password to use to access the keystore.- Returns:
- The key.
- Throws:
SecureStorageException
- If the key could not be read.
-
getStore
public KeyStore getStore()
Description copied from interface:KeyStoreHandler
Get the keystore.- Specified by:
getStore
in interfaceKeyStoreHandler
- Returns:
- the keystore.
-
setStore
public void setStore(KeyStore keystore) throws Exception
Description copied from interface:KeyStoreHandler
Sets the keystore.- Specified by:
setStore
in interfaceKeyStoreHandler
- Parameters:
keystore
- The keystore to use- Throws:
Exception
- If an error occurs
-
getPassword
public String getPassword()
Description copied from interface:KeyStoreHandler
Returns the password.- Specified by:
getPassword
in interfaceKeyStoreHandler
- Returns:
- the password used to access the keystore
-
getLocation
public String getLocation()
Description copied from interface:KeyStoreHandler
Returns the path to the keystore.- Specified by:
getLocation
in interfaceKeyStoreHandler
- Returns:
- the path
-
getType
public String getType()
Description copied from interface:KeyStoreHandler
Returns the type of the keystore.- Specified by:
getType
in interfaceKeyStoreHandler
- Returns:
- the keystore type
-
store
public void store() throws Exception
Description copied from interface:KeyStoreHandler
Saves the keystore.- Specified by:
store
in interfaceKeyStoreHandler
- Throws:
Exception
- If an error occurs.
-
-