Class SandboxClosure<V>

java.lang.Object
groovy.lang.GroovyObjectSupport
groovy.lang.Closure<V>
com.axelor.script.SandboxClosure<V>
All Implemented Interfaces:
SandboxCode, groovy.lang.GroovyCallable<V>, groovy.lang.GroovyObject, Serializable, Cloneable, Runnable, Callable<V>
Direct Known Subclasses:
SandboxClosureWrapper, SandboxMethodPointer

public abstract class SandboxClosure<V> extends groovy.lang.Closure<V> implements SandboxCode
Base class of the closures compiled by GroovyScriptSupport.

Inside a closure, a call or property access without an explicit receiver is resolved on the closure's owner and delegate, which the receiver checks never see. A closure whose delegate (or owner) is a class the policy denies would therefore give access to it, for example its static methods and properties (c.delegate = System then getenv()).

This class ensures that a sandboxed closure never holds such a delegate or owner: they can only be changed through setDelegate(Object) (used by with, c.delegate = ..., c['delegate'] = ..., etc.) and rehydrate(Object, Object, Object), which validate them against the policy. A collection or an array is validated with its elements, also when a property is resolved on it, as its elements can be changed later.

The closures Groovy builds from a sandboxed closure (curry, >>, memoize, trampoline...) are sandboxed too, see SandboxClosureWrapper.

The compiled closures are made to extend this class by SandboxClosureProcessor, as the Groovy compiler always generates closures extending Closure.

