Package org.forgerock.openig.script
Class AbstractScriptableHeapObject<V>
java.lang.Object
org.forgerock.openig.script.AbstractScriptableHeapObject<V>
- Type Parameters:
V
- The expected result type of thePromise
. As a convenience, this class supports non-Promise type to be returned from the script, and will wrap it into aPromise
.
- All Implemented Interfaces:
Closeable
,AutoCloseable
- Direct Known Subclasses:
ScriptableAccessTokenResolver
,ScriptableFilter
,ScriptableHandler
,ScriptableIdentityAssertionPlugin
,ScriptableIdentityAssertionPluginTechPreview
,ScriptableJwtValidatorCustomizer
,ScriptableResourceAccess
,ScriptableResourceUriProvider
,ScriptableThrottlingPolicy
A scriptable heap object acts as a simple wrapper around the scripting engine.
This class is a base class for implementing any interface that we want to make pluggable through scripting support.
Scripts are provided with the following variables bindings:
logger
- The logger for this scriptglobals
- the Map of global variables which persist across successive invocations of the scriptcontext
- the associated request contextcontexts
- the visible contexts, keyed by context's namehttp
- an HTTP client which may be used for performing outbound HTTP requests
The provided args
parameters supports config-time expressions evaluation with the
special addition of a heap
variable that allows the script to get references
to other objects available in the heap.
{
"args": {
"ref": "heap['object-name']"
}
}
NOTE : at the moment only Groovy is supported.
-
Nested Class Summary
Modifier and TypeClassDescriptionprotected static class
Creates and initializes a scriptable heap object in a heap environment. -
Constructor Summary
ModifierConstructorDescriptionprotected
AbstractScriptableHeapObject
(Script compiledScript, Heap heap, String name) Creates a new scriptable heap object using the provided compiled script. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
protected final V
Synchronously runs the compiled script using the provided bindings.protected final Promise<V,
ScriptException> runScriptAsync
(Bindings bindings, Context context, Class<V> clazz) Asynchronously runs the compiled script using the provided bindings.void
Sets the parameters which should be made available to scripts.void
setClientHandler
(Handler clientHandler) Sets the HTTP client handler which should be made available to scripts.
-
Constructor Details
-
AbstractScriptableHeapObject
Creates a new scriptable heap object using the provided compiled script.- Parameters:
compiledScript
- The compiled script.heap
- The heap to look for bindingsname
- The name of this scriptable heap object.
-
-
Method Details
-
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
-
setClientHandler
Sets the HTTP client handler which should be made available to scripts.- Parameters:
clientHandler
- The HTTP client handler which should be made available to scripts.
-
setArgs
Sets the parameters which should be made available to scripts.- Parameters:
args
- The parameters which should be made available to scripts.
-
runScriptAsync
protected final Promise<V,ScriptException> runScriptAsync(Bindings bindings, Context context, Class<V> clazz) Asynchronously runs the compiled script using the provided bindings.- Parameters:
bindings
- Base bindings available to the script (will be enriched).context
- request processing contextclazz
- the class representing the expected result type of thePromise
- Returns:
- the Promise of a Response produced by the script
-
runScript
protected final V runScript(Bindings bindings, Context context, Class<V> clazz) throws ScriptException Synchronously runs the compiled script using the provided bindings.- Parameters:
bindings
- Base bindings available to the script (will be enriched).context
- request processing contextclazz
- the class representing the expected result type of thePromise
- Returns:
- the Promise of a Response produced by the script
- Throws:
ScriptException
- if the script throws an exception at runtime.
-