Class ScriptedKeyStrategy
java.lang.Object
net.shibboleth.utilities.java.support.component.AbstractInitializableComponent
net.shibboleth.utilities.java.support.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.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate long
Size of key cache to maintain.private String
Current key alias loaded.private Object
Custom object for script.private SecretKey
Current default key loaded.private Timer
Timer used to schedule update tasks if no external one set.private final LinkedHashMap<String,
SecretKey> Cache of keys.private EvaluableScript
Script to obtain keys.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
setCacheSize
(long size) Set the number of keys to cache.void
setCustomObject
(Object object) Set the custom (externally provided) object.void
setKeyScript
(EvaluableScript script) Set the script to run to access keys.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
-
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
-
setKeyScript
Set the script to run to access keys.- Parameters:
script
- script to run
-
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
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).Also purge cache to limit size.
- Throws:
KeyException
- if the key cannot be updated
-