Class SandboxPolicy.Builder
java.lang.Object
org.codehaus.commons.compiler.sandbox.SandboxPolicy.Builder
- Enclosing class:
SandboxPolicy
Creates
SandboxPolicys. All class names are binary names in the format of Class.getName(),
e.g. "java.util.Map$Entry".-
Method Summary
Modifier and TypeMethodDescriptionallowAllMembers(String... classNames) Allows all fields, methods and constructors that the given classes declare, except the never-allowed ones.allowConstructors(String... classNames) Allows all constructors of the given classes, except the never-allowed ones.allowField(String className, String name) Allows reading and writing the named field of the class.allowMethod(String className, String name, String descriptor) Allows one method or constructor.allowMethods(String className, String... names) Allows all overloads of the named methods of the class.allowSubclassing(String... classNames) Allows sandboxed code to declare classes that extend or implement the given classes or interfaces.build()include(SandboxPolicy policy) Adds all rules of the given policy, e.g. ofSandboxPolicy.JAVA_LANG_BASIC, and requires an executor if the policy does.Requires that code that JANINO compiles with this policy is executed only by aSandboxExecutor.
-
Method Details
-
allowMethod
Allows one method or constructor.- Parameters:
name- The method name, or"<init>"for a constructordescriptor- The method descriptor, e.g."(Ljava/lang/String;)V"
-
allowMethods
Allows all overloads of the named methods of the class. -
allowField
Allows reading and writing the named field of the class. (Writing afinalfield fails anyway.) -
allowConstructors
Allows all constructors of the given classes, except the never-allowed ones. -
allowAllMembers
Allows all fields, methods and constructors that the given classes declare, except the never-allowed ones. -
allowSubclassing
Allows sandboxed code to declare classes that extend or implement the given classes or interfaces. -
requireExecutor
Requires that code that JANINO compiles with this policy is executed only by aSandboxExecutor.By default, the resource limit checks that JANINO inserts do nothing outside of a
SandboxExecutor. That concerns e.g. static initializers and constructors that run when the host instantiates a generated class, and methods liketoString()that the host calls on an object that the sandboxed code returned. With this option, these checks throw anIllegalStateExceptioninstead, so that sandboxed code cannot run without limits.This option has no effect on the JDK back end (
commons-compiler-jdk), which does not insert resource limit checks. -
include
Adds all rules of the given policy, e.g. ofSandboxPolicy.JAVA_LANG_BASIC, and requires an executor if the policy does. -
build
-