public class BasicKeystoreKeyStrategy extends AbstractInitializableComponent implements DataSealerKeyStrategy
The separate resource must be a Java properties file containing a CURRENT_VERSION_PROP
property pointing to the latest key version.
| Modifier and Type | Field and Description |
|---|---|
static String |
CURRENT_VERSION_PROP
Name of property representing current key version.
|
private String |
currentAlias
Current key alias loaded.
|
private SecretKey |
defaultKey
Current default key loaded.
|
private Timer |
internalTaskTimer
Timer used to schedule update tasks if no external one set.
|
private String |
keyAlias
Keystore base alias for encryption keys.
|
private String |
keyPassword
Password for encryption key(s).
|
private String |
keystorePassword
Password for keystore.
|
private Resource |
keystoreResource
Keystore resource.
|
private String |
keystoreType
Type of keystore to use for access to keys.
|
private Resource |
keyVersionResource
Version resource.
|
private Logger |
log
Class logger.
|
private long |
updateInterval
Number of milliseconds between key update checks.
|
private TimerTask |
updateTask
Task that checks for updated key version.
|
private Timer |
updateTaskTimer
Timer used to schedule update tasks.
|
| Constructor and Description |
|---|
BasicKeystoreKeyStrategy()
Constructor.
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
doDestroy()
Performs component specific destruction logic.
|
void |
doInitialize()
Performs the initialization of the component.
|
Pair<String,SecretKey> |
getDefaultKey()
Get the default/current key to use for new operations, returned along with an identifier for it.
|
SecretKey |
getKey(String name)
Get a specifically named key.
|
void |
setKeyAlias(String alias)
Set the encryption key alias base name.
|
void |
setKeyPassword(String password)
Set the encryption key password.
|
void |
setKeystorePassword(String password)
Set the keystore password.
|
void |
setKeystoreResource(Resource resource)
Set the keystore resource.
|
void |
setKeystoreType(String type)
Set the keystore type.
|
void |
setKeyVersionResource(Resource resource)
Set the key version resource.
|
void |
setUpdateInterval(long interval)
Set the number of milliseconds between key update checks.
|
void |
setUpdateTaskTimer(Timer timer)
Set the timer used to schedule update tasks.
|
private void |
updateDefaultKey()
Update the loaded copy of the default key based on the current key version if it's out of date
(loading key version from scratch if need be).
|
destroy, initialize, isDestroyed, isInitialized@Nonnull @NotEmpty public static final String CURRENT_VERSION_PROP
@NonnullAfterInit private String keystoreType
@NonnullAfterInit private Resource keystoreResource
@NonnullAfterInit private Resource keyVersionResource
@NonnullAfterInit private String keystorePassword
@NonnullAfterInit private String keyAlias
@NonnullAfterInit private String keyPassword
@NonnullAfterInit private String currentAlias
@NonnullAfterInit private SecretKey defaultKey
@Duration @NonNegative private long updateInterval
private Timer updateTaskTimer
private Timer internalTaskTimer
private TimerTask updateTask
public void setKeystoreType(@Nonnull@NotEmpty String type)
type - the keystore typepublic void setKeystoreResource(@Nonnull@NotEmpty Resource resource)
resource - the keystore resourcepublic void setKeyVersionResource(@Nonnull@NotEmpty Resource resource)
resource - the key version resourcepublic void setKeystorePassword(@Nonnull@NotEmpty String password)
password - the keystore passwordpublic void setKeyAlias(@Nonnull@NotEmpty String alias)
alias - the encryption key alias basepublic void setKeyPassword(@Nonnull@NotEmpty String password)
password - the encryption key passwordpublic void setUpdateInterval(@Duration@NonNegative long interval)
interval - number of milliseconds between key update checkspublic void setUpdateTaskTimer(@Nullable Timer timer)
timer - timer used to schedule update taskspublic void doInitialize()
throws ComponentInitializationException
doInitialize in class AbstractInitializableComponentComponentInitializationException - thrown if there is a problem initializing the componentprotected void doDestroy()
doDestroy in class AbstractInitializableComponent@Nonnull public Pair<String,SecretKey> getDefaultKey() throws KeyException
getDefaultKey in interface DataSealerKeyStrategyKeyException - if the key cannot be returned@Nonnull public SecretKey getKey(@Nonnull@NotEmpty String name) throws KeyException
getKey in interface DataSealerKeyStrategyname - name of the key to retrieveKeyException - if the key cannot be returned, does not exist, etc.private void updateDefaultKey()
throws KeyException
KeyException - if the key cannot be updatedCopyright © 1999–2015. All rights reserved.