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
HTTPResponseMappingStrategythat 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>acceptTypesAcceptable Content-Types.private org.slf4j.LoggerlogClass logger.private longmaxLengthLimit on content-length.static StringRESULTS_STRINGThe id of the object where the results go.-
Fields inherited from class net.shibboleth.utilities.java.support.scripting.AbstractScriptEvaluator
DEFAULT_ENGINE
-
-
Constructor Summary
Constructors Modifier Constructor Description privateScriptedResponseMappingStrategy(EvaluableScript theScript)Constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private 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)Map<String,IdPAttribute>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<String,IdPAttribute>map(Map<String,IdPAttribute> results)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 Detail
-
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.
-
maxLength
private long maxLength
Limit on content-length.
-
-
Constructor Detail
-
ScriptedResponseMappingStrategy
private ScriptedResponseMappingStrategy(@Nonnull EvaluableScript theScript)Constructor.- Parameters:
theScript- the script to run
-
-
Method Detail
-
setAcceptStatuses
public void setAcceptStatuses(@Nonnull @NonnullElements Collection<Integer> statuses)
Set the HTTP status codes to treat as successful.- Parameters:
statuses- successful codes
-
setAcceptTypes
public void setAcceptTypes(@Nonnull @NonnullElements 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
@Nonnull public Map<String,IdPAttribute> map(@Nonnull Map<String,IdPAttribute> results) throws ResolutionException
- Specified by:
mapin interfaceMappingStrategy<Map<String,IdPAttribute>>- Throws:
ResolutionException
-
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
protected void prepareContext(@Nonnull ScriptContext scriptContext, @Nullable Object... input)- 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.http.HttpResponse response) throws IOExceptionEnforce any status code requirements.- Parameters:
response- HTTP response- Throws:
IOException- if the status is unacceptable
-
checkContentType
private void checkContentType(@Nonnull org.apache.http.HttpEntity entity) throws IOExceptionEnforce Content-Type requirements.- Parameters:
entity- the entity body- Throws:
IOException- if the type is unacceptable
-
checkContentLength
private void checkContentLength(@Nonnull org.apache.http.HttpEntity entity) throws IOExceptionCheck 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 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
-
-