Class ScriptedStorageMappingStrategy
java.lang.Object
net.shibboleth.utilities.java.support.scripting.AbstractScriptEvaluator
net.shibboleth.idp.attribute.resolver.dc.storage.impl.ScriptedStorageMappingStrategy
- All Implemented Interfaces:
MappingStrategy<StorageRecord<?>>
,StorageMappingStrategy
public final class ScriptedStorageMappingStrategy
extends AbstractScriptEvaluator
implements StorageMappingStrategy
StorageMappingStrategy
that relies on a script to map the record to the
attribute set.
Well-suited to JSON output formats that can be parsed by the scripting engine.
- Since:
- 4.1.0
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final org.slf4j.Logger
Class logger.static final String
The id of the object where the results go.Fields inherited from class net.shibboleth.utilities.java.support.scripting.AbstractScriptEvaluator
DEFAULT_ENGINE
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprivate
ScriptedStorageMappingStrategy
(EvaluableScript theScript) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionprivate void
checkValues
(IdPAttribute attribute) Ensure that all the values in the attribute are of the correct type.protected Object
finalizeContext
(ScriptContext scriptContext, Object scriptResult) (package private) static ScriptedStorageMappingStrategy
inlineScript
(String scriptSource) Factory to createScriptedStorageMappingStrategy
from inline data.(package private) static ScriptedStorageMappingStrategy
inlineScript
(String engineName, String scriptSource) Factory to createScriptedStorageMappingStrategy
from inline data.map
(StorageRecord<?> results) Maps the given results to a collection ofIdPAttribute
indexed by the attribute's ID.protected void
prepareContext
(ScriptContext scriptContext, Object... input) (package private) static ScriptedStorageMappingStrategy
resourceScript
(String engineName, Resource resource) Factory to createScriptedStorageMappingStrategy
from aResource
.(package private) static ScriptedStorageMappingStrategy
resourceScript
(Resource resource) Factory to createScriptedStorageMappingStrategy
from aResource
.Methods inherited from class net.shibboleth.utilities.java.support.scripting.AbstractScriptEvaluator
evaluate, getCustomObject, getHideExceptions, getLogPrefix, getOutputType, getReturnOnError, setCustomObject, setHideExceptions, setLogPrefix, setOutputType, setReturnOnError
-
Field Details
-
RESULTS_STRING
The id of the object where the results go.- See Also:
-
log
@Nonnull private final org.slf4j.Logger logClass logger.
-
-
Constructor Details
-
ScriptedStorageMappingStrategy
Constructor.- Parameters:
theScript
- the script to run
-
-
Method Details
-
map
@Nonnull public Map<String,IdPAttribute> map(@Nonnull StorageRecord<?> results) throws ResolutionException Maps the given results to a collection ofIdPAttribute
indexed by the attribute's ID.- Specified by:
map
in interfaceMappingStrategy<StorageRecord<?>>
- Parameters:
results
- to map- Returns:
- the mapped attributes or null if none exist
- Throws:
ResolutionException
- thrown if there is a problem reading data or mapping it
-
prepareContext
- Specified by:
prepareContext
in classAbstractScriptEvaluator
-
finalizeContext
@Nullable protected Object finalizeContext(@Nonnull ScriptContext scriptContext, @Nullable Object scriptResult) throws ScriptException - Overrides:
finalizeContext
in classAbstractScriptEvaluator
- Throws:
ScriptException
-
checkValues
Ensure that all the values in the attribute are of the correct type.- Parameters:
attribute
- the attribute to look at
-
resourceScript
@Nonnull static ScriptedStorageMappingStrategy resourceScript(@Nonnull @NotEmpty String engineName, @Nonnull Resource resource) throws ScriptException, IOException Factory to createScriptedStorageMappingStrategy
from aResource
.- Parameters:
engineName
- the languageresource
- the resource to look at- Returns:
- the function
- Throws:
ScriptException
- if the compile failsIOException
- if the file doesn't exist.
-
resourceScript
@Nonnull static ScriptedStorageMappingStrategy resourceScript(@Nonnull Resource resource) throws ScriptException, IOException Factory to createScriptedStorageMappingStrategy
from aResource
.- Parameters:
resource
- the resource to look at- Returns:
- the function
- Throws:
ScriptException
- if the compile failsIOException
- if the file doesn't exist.
-
inlineScript
@Nonnull static ScriptedStorageMappingStrategy inlineScript(@Nonnull @NotEmpty String engineName, @Nonnull @NotEmpty String scriptSource) throws ScriptException Factory to createScriptedStorageMappingStrategy
from inline data.- Parameters:
scriptSource
- the script, as a stringengineName
- the language- Returns:
- the function
- Throws:
ScriptException
- if the compile fails
-
inlineScript
@Nonnull static ScriptedStorageMappingStrategy inlineScript(@Nonnull @NotEmpty String scriptSource) throws ScriptException Factory to createScriptedStorageMappingStrategy
from inline data.- Parameters:
scriptSource
- the script, as a string- Returns:
- the function
- Throws:
ScriptException
- if the compile fails
-