Package net.shibboleth.shared.scripting
Class AbstractScriptEvaluator
java.lang.Object
net.shibboleth.shared.scripting.AbstractScriptEvaluator
- Direct Known Subclasses:
ScriptedBiConsumer,ScriptedBiFunction,ScriptedBiPredicate,ScriptedConsumer,ScriptedFunction,ScriptedPredicate,ScriptedRunnable.RunnableScriptEvaluator
A component that evaluates an
EvaluableScript against a set of inputs
and returns the result.- Since:
- 7.4.0
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate Collection<ScriptContextExtender>Extension objects to apply.private ObjectA custom object to inject into the script.static final StringThe default language is Javascript.private booleanWhether to raise runtime exceptions if a script fails.private final org.slf4j.LoggerClass logger.private StringDebugging info.private Class<?>The output type to validate.private ObjectValue to return from script if an error occurs.private final EvaluableScriptThe script we care about. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected ObjectEvaluate the script.protected ObjectfinalizeContext(ScriptContext scriptContext, Object scriptResult) Complete processing by evaluating the result of the script and returning the final result to the caller.protected ObjectReturn the custom (externally provided) object.protected booleanGet whether to hide exceptions in script execution.protected StringGet log prefix for debugging.protected Class<?>Get the output type to be enforced.protected ObjectGet value to return if an error occurs.protected abstract voidprepareContext(ScriptContext scriptContext, Object... input) Pre-process the script context before execution.voidsetContextExtenders(Collection<? extends ScriptContextExtender> extenders) SetScriptContextExtenderinstances to apply when populating script context.voidsetCustomObject(Object object) Set the custom (externally provided) object.voidsetHideExceptions(boolean flag) Set whether to hide exceptions in script execution (default is false).voidsetLogPrefix(String prefix) Set log prefix for debugging.protected voidsetOutputType(Class<?> type) Set the output type to be enforced.protected voidsetReturnOnError(Object value) Set value to return if an error occurs.
-
Field Details
-
DEFAULT_ENGINE
The default language is Javascript.- See Also:
-
log
@Nonnull private final org.slf4j.Logger logClass logger. -
script
The script we care about. -
contextExtenders
Extension objects to apply. -
logPrefix
Debugging info. -
outputType
The output type to validate. -
customObject
A custom object to inject into the script. -
hideExceptions
private boolean hideExceptionsWhether to raise runtime exceptions if a script fails. -
returnOnError
Value to return from script if an error occurs.
-
-
Constructor Details
-
Method Details
-
getLogPrefix
Get log prefix for debugging.- Returns:
- log prefix
-
setLogPrefix
Set log prefix for debugging.- Parameters:
prefix- log prefix
-
getOutputType
Get the output type to be enforced.- Returns:
- output type
-
setOutputType
Set the output type to be enforced.- Parameters:
type- output type
-
getCustomObject
Return the custom (externally provided) object.- Returns:
- the custom object
-
setCustomObject
Set the custom (externally provided) object.- Parameters:
object- the custom object
-
getHideExceptions
protected boolean getHideExceptions()Get whether to hide exceptions in script execution.- Returns:
- whether to hide exceptions in script execution
-
setHideExceptions
public void setHideExceptions(boolean flag) Set whether to hide exceptions in script execution (default is false).- Parameters:
flag- flag to set
-
getReturnOnError
Get value to return if an error occurs.- Returns:
- value to return
-
setReturnOnError
Set value to return if an error occurs.- Parameters:
value- value to return
-
setContextExtenders
SetScriptContextExtenderinstances to apply when populating script context.- Parameters:
extenders- extenders to apply- Since:
- 9.0.0
-
evaluate
Evaluate the script.- Parameters:
input- input parameters- Returns:
- script result
-
prepareContext
protected abstract void prepareContext(@Nonnull ScriptContext scriptContext, @Nullable Object... input) Pre-process the script context before execution.- Parameters:
scriptContext- the script contextinput- the input
-
finalizeContext
@Nullable protected Object finalizeContext(@Nonnull ScriptContext scriptContext, @Nullable Object scriptResult) throws ScriptException Complete processing by evaluating the result of the script and returning the final result to the caller.The default implementation just returns the result.
- Parameters:
scriptContext- the context after executionscriptResult- the result of script execution- Returns:
- the final result to return, or null
- Throws:
ScriptException- to signal a failure after script execution
-