Top Description Fields Constructors Methods
org.codehaus.commons.compiler

public final Class Sandbox

extends Object
Class Inheritance
Imports
java.security.AccessControlContext, .AccessController, .CodeSource, .Permission, .PermissionCollection, .Permissions, .Policy, .PrivilegedAction, .PrivilegedActionException, .PrivilegedExceptionAction, .ProtectionDomain, org.codehaus.commons.nullanalysis.NotNullByDefault

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; }
    });
See Also
ORACLE: Java Essentials: The Security Manager

Field Summary

Modifier and TypeField and Description
private final AccessControlContext
accessControlContext

Deprecated as a consequence of AccessControlContext being deprecated.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public <R> R

Returns:

The value returned by the action
confine
(PrivilegedAction<R> action)

Runs the given action, confined by the permissions configured through the constructor.

public <R> R
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

accessControlContextback to summary
private final AccessControlContext accessControlContext

Deprecated

as a consequence of AccessControlContext being deprecated. See corresponding docs for further information.

Constructor Detail

Sandboxback to summary
public Sandbox(PermissionCollection permissions)
Parameters
permissions:PermissionCollection

Will be applied on later calls to confine(PrivilegedAction) and confine(PrivilegedExceptionAction)

Method Detail

confineback to summary
public <R> R confine(PrivilegedAction<R> action)

Runs the given action, confined by the permissions configured through the constructor.

Returns:R

The value returned by the action

confineback to summary
public <R> R confine(PrivilegedExceptionAction<R> action) throws Exception