Class ScriptedResponseMappingStrategy
java.lang.Object
net.shibboleth.utilities.java.support.scripting.AbstractScriptEvaluator
net.shibboleth.idp.attribute.resolver.dc.http.impl.ScriptedResponseMappingStrategy
- All Implemented Interfaces:
HTTPResponseMappingStrategy,MappingStrategy<Map<String,,IdPAttribute>> org.apache.http.client.ResponseHandler<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
FieldsModifier and TypeFieldDescription"Successful" statuses.Acceptable Content-Types.private final org.slf4j.LoggerClass logger.private longLimit on content-length.static final StringThe id of the object where the results go.Fields inherited from class net.shibboleth.utilities.java.support.scripting.AbstractScriptEvaluator
DEFAULT_ENGINE -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateScriptedResponseMappingStrategy(EvaluableScript theScript) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionprivate voidcheckContentLength(org.apache.http.HttpEntity entity) Check the content length.private voidcheckContentType(org.apache.http.HttpEntity entity) Enforce Content-Type requirements.private voidcheckStatus(org.apache.http.HttpResponse response) Enforce any status code requirements.private voidcheckValues(IdPAttribute attribute) Ensure that all the values in the attribute are of the correct type.protected ObjectfinalizeContext(ScriptContext scriptContext, Object scriptResult) handleResponse(org.apache.http.HttpResponse response) (package private) static ScriptedResponseMappingStrategyinlineScript(String scriptSource) Factory to createScriptedResponseMappingStrategyfrom inline data.(package private) static ScriptedResponseMappingStrategyinlineScript(String engineName, String scriptSource) Factory to createScriptedResponseMappingStrategyfrom inline data.map(Map<String, IdPAttribute> results) Maps the given results to a collection ofIdPAttributeindexed by the attribute's ID.protected voidprepareContext(ScriptContext scriptContext, Object... input) (package private) static ScriptedResponseMappingStrategyresourceScript(String engineName, Resource resource) Factory to createScriptedResponseMappingStrategyfrom aResource.(package private) static ScriptedResponseMappingStrategyresourceScript(Resource resource) Factory to createScriptedResponseMappingStrategyfrom aResource.voidsetAcceptStatuses(Collection<Integer> statuses) Set the HTTP status codes to treat as successful.voidsetAcceptTypes(Collection<String> types) Set the content-types to allow.voidsetMaxLength(long len) Set a limit on content-length.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. -
acceptStatuses
"Successful" statuses. -
acceptTypes
Acceptable Content-Types. -
maxLength
private long maxLengthLimit on content-length.
-
-
Constructor Details
-
ScriptedResponseMappingStrategy
Constructor.- Parameters:
theScript- the script to run
-
-
Method Details
-
setAcceptStatuses
Set the HTTP status codes to treat as successful.- Parameters:
statuses- successful codes
-
setAcceptTypes
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
@Nonnull public Map<String,IdPAttribute> map(@Nonnull Map<String, IdPAttribute> results) throws ResolutionExceptionMaps the given results to a collection ofIdPAttributeindexed by the attribute's ID.- Specified by:
mapin interfaceMappingStrategy<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.http.HttpResponse response) throws IOException - Specified by:
handleResponsein interfaceorg.apache.http.client.ResponseHandler<Map<String,IdPAttribute>> - Throws:
IOException
-
prepareContext
- Specified by:
prepareContextin classAbstractScriptEvaluator
-
finalizeContext
@Nullable protected Object finalizeContext(@Nonnull ScriptContext scriptContext, @Nullable Object scriptResult) throws ScriptException - Overrides:
finalizeContextin classAbstractScriptEvaluator- Throws:
ScriptException
-
checkStatus
Enforce any status code requirements.- Parameters:
response- HTTP response- Throws:
IOException- if the status is unacceptable
-
checkContentType
Enforce Content-Type requirements.- Parameters:
entity- the entity body- Throws:
IOException- if the type is unacceptable
-
checkContentLength
Check the content length.- Parameters:
entity- the entity body- Throws:
IOException- if the length is unacceptable
-
checkValues
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 String engineName, @Nonnull Resource resource) throws ScriptException, IOException Factory to createScriptedResponseMappingStrategyfrom 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 ScriptedResponseMappingStrategy resourceScript(@Nonnull Resource resource) throws ScriptException, IOException Factory to createScriptedResponseMappingStrategyfrom 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 ScriptedResponseMappingStrategy inlineScript(@Nonnull @NotEmpty String engineName, @Nonnull @NotEmpty String scriptSource) throws ScriptException Factory to createScriptedResponseMappingStrategyfrom inline data.- Parameters:
scriptSource- the script, as a stringengineName- the language- Returns:
- the function
- Throws:
ScriptException- if the compile fails
-
inlineScript
@Nonnull static ScriptedResponseMappingStrategy inlineScript(@Nonnull @NotEmpty String scriptSource) throws ScriptException Factory to createScriptedResponseMappingStrategyfrom inline data.- Parameters:
scriptSource- the script, as a string- Returns:
- the function
- Throws:
ScriptException- if the compile fails
-