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
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.shared.scripting.AbstractScriptEvaluator
DEFAULT_ENGINE -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateScriptedResponseMappingStrategy(EvaluableScript theScript) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionprivate voidcheckContentLength(org.apache.hc.core5.http.HttpEntity entity) Check the content length.private voidcheckContentType(org.apache.hc.core5.http.HttpEntity entity) Enforce Content-Type requirements.private voidcheckStatus(org.apache.hc.core5.http.ClassicHttpResponse 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.hc.core5.http.ClassicHttpResponse 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.shared.scripting.AbstractScriptEvaluator
evaluate, getCustomObject, getHideExceptions, getLogPrefix, getOutputType, getReturnOnError, setContextExtenders, 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
-
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
@Nullable @Unmodifiable @NotLive 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.hc.core5.http.ClassicHttpResponse response) throws IOException - Specified by:
handleResponsein interfaceorg.apache.hc.core5.http.io.HttpClientResponseHandler<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
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
Ensure that all the values in the attribute are of the correct type.- Parameters:
attribute- the attribute to look at
-
inlineScript
@Nonnull static ScriptedResponseMappingStrategy inlineScript(@Nonnull @NotEmpty @ParameterName(name="engineName") String engineName, @Nonnull @NotEmpty @ParameterName(name="scriptSource") String scriptSource) throws ScriptException, ComponentInitializationException Factory to createScriptedResponseMappingStrategyfrom inline data.- Parameters:
scriptSource- the script, as a stringengineName- the language- Returns:
- the function
- Throws:
ScriptException- if the compile failsComponentInitializationException- if the script object fails to initialize
-
inlineScript
@Nonnull static ScriptedResponseMappingStrategy inlineScript(@Nonnull @NotEmpty @ParameterName(name="scriptSource") String scriptSource) throws ScriptException, ComponentInitializationException Factory to createScriptedResponseMappingStrategyfrom inline data.- Parameters:
scriptSource- the script, as a string- Returns:
- the function
- Throws:
ScriptException- if the compile failsComponentInitializationException- if the script object fails to initialize
-