public final class Sandbox extends Object
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; } });
Constructor and Description |
---|
Sandbox(PermissionCollection permissions) |
Modifier and Type | Method and Description |
---|---|
<R> R |
confine(PrivilegedAction<R> action)
Runs the given action, confined by the permissions configured through the
constructor . |
<R> R |
confine(PrivilegedExceptionAction<R> action) |
public Sandbox(PermissionCollection permissions)
permissions
- Will be applied on later calls to confine(PrivilegedAction)
and confine(PrivilegedExceptionAction)
public <R> R confine(PrivilegedAction<R> action)
constructor
.public <R> R confine(PrivilegedExceptionAction<R> action) throws Exception
Exception
Copyright © 2021. All rights reserved.