Class SandboxGroovyMethods

java.lang.Object
com.axelor.script.SandboxGroovyMethods

public final class SandboxGroovyMethods extends Object
Groovy extension methods overriding the GDK methods that escape the script sandbox.

Registered as an extension module (see META-INF/groovy/org.codehaus.groovy.runtime.ExtensionModule), these take precedence over the GDK methods of the same signature, so they intercept the call however it is dispatched: direct call, dynamic method name, invokeMethod, closure delegate, spread, etc. The receiver check cannot catch these, as they run on allow-listed receivers (String, List, any object).

  • execute: starts an operating system process
  • use: applies a category, exposing static methods of any class (e.g. System.getenv) as methods of allow-listed receivers
  • mixin: mixes any class (e.g. GroovyShell) into an allow-listed class, for the whole application
  • setMetaClass, metaClass: replace the metaclass of a class, for the whole application (e.g. removing the guard of SandboxGuardedMethods)
  • asType (as): converting a list or map calls a constructor of the target class, so the target class must be allowed
  • addShutdownHook: registers code run when the JVM shuts down, outside of any evaluation (no timeout), for the whole application
  • getAt with a property name (list['name']): reads the property of each element of a collection or an array, which must be allowed as receivers

They are denied only when called from sandboxed code; otherwise they delegate to the GDK.

  • Method Details

    • execute

      public static Process execute(String self) throws IOException
      Throws:
      IOException
    • execute

      public static Process execute(String self, String[] envp, File dir) throws IOException
      Throws:
      IOException
    • execute

      public static Process execute(String self, List<?> envp, File dir) throws IOException
      Throws:
      IOException
    • execute

      public static Process execute(String[] commandArray) throws IOException
      Throws:
      IOException
    • execute

      public static Process execute(String[] commandArray, String[] envp, File dir) throws IOException
      Throws:
      IOException
    • execute

      public static Process execute(String[] commandArray, List<?> envp, File dir) throws IOException
      Throws:
      IOException
    • execute

      public static Process execute(List<?> commands) throws IOException
      Throws:
      IOException
    • execute

      public static Process execute(List<?> commands, String[] envp, File dir) throws IOException
      Throws:
      IOException
    • execute

      public static Process execute(List<?> commands, List<?> envp, File dir) throws IOException
      Throws:
      IOException
    • use

      public static <T> T use(Object self, Class<?> categoryClass, groovy.lang.Closure<T> closure)
    • use

      public static <T> T use(Object self, List<Class> categoryClassList, groovy.lang.Closure<T> closure)
    • use

      public static Object use(Object self, Object[] array)
    • setMetaClass

      public static void setMetaClass(Class<?> self, groovy.lang.MetaClass metaClass)
    • setMetaClass

      public static void setMetaClass(Object self, groovy.lang.MetaClass metaClass)
    • setMetaClass

      public static void setMetaClass(groovy.lang.GroovyObject self, groovy.lang.MetaClass metaClass)
    • metaClass

      public static groovy.lang.MetaClass metaClass(Class<?> self, groovy.lang.Closure<?> closure)
    • metaClass

      public static groovy.lang.MetaClass metaClass(Object self, groovy.lang.Closure<?> closure)
    • asType

      public static <T> T asType(Iterable<?> self, Class<T> type)
    • asType

      public static <T> T asType(Collection<?> self, Class<T> type)
    • asType

      public static <T> T asType(Object[] self, Class<T> type)
    • asType

      public static <T> T asType(groovy.lang.Closure<?> self, Class<T> type)
    • asType

      public static <T> T asType(Map<?,?> self, Class<T> type)
    • asType

      public static <T> T asType(Number self, Class<T> type)
    • asType

      public static <T> T asType(Object self, Class<T> type)
    • asType

      public static <T> T asType(CharSequence self, Class<T> type)
    • asType

      public static <T> T asType(groovy.lang.GString self, Class<T> type)
    • asType

      public static <T> T asType(String self, Class<T> type)
    • getAt

      public static List getAt(Collection<?> self, String property)
    • getAt

      public static Object getAt(Object self, String property)
    • addShutdownHook

      public static void addShutdownHook(Object self, groovy.lang.Closure<?> closure)
    • mixin

      public static void mixin(groovy.lang.MetaClass self, List<Class> categoryClasses)
    • mixin

      public static void mixin(Class<?> self, List<Class> categoryClasses)
    • mixin

      public static void mixin(Class<?> self, Class<?> categoryClass)
    • mixin

      public static void mixin(Class<?> self, Class<?>[] categoryClass)
    • mixin

      public static void mixin(groovy.lang.MetaClass self, Class<?> categoryClass)
    • mixin

      public static void mixin(groovy.lang.MetaClass self, Class<?>[] categoryClass)