Package org.codehaus.commons.compiler
Class Sandbox
java.lang.Object
org.codehaus.commons.compiler.Sandbox
Executes a
PrivilegedAction
or PrivilegedExceptionAction
in a context with restricted permissions.
This is useful for executing "untrusted" code, e.g. user-provided expressions or scripts that were compiled with
JANINO.
Code example:
Permissions noPermissions = new Permissions(); Sandbox sandbox = new Sandbox(noPermissions); sandbox.confine(new PrivilegedExceptionAction<Object>() { @Override public Object run() throws Exception { new java.io.File("xxx").delete(); return null; } });
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<R> R
confine
(PrivilegedAction<R> action) Runs the given action, confined by the permissions configured through theconstructor
.<R> R
confine
(PrivilegedExceptionAction<R> action)
-
Field Details
-
accessControlContext
-
-
Constructor Details
-
Sandbox
- Parameters:
permissions
- Will be applied on later calls toconfine(PrivilegedAction)
andconfine(PrivilegedExceptionAction)
-
-
Method Details
-
confine
Runs the given action, confined by the permissions configured through theconstructor
.- Returns:
- The value returned by the action
-
confine
- Throws:
Exception
-