Class BasicKeystoreKeyStrategy
java.lang.Object
net.shibboleth.shared.component.AbstractInitializableComponent
net.shibboleth.shared.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.
-
Nested Class Summary
Nested classes/interfaces inherited from interface net.shibboleth.shared.security.DataSealerKeyStrategy
DataSealerKeyStrategy.NamedKey -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringName of property representing current key version.private StringCurrent key alias loaded.private SecretKeyCurrent default key loaded.private TimerTimer used to schedule update tasks if no external one set.private StringKeystore base alias for encryption keys.private StringPassword for encryption key(s).private StringPassword for keystore.private ResourceKeystore resource.private StringType of keystore to use for access to keys.private ResourceVersion resource.private org.slf4j.LoggerClass logger.private DurationTime between key update checks.private TimerTaskTask that checks for updated key version.private TimerTimer used to schedule update tasks. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidvoidGet the default/current key to use for new operations, returned along with an identifier for it.Get an immutable record of the default named key.Get a specifically named key.voidsetKeyAlias(String alias) Set the encryption key alias base name.voidsetKeyPassword(String password) Set the encryption key password.voidsetKeystorePassword(String password) Set the keystore password.voidsetKeystoreResource(Resource resource) Set the keystore resource.voidsetKeystoreType(String type) Set the keystore type.voidsetKeyVersionResource(Resource resource) Set the key version resource.voidsetUpdateInterval(Duration interval) Set the time between key update checks.voidsetUpdateTaskTimer(Timer timer) Set the timer used to schedule update tasks.private voidUpdate 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.shared.component.AbstractInitializableComponent
checkComponentActive, checkSetterPreconditions, destroy, ifDestroyedThrowDestroyedComponentException, ifInitializedThrowUnmodifiabledComponentException, ifNotInitializedThrowUninitializedComponentException, 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
-
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
- Overrides:
doInitializein classAbstractInitializableComponent- Throws:
ComponentInitializationException
-
doDestroy
protected void doDestroy()- Overrides:
doDestroyin classAbstractInitializableComponent
-
getDefaultKey
Get the default/current key to use for new operations, returned along with an identifier for it.- Specified by:
getDefaultKeyin interfaceDataSealerKeyStrategy- Returns:
- the key
- Throws:
KeyException- if the key cannot be returned
-
getDefaultKeyRecord
Get an immutable record of the default named key.- Specified by:
getDefaultKeyRecordin interfaceDataSealerKeyStrategy- Returns:
- default key record
- Throws:
KeyException- if the key is unobtainable
-
getKey
Get a specifically named key.- Specified by:
getKeyin 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
-