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

# Class ScriptedResponseMappingStrategy

java.lang.Object
net.shibboleth.shared.scripting.AbstractScriptEvaluator
net.shibboleth.idp.attribute.resolver.dc.http.impl.ScriptedResponseMappingStrategy

All Implemented Interfaces:
  `HTTPResponseMappingStrategy`, `MappingStrategy<Map<String,IdPAttribute>>`, `org.apache.hc.core5.http.io.HttpClientResponseHandler<Map<String,IdPAttribute>>`

public final class ScriptedResponseMappingStrategy extends AbstractScriptEvaluator implements HTTPResponseMappingStrategy
`HTTPResponseMappingStrategy` that relies on a script to map the response to the attribute set.

Well-suited to JSON output formats that can be parsed by the scripting engine.

## Field Summary

Fields
Modifier and Type
Field
Description
`private Set<Integer>`
`acceptStatuses`
"Successful" statuses.
`private Set<String>`
`acceptTypes`
Acceptable Content-Types.
`private final org.slf4j.Logger`
`log`
Class logger.
`private long`
`maxLength`
Limit on content-length.
`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`
`ScriptedResponseMappingStrategy(EvaluableScript theScript)`
Constructor.

## Method Summary

Modifier and Type
Method
Description
`private void`
`checkContentLength(org.apache.hc.core5.http.HttpEntity entity)`
Check the content length.
`private void`
`checkContentType(org.apache.hc.core5.http.HttpEntity entity)`
Enforce Content-Type requirements.
`private void`
`checkStatus(org.apache.hc.core5.http.ClassicHttpResponse response)`
Enforce any status code requirements.
`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)`
`Map<String,IdPAttribute>`
`handleResponse(org.apache.hc.core5.http.ClassicHttpResponse response)`
`(package private) static ScriptedResponseMappingStrategy`
`inlineScript(String scriptSource)`
Factory to create `ScriptedResponseMappingStrategy` from inline data.
`(package private) static ScriptedResponseMappingStrategy`
`inlineScript(String engineName, String scriptSource)`
Factory to create `ScriptedResponseMappingStrategy` from inline data.
`Map<String,IdPAttribute>`
`map(Map<String,IdPAttribute> 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 ScriptedResponseMappingStrategy`
`resourceScript(String engineName, Resource resource)`
Factory to create `ScriptedResponseMappingStrategy` from a `Resource`.
`(package private) static ScriptedResponseMappingStrategy`
`resourceScript(Resource resource)`
Factory to create `ScriptedResponseMappingStrategy` from a `Resource`.
`void`
`setAcceptStatuses(Collection<Integer> statuses)`
Set the HTTP status codes to treat as successful.
`void`
`setAcceptTypes(Collection<String> types)`
Set the content-types to allow.
`void`
`setMaxLength(long len)`
Set a limit on content-length.

### 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.

### acceptStatuses

@Nonnull private Set<Integer> acceptStatuses
"Successful" statuses.

### acceptTypes

@Nonnull private Set<String> acceptTypes
Acceptable Content-Types.

### maxLength

private long maxLength
Limit on content-length.

## Constructor Details

### ScriptedResponseMappingStrategy

private ScriptedResponseMappingStrategy(@Nonnull EvaluableScript theScript)
Constructor.

Parameters:
  `theScript` - the script to run

## Method Details

### setAcceptStatuses

public void setAcceptStatuses(@Nonnull Collection<Integer> statuses)
Set the HTTP status codes to treat as successful.

Parameters:
  `statuses` - successful codes

### setAcceptTypes

public void setAcceptTypes(@Nonnull Collection<String> types)
Set the content-types to allow.

Parameters:
  `types` - types to allow

### setMaxLength

public void setMaxLength(long len)
Set a limit on content-length.

Defaults to 0, allowing any. Setting a limit implies that an unknown length will be rejected.

Parameters:
  `len` - limit on size

### map

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

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

### handleResponse

public Map<String,IdPAttribute> handleResponse(org.apache.hc.core5.http.ClassicHttpResponse response) throws IOException

Specified by:
  `handleResponse` in interface `org.apache.hc.core5.http.io.HttpClientResponseHandler<Map<String,IdPAttribute>>`
Throws:
  `IOException`

### 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`

### checkStatus

private void checkStatus(@Nonnull org.apache.hc.core5.http.ClassicHttpResponse response) throws IOException
Enforce any status code requirements.

Parameters:
  `response` - HTTP response
Throws:
  `IOException` - if the status is unacceptable

### checkContentType

private void checkContentType(@Nonnull org.apache.hc.core5.http.HttpEntity entity) throws IOException
Enforce Content-Type requirements.

Parameters:
  `entity` - the entity body
Throws:
  `IOException` - if the type is unacceptable

### checkContentLength

private void checkContentLength(@Nonnull org.apache.hc.core5.http.HttpEntity entity) throws IOException
Check the content length.

Parameters:
  `entity` - the entity body
Throws:
  `IOException` - if the length is unacceptable

### checkValues

private void checkValues(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 ScriptedResponseMappingStrategy resourceScript(@Nonnull @NotEmpty @ParameterName(name="engineName") String engineName, @Nonnull @ParameterName(name="resource") Resource resource) throws ScriptException, IOException, ComponentInitializationException
Factory to create `ScriptedResponseMappingStrategy` 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 ScriptedResponseMappingStrategy resourceScript(@Nonnull @ParameterName(name="resource") Resource resource) throws ScriptException, IOException, ComponentInitializationException
Factory to create `ScriptedResponseMappingStrategy` 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 ScriptedResponseMappingStrategy inlineScript(@Nonnull @NotEmpty @ParameterName(name="engineName") String engineName, @Nonnull @NotEmpty @ParameterName(name="scriptSource") String scriptSource) throws ScriptException, ComponentInitializationException
Factory to create `ScriptedResponseMappingStrategy` 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 ScriptedResponseMappingStrategy inlineScript(@Nonnull @NotEmpty @ParameterName(name="scriptSource") String scriptSource) throws ScriptException, ComponentInitializationException
Factory to create `ScriptedResponseMappingStrategy` 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