Package net.shibboleth.idp.attribute.resolver.dc.storage.impl

# Class ScriptedStorageMappingStrategy

java.lang.Object
net.shibboleth.shared.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

Fields
Modifier and Type
Field
Description
`private final org.slf4j.Logger`
`log`
Class logger.
`static final String`
`RESULTS_STRING`
The id of the object where the results go.

### Fields inherited from class net.shibboleth.shared.scripting.AbstractScriptEvaluator

`DEFAULT_ENGINE`

## Constructor Summary

Constructors
Modifier
Constructor
Description
`private`
`ScriptedStorageMappingStrategy(EvaluableScript theScript)`
Constructor.

## Method Summary

Modifier and Type
Method
Description
`private 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 create `ScriptedStorageMappingStrategy` from inline data.
`(package private) static ScriptedStorageMappingStrategy`
`inlineScript(String engineName, String scriptSource)`
Factory to create `ScriptedStorageMappingStrategy` from inline data.
`Map<String,IdPAttribute>`
`map(StorageRecord<?> results)`
Maps the given results to a collection of `IdPAttribute` indexed by the attribute's ID.
`protected void`
`prepareContext(ScriptContext scriptContext, Object... input)`
`(package private) static ScriptedStorageMappingStrategy`
`resourceScript(String engineName, Resource resource)`
Factory to create `ScriptedStorageMappingStrategy` from a `Resource`.
`(package private) static ScriptedStorageMappingStrategy`
`resourceScript(Resource resource)`
Factory to create `ScriptedStorageMappingStrategy` from a `Resource`.

### Methods inherited from class net.shibboleth.shared.scripting.AbstractScriptEvaluator

`evaluate, getCustomObject, getHideExceptions, getLogPrefix, getOutputType, getReturnOnError, setContextExtenders, setCustomObject, setHideExceptions, setLogPrefix, setOutputType, setReturnOnError`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Field Details

### RESULTS_STRING

@Nonnull public static final String RESULTS_STRING
The id of the object where the results go.

See Also:
  - Constant Field Values

### log

@Nonnull private final org.slf4j.Logger log
Class logger.

## Constructor Details

### ScriptedStorageMappingStrategy

private ScriptedStorageMappingStrategy(@Nonnull EvaluableScript theScript)
Constructor.

Parameters:
  `theScript` - the script to run

## Method Details

### map

@Nonnull @Unmodifiable @NotLive public Map<String,IdPAttribute> map(@Nonnull StorageRecord<?> results) throws ResolutionException
Maps the given results to a collection of `IdPAttribute` indexed by the attribute's ID.

Specified by:
  `map` in interface `MappingStrategy<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

protected void prepareContext(@Nonnull ScriptContext scriptContext, @Nullable Object... input)

Specified by:
  `prepareContext` in class `AbstractScriptEvaluator`

### finalizeContext

@Nullable protected Object finalizeContext(@Nonnull ScriptContext scriptContext, @Nullable Object scriptResult) throws ScriptException

Overrides:
  `finalizeContext` in class `AbstractScriptEvaluator`
Throws:
  `ScriptException`

### checkValues

private void checkValues(@Nonnull IdPAttribute attribute)
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 @ParameterName(name="engineName") String engineName, @Nonnull @ParameterName(name="resource") Resource resource) throws ScriptException, IOException, ComponentInitializationException
Factory to create `ScriptedStorageMappingStrategy` from a `Resource`.

Parameters:
  `engineName` - the language
  `resource` - the resource to look at
Returns:
  the function
Throws:
  `ScriptException` - if the compile fails
  `IOException` - if the file doesn't exist.
  `ComponentInitializationException` - if the script object fails to initialize

### resourceScript

@Nonnull static ScriptedStorageMappingStrategy resourceScript(@Nonnull @ParameterName(name="resource") Resource resource) throws ScriptException, IOException, ComponentInitializationException
Factory to create `ScriptedStorageMappingStrategy` from a `Resource`.

Parameters:
  `resource` - the resource to look at
Returns:
  the function
Throws:
  `ScriptException` - if the compile fails
  `IOException` - if the file doesn't exist.
  `ComponentInitializationException` - if the script object fails to initialize

### inlineScript

@Nonnull static ScriptedStorageMappingStrategy inlineScript(@Nonnull @NotEmpty @ParameterName(name="engineName") String engineName, @Nonnull @NotEmpty @ParameterName(name="scriptSource") String scriptSource) throws ScriptException, ComponentInitializationException
Factory to create `ScriptedStorageMappingStrategy` from inline data.

Parameters:
  `scriptSource` - the script, as a string
  `engineName` - the language
Returns:
  the function
Throws:
  `ScriptException` - if the compile fails
  `ComponentInitializationException` - if the script object fails to initialize

### inlineScript

@Nonnull static ScriptedStorageMappingStrategy inlineScript(@Nonnull @NotEmpty @ParameterName(name="scriptSource") String scriptSource) throws ScriptException, ComponentInitializationException
Factory to create `ScriptedStorageMappingStrategy` from inline data.

Parameters:
  `scriptSource` - the script, as a string
Returns:
  the function
Throws:
  `ScriptException` - if the compile fails
  `ComponentInitializationException` - if the script object fails to initialize