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; }
});
| Modifier and Type | Field and Description |
|---|---|
| private final AccessControlContext | accessControlContext
Deprecated
as a consequence of
AccessControlContext being deprecated.
|
| Access | Constructor and Description |
|---|---|
| public | Sandbox(PermissionCollection
Will be applied on later calls to permissions)confine(PrivilegedAction) and confine(PrivilegedExceptionAction)
|
| Modifier and Type | Method and Description |
|---|---|
| public <R> R | Returns: The value returned by the actionRuns the given action, confined by the permissions configured through the |
| public <R> R |
| accessControlContext | back to summary |
|---|---|
| private final AccessControlContext accessControlContext
Deprecated as a consequence of | |
| Sandbox | back to summary |
|---|---|
public Sandbox(PermissionCollection permissions)
| |
| confine | back to summary |
|---|---|
| public <R> R confine(PrivilegedAction<R> action) Runs the given action, confined by the permissions configured through the
| |
| confine | back to summary |
|---|---|
| public <R> R confine(PrivilegedExceptionAction<R> action) throws Exception | |