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,ScriptableJwtValidatorCustomizer,ScriptableResourceAccess,ScriptableResourceUriProvider,ScriptableThrottlingPolicy
public class AbstractScriptableHeapObject<V> extends Object implements Closeable
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 requestsldap- an LDAP client which may be used for performing LDAP requests such as LDAP authentication
The provided
argsparameters supports config-time expressions evaluation with the special addition of aheapvariable 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
Nested Classes Modifier and Type Class Description protected static classAbstractScriptableHeapObject.AbstractScriptableHeaplet<V>Creates and initializes a scriptable heap object in a heap environment.
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractScriptableHeapObject(Script compiledScript, Heap heap, String name)Creates a new scriptable heap object using the provided compiled script.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()protected VrunScript(Bindings bindings, Context context, Class<V> clazz)Synchronously runs the compiled script using the provided bindings.protected Promise<V,ScriptException>runScriptAsync(Bindings bindings, Context context, Class<V> clazz)Asynchronously runs the compiled script using the provided bindings.voidsetArgs(Map<String,Object> args)Sets the parameters which should be made available to scripts.voidsetClientHandler(Handler clientHandler)Sets the HTTP client handler which should be made available to scripts.
-
-
-
Constructor Detail
-
AbstractScriptableHeapObject
protected AbstractScriptableHeapObject(Script compiledScript, Heap heap, String name)
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 Detail
-
close
public void close() throws IOException- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-
setClientHandler
public void setClientHandler(Handler clientHandler)
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
public void setArgs(Map<String,Object> args)
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.
-
-