Class ScriptedKeyStrategy
java.lang.Object
net.shibboleth.shared.component.AbstractInitializableComponent
net.shibboleth.shared.security.impl.ScriptedKeyStrategy
- All Implemented Interfaces:
Component,DestructableComponent,InitializableComponent,DataSealerKeyStrategy
public class ScriptedKeyStrategy
extends AbstractInitializableComponent
implements DataSealerKeyStrategy
Implements a strategy for access to versioned symmetric keys using scripts.
Suitable for integrating with external key services.
-
Nested Class Summary
Nested classes/interfaces inherited from interface net.shibboleth.shared.security.DataSealerKeyStrategy
DataSealerKeyStrategy.NamedKey -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate longSize of key cache to maintain.private StringCurrent key alias loaded.private ObjectCustom object for script.private SecretKeyCurrent default key loaded.private TimerTimer used to schedule update tasks if no external one set.private final LinkedHashMap<String,SecretKey> Cache of keys.private EvaluableScriptScript to obtain keys.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.voidsetCacheSize(long size) Set the number of keys to cache.voidsetCustomObject(Object object) Set the custom (externally provided) object.voidsetKeyScript(EvaluableScript script) Set the script to run to access keys.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
-
log
@Nonnull private org.slf4j.Logger logClass logger. -
keyScript
Script to obtain keys. -
customObject
Custom object for script. -
currentAlias
Current key alias loaded. -
defaultKey
Current default key loaded. -
keyCache
Cache of keys. -
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. -
cacheSize
Size of key cache to maintain.
-
-
Constructor Details
-
ScriptedKeyStrategy
public ScriptedKeyStrategy()Constructor.
-
-
Method Details
-
setCustomObject
Set the custom (externally provided) object.- Parameters:
object- the custom object
-
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
-
setCacheSize
Set the number of keys to cache.Defaults to 30.
- Parameters:
size- size of cache
-
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).Also purge cache to limit size.
- Throws:
KeyException- if the key cannot be updated