Class BasicKeystoreKeyStrategy
java.lang.Object
net.shibboleth.utilities.java.support.component.AbstractInitializableComponent
net.shibboleth.utilities.java.support.security.impl.BasicKeystoreKeyStrategy
- All Implemented Interfaces:
Component
,DestructableComponent
,InitializableComponent
,DataSealerKeyStrategy
public class BasicKeystoreKeyStrategy
extends AbstractInitializableComponent
implements DataSealerKeyStrategy
Implements a strategy for access to versioned symmetric keys using a keystore, and a standalone file
for tracking the latest key version, to compensate for the lack of extensible attribute support in the
pre-Java 8 KeyStore API.
The separate resource must be a Java properties file containing a CURRENT_VERSION_PROP
property pointing to the latest key version.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String
Name of property representing current key version.private String
Current key alias loaded.private SecretKey
Current default key loaded.private Timer
Timer used to schedule update tasks if no external one set.private String
Keystore base alias for encryption keys.private String
Password for encryption key(s).private String
Password for keystore.private Resource
Keystore resource.private String
Type of keystore to use for access to keys.private Resource
Version resource.private org.slf4j.Logger
Class logger.private Duration
Time between key update checks.private TimerTask
Task that checks for updated key version.private Timer
Timer used to schedule update tasks. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected void
Performs component specific destruction logic.void
Performs the initialization of the component.Get the default/current key to use for new operations, returned along with an identifier for it.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
(Duration interval) Set the time between key update checks.void
setUpdateTaskTimer
(Timer timer) Set the timer used to schedule update tasks.private void
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).Methods inherited from class net.shibboleth.utilities.java.support.component.AbstractInitializableComponent
destroy, initialize, isDestroyed, isInitialized
-
Field Details
-
CURRENT_VERSION_PROP
Name of property representing current key version.- See Also:
-
log
@Nonnull private org.slf4j.Logger logClass logger. -
keystoreType
Type of keystore to use for access to keys. -
keystoreResource
Keystore resource. -
keyVersionResource
Version resource. -
keystorePassword
Password for keystore. -
keyAlias
Keystore base alias for encryption keys. -
keyPassword
Password for encryption key(s). -
currentAlias
Current key alias loaded. -
defaultKey
Current default key loaded. -
updateInterval
Time between key update checks. Default value: (PT15M). -
updateTaskTimer
Timer used to schedule update tasks. -
internalTaskTimer
Timer used to schedule update tasks if no external one set. -
updateTask
Task that checks for updated key version.
-
-
Constructor Details
-
BasicKeystoreKeyStrategy
public BasicKeystoreKeyStrategy()Constructor.
-
-
Method Details
-
setKeystoreType
Set the keystore type.- Parameters:
type
- the keystore type
-
setKeystoreResource
Set the keystore resource.- Parameters:
resource
- the keystore resource
-
setKeyVersionResource
Set the key version resource.- Parameters:
resource
- the key version resource
-
setKeystorePassword
Set the keystore password.- Parameters:
password
- the keystore password
-
setKeyAlias
Set the encryption key alias base name.- Parameters:
alias
- the encryption key alias base
-
setKeyPassword
Set the encryption key password.- Parameters:
password
- the encryption key password
-
setUpdateInterval
Set the time between key update checks. A value of 0 indicates that no updates will be performed. This setting cannot be changed after the service has been initialized.- Parameters:
interval
- time between key update checks
-
setUpdateTaskTimer
Set the timer used to schedule update tasks. This setting cannot be changed after the service has been initialized.- Parameters:
timer
- timer used to schedule update tasks
-
doInitialize
Performs the initialization of the component. This method is executed within the lock on the object being initialized. The default implementation of this method is a no-op.- Overrides:
doInitialize
in classAbstractInitializableComponent
- Throws:
ComponentInitializationException
- thrown if there is a problem initializing the component
-
doDestroy
protected void doDestroy()Performs component specific destruction logic. This method is executed within the lock on the object being destroyed. The default implementation of this method is a no-op.- Overrides:
doDestroy
in classAbstractInitializableComponent
-
getDefaultKey
Get the default/current key to use for new operations, returned along with an identifier for it.- Specified by:
getDefaultKey
in interfaceDataSealerKeyStrategy
- Returns:
- the key
- Throws:
KeyException
- if the key cannot be returned
-
getKey
Get a specifically named key.- Specified by:
getKey
in interfaceDataSealerKeyStrategy
- Parameters:
name
- name of the key to retrieve- Returns:
- the key
- Throws:
KeyException
- if the key cannot be returned, does not exist, etc.
-
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).- Throws:
KeyException
- if the key cannot be updated
-