Class SandboxPolicy
A SandboxPolicy is immutable; use a SandboxPolicy.Builder to create one:
SandboxPolicy policy = SandboxPolicy.builder()
.include(SandboxPolicy.JAVA_LANG_BASIC)
.include(SandboxPolicy.COLLECTIONS)
.allowAllMembers("com.acme.ScriptApi")
.build();
Rules always apply to the declaring class of a member; e.g. ArrayList.toString() is declared by
java.util.AbstractCollection.
Some members are never allowed (see isNeverAllowed(MemberRef)), because they would allow
sandboxed code to escape the sandbox or to affect the entire JVM, e.g. reflection, class loading, access control
(AccessController.doPrivileged()), threads, file and network access, and system properties. Class-wide
rules (SandboxPolicy.Builder.allowAllMembers(String...), SandboxPolicy.Builder.allowConstructors(String...)) never enable
them; a host that really wants to allow such a member must name it explicitly (SandboxPolicy.Builder.allowMethod(String, String, String), SandboxPolicy.Builder.allowMethods(String, String...), SandboxPolicy.Builder.allowField(String, String)).
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final SandboxPolicyThe core collections ofjava.util: the collection interfaces and their common implementations,Collections,ArraysandOptional.static final SandboxPolicyThe functional interfaces ofjava.util.function(Function,Predicate,Supplier, ...); sandboxed code may also implement them.static final SandboxPolicyBasic functionality ofjava.lang:Object(withoutwait()andnotify()),Class.getName()andgetSimpleName(),String,StringBuilder,Math, the wrapper types,Enum, the common exceptions, andjava.util.Objects.static final SandboxPolicyThe date and time API ofjava.time, including theformatandtemporalpackages and the ISO calendar system of thechronopackage.static final SandboxPolicyjava.math:BigInteger,BigDecimal,MathContextandRoundingMode.static final SandboxPolicyjava.util.regex:Pattern,Matcher,MatchResultandPatternSyntaxException.static final SandboxPolicyThe sequential streams ofjava.util.stream(Stream,IntStream,LongStream,DoubleStream,Collectors, ...) and the summary statistics ofjava.util; includesFUNCTIONAL.static final SandboxPolicyThe number, date and message formats ofjava.text(NumberFormat,DecimalFormat,SimpleDateFormat,MessageFormat, ...), plusCollatorandNormalizer.static final SandboxPolicyUtility classes ofjava.util:Random,SplittableRandom,ThreadLocalRandom,UUID,StringJoiner,StringTokenizer,BitSet,Base64,Locale,Date,Calendar,GregorianCalendar,TimeZone, andFormatter(without the constructors that open files). -
Method Summary
Modifier and TypeMethodDescriptionstatic SandboxPolicy.Builderbuilder()booleanbooleanstatic booleanisNeverAllowed(MemberRef member) booleanisSubclassingAllowed(String className)
-
Field Details
-
JAVA_LANG_BASIC
Basic functionality ofjava.lang:Object(withoutwait()andnotify()),Class.getName()andgetSimpleName(),String,StringBuilder,Math, the wrapper types,Enum, the common exceptions, andjava.util.Objects. -
COLLECTIONS
The core collections ofjava.util: the collection interfaces and their common implementations,Collections,ArraysandOptional. -
FUNCTIONAL
The functional interfaces ofjava.util.function(Function,Predicate,Supplier, ...); sandboxed code may also implement them. -
STREAMS
The sequential streams ofjava.util.stream(Stream,IntStream,LongStream,DoubleStream,Collectors, ...) and the summary statistics ofjava.util; includesFUNCTIONAL. Parallel streams are never allowed. -
MATH
java.math:BigInteger,BigDecimal,MathContextandRoundingMode. -
REGEX
java.util.regex:Pattern,Matcher,MatchResultandPatternSyntaxException. -
JAVA_TIME
The date and time API ofjava.time, including theformatandtemporalpackages and the ISO calendar system of thechronopackage. -
TEXT
The number, date and message formats ofjava.text(NumberFormat,DecimalFormat,SimpleDateFormat,MessageFormat, ...), plusCollatorandNormalizer. -
UTILITIES
Utility classes ofjava.util:Random,SplittableRandom,ThreadLocalRandom,UUID,StringJoiner,StringTokenizer,BitSet,Base64,Locale,Date,Calendar,GregorianCalendar,TimeZone, andFormatter(without the constructors that open files).
-
-
Method Details
-
builder
- Returns:
- A new builder for an initially empty policy, i.e. a policy that allows nothing
-
isAllowed
- Parameters:
member- A field, method or constructor, identified by its declaring class- Returns:
- Whether sandboxed code may use the member
-
isSubclassingAllowed
- Returns:
- Whether sandboxed code may declare classes that extend or implement the named class or interface
-
isExecutorRequired
public boolean isExecutorRequired()- Returns:
- Whether code that JANINO compiles with this policy may only be executed by a
SandboxExecutor; seeSandboxPolicy.Builder.requireExecutor()
-
isNeverAllowed
- Returns:
- Whether the member is one of the members that are never allowed unless a policy names them
explicitly; see
the class documentation
-