Class AbstractScriptableHeapObject<V>

  • Type Parameters:
    V - The expected result type of the Promise. As a convenience, this class supports non-Promise type to be returned from the script, and will wrap it into a Promise.
    All Implemented Interfaces:
    Closeable, AutoCloseable
    Direct Known Subclasses:
    ScriptableAccessTokenResolver, ScriptableFilter, ScriptableHandler, ScriptableIdentityAssertionPluginTechPreview, 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 script
    • globals - the Map of global variables which persist across successive invocations of the script
    • context - the associated request context
    • contexts - the visible contexts, keyed by context's name
    • http - an HTTP client which may be used for performing outbound HTTP requests
    • ldap - an LDAP client which may be used for performing LDAP requests such as LDAP authentication

    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.

    • 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 bindings
        name - The name of this scriptable heap object.
    • Method Detail

      • 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 context
        clazz - the class representing the expected result type of the Promise
        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 context
        clazz - the class representing the expected result type of the Promise
        Returns:
        the Promise of a Response produced by the script
        Throws:
        ScriptException - if the script throws an exception at runtime.