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 aKeyStoreHandlerin 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 StringgetLocation()Returns the path to the keystore.StringgetPassword()Returns the password.KeyStoregetStore()Get the keystore.StringgetType()Returns the type of the keystore.PrivateKeyreadPrivateKeyFromKeyStore(String alias)Get a private key for the alias using the default password fromgetPassword().PrivateKeyreadPrivateKeyFromKeyStore(String alias, String password)Get the private key with the given alias.PublicKeyreadPublicKeyFromKeyStore(String alias)Get the public key with the given alias.SecretKeyreadSecretKeyFromKeyStore(String alias)Get the secret key with the given alias using the default password fromgetPassword().SecretKeyreadSecretKeyFromKeyStore(String alias, String password)Get the secret key with the given alias.voidsetStore(KeyStore keystore)Sets the keystore.voidstore()Saves the keystore.voidwriteToKeyStore(SecretKey secretKey, String alias)Writes to the secret storage using the same password than the KeyStoreHandler.voidwriteToKeyStore(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:KeyStoreHandlerGet the keystore.- Specified by:
getStorein interfaceKeyStoreHandler- Returns:
- the keystore.
-
setStore
public void setStore(KeyStore keystore) throws Exception
Description copied from interface:KeyStoreHandlerSets the keystore.- Specified by:
setStorein interfaceKeyStoreHandler- Parameters:
keystore- The keystore to use- Throws:
Exception- If an error occurs
-
getPassword
public String getPassword()
Description copied from interface:KeyStoreHandlerReturns the password.- Specified by:
getPasswordin interfaceKeyStoreHandler- Returns:
- the password used to access the keystore
-
getLocation
public String getLocation()
Description copied from interface:KeyStoreHandlerReturns the path to the keystore.- Specified by:
getLocationin interfaceKeyStoreHandler- Returns:
- the path
-
getType
public String getType()
Description copied from interface:KeyStoreHandlerReturns the type of the keystore.- Specified by:
getTypein interfaceKeyStoreHandler- Returns:
- the keystore type
-
store
public void store() throws ExceptionDescription copied from interface:KeyStoreHandlerSaves the keystore.- Specified by:
storein interfaceKeyStoreHandler- Throws:
Exception- If an error occurs.
-
-