Class StandardGroovySandbox
java.lang.Object
org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.StandardGroovySandbox
- All Implemented Interfaces:
GroovySandbox
Allows Groovy scripts (including Groovy Templates) to be run inside a sandbox.
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic @NotNull org.codehaus.groovy.control.CompilerConfiguration
Prepares a compiler configuration that rejects certain AST transformations.static @NotNull ClassLoader
Prepares a classloader for Groovy shell for sandboxing.static @NotNull org.codehaus.groovy.control.CompilerConfiguration
Prepares a compiler configuration the sandbox.enter()
Starts a dynamic scope within which calls will be sandboxed.Compiles and runs a script within the sandbox.withWhitelist
(@Nullable Whitelist whitelist) Specify a whitelist.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.GroovySandbox
wrapFunc, wrapRunnable
-
Field Details
-
LOGGER
-
-
Constructor Details
-
StandardGroovySandbox
public StandardGroovySandbox()Creates a sandbox with default settings.
-
-
Method Details
-
withWhitelist
Specify a whitelist. By defaultWhitelist.all()
is used.- Returns:
this
-
enter
Starts a dynamic scope within which calls will be sandboxed.- Specified by:
enter
in interfaceGroovySandbox
- Returns:
- a scope object, useful for putting this into a
try
-with-resources block
-
runScript
public Object runScript(@NotNull @NotNull groovy.lang.GroovyShell shell, @NotNull @NotNull String script) Compiles and runs a script within the sandbox.- Parameters:
shell
- the shell to be used; seecreateSecureCompilerConfiguration()
and similar methodsscript
- the script to run- Returns:
- the return value of the script
-
createSecureCompilerConfiguration
@NotNull public static @NotNull org.codehaus.groovy.control.CompilerConfiguration createSecureCompilerConfiguration()Prepares a compiler configuration the sandbox. CAUTIONWhen creating
GroovyShell
with thisCompilerConfiguration
, you also have to usecreateSecureClassLoader(ClassLoader)
to wrap a classloader of your choice into sandbox-aware one.Otherwise the classloader that you provide to
GroovyShell
might have its own copy of groovy-sandbox, which lets the code escape the sandbox.- Returns:
- a compiler configuration set up to use the sandbox
-
createBaseCompilerConfiguration
@NotNull public static @NotNull org.codehaus.groovy.control.CompilerConfiguration createBaseCompilerConfiguration()Prepares a compiler configuration that rejects certain AST transformations. Used bycreateSecureCompilerConfiguration()
. -
createSecureClassLoader
Prepares a classloader for Groovy shell for sandboxing.See
createSecureCompilerConfiguration()
for the discussion.
-