See Also:
  • Field Summary

    Fields inherited from class groovy.lang.Closure

    DELEGATE_FIRST, DELEGATE_ONLY, DONE, IDENTITY, maximumNumberOfParameters, OWNER_FIRST, OWNER_ONLY, parameterTypes, SKIP, TO_SELF
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
     
    protected
    SandboxClosure(Object owner, Object thisObject)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    <W> groovy.lang.Closure<W>
    andThen(groovy.lang.Closure<W> other)
     
    groovy.lang.Closure<V>
     
    groovy.lang.Closure<V>
    andThenSelf(int times)
     
    groovy.lang.Closure<V>
    compose(groovy.lang.Closure other)
     
    groovy.lang.Closure<V>
     
    groovy.lang.Closure<V>
    composeSelf(int times)
     
    groovy.lang.Closure<V>
    curry(Object argument)
     
    groovy.lang.Closure<V>
    curry(Object... arguments)
     
    getProperty(String property)
     
    groovy.lang.Closure<V>
    leftShift(groovy.lang.Closure other)
     
    groovy.lang.Closure<V>
     
    groovy.lang.Closure<V>
    memoizeAtLeast(int protectedCacheSize)
     
    groovy.lang.Closure<V>
    memoizeAtMost(int maxCacheSize)
     
    groovy.lang.Closure<V>
    memoizeBetween(int protectedCacheSize, int maxCacheSize)
     
    groovy.lang.Closure<V>
    ncurry(int n, Object argument)
     
    groovy.lang.Closure<V>
    ncurry(int n, Object... arguments)
     
    groovy.lang.Closure<V>
    rcurry(Object argument)
     
    groovy.lang.Closure<V>
    rcurry(Object... arguments)
     
    groovy.lang.Closure<V>
    rehydrate(Object delegate, Object owner, Object thisObject)
     
    <W> groovy.lang.Closure<W>
    rightShift(groovy.lang.Closure<W> other)
     
    void
    setDelegate(Object delegate)
     
    groovy.lang.Closure<V>
     
    groovy.lang.Closure<V>
    trampoline(Object... arguments)
     

    Methods inherited from class groovy.lang.Closure

    asWritable, call, call, call, clone, dehydrate, getDelegate, getDirective, getMaximumNumberOfParameters, getOwner, getParameterTypes, getResolveStrategy, getThisObject, isCase, leftShift, run, setDirective, setProperty, setResolveStrategy, throwRuntimeException

    Methods inherited from class groovy.lang.GroovyObjectSupport

    getMetaClass, setMetaClass

    Methods inherited from class java.lang.Object

    equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface groovy.lang.GroovyObject

    invokeMethod
  • Constructor Details

    • SandboxClosure

      protected SandboxClosure(Object owner, Object thisObject)
    • SandboxClosure

      protected SandboxClosure(Object owner)
  • Method Details

    • setDelegate

      public void setDelegate(Object delegate)
      Overrides:
      setDelegate in class groovy.lang.Closure<V>
    • rehydrate

      public groovy.lang.Closure<V> rehydrate(Object delegate, Object owner, Object thisObject)
      Overrides:
      rehydrate in class groovy.lang.Closure<V>
    • curry

      public groovy.lang.Closure<V> curry(Object... arguments)
      Overrides:
      curry in class groovy.lang.Closure<V>
    • curry

      public groovy.lang.Closure<V> curry(Object argument)
      Overrides:
      curry in class groovy.lang.Closure<V>
    • rcurry

      public groovy.lang.Closure<V> rcurry(Object... arguments)
      Overrides:
      rcurry in class groovy.lang.Closure<V>
    • rcurry

      public groovy.lang.Closure<V> rcurry(Object argument)
      Overrides:
      rcurry in class groovy.lang.Closure<V>
    • ncurry

      public groovy.lang.Closure<V> ncurry(int n, Object... arguments)
      Overrides:
      ncurry in class groovy.lang.Closure<V>
    • ncurry

      public groovy.lang.Closure<V> ncurry(int n, Object argument)
      Overrides:
      ncurry in class groovy.lang.Closure<V>
    • rightShift

      public <W> groovy.lang.Closure<W> rightShift(groovy.lang.Closure<W> other)
      Overrides:
      rightShift in class groovy.lang.Closure<V>
    • leftShift

      public groovy.lang.Closure<V> leftShift(groovy.lang.Closure other)
      Overrides:
      leftShift in class groovy.lang.Closure<V>
    • andThen

      public <W> groovy.lang.Closure<W> andThen(groovy.lang.Closure<W> other)
      Overrides:
      andThen in class groovy.lang.Closure<V>
    • andThenSelf

      public groovy.lang.Closure<V> andThenSelf()
      Overrides:
      andThenSelf in class groovy.lang.Closure<V>
    • andThenSelf

      public groovy.lang.Closure<V> andThenSelf(int times)
      Overrides:
      andThenSelf in class groovy.lang.Closure<V>
    • compose

      public groovy.lang.Closure<V> compose(groovy.lang.Closure other)
      Overrides:
      compose in class groovy.lang.Closure<V>
    • composeSelf

      public groovy.lang.Closure<V> composeSelf()
      Overrides:
      composeSelf in class groovy.lang.Closure<V>
    • composeSelf

      public groovy.lang.Closure<V> composeSelf(int times)
      Overrides:
      composeSelf in class groovy.lang.Closure<V>
    • memoize

      public groovy.lang.Closure<V> memoize()
      Overrides:
      memoize in class groovy.lang.Closure<V>
    • memoizeAtMost

      public groovy.lang.Closure<V> memoizeAtMost(int maxCacheSize)
      Overrides:
      memoizeAtMost in class groovy.lang.Closure<V>
    • memoizeAtLeast

      public groovy.lang.Closure<V> memoizeAtLeast(int protectedCacheSize)
      Overrides:
      memoizeAtLeast in class groovy.lang.Closure<V>
    • memoizeBetween

      public groovy.lang.Closure<V> memoizeBetween(int protectedCacheSize, int maxCacheSize)
      Overrides:
      memoizeBetween in class groovy.lang.Closure<V>
    • trampoline

      public groovy.lang.Closure<V> trampoline(Object... arguments)
      Overrides:
      trampoline in class groovy.lang.Closure<V>
    • trampoline

      public groovy.lang.Closure<V> trampoline()
      Overrides:
      trampoline in class groovy.lang.Closure<V>
    • getProperty

      public Object getProperty(String property)
      Specified by:
      getProperty in interface groovy.lang.GroovyObject
      Overrides:
      getProperty in class groovy.lang.Closure<V>