Package org.graalvm.polyglot
Class HostAccess
java.lang.Object
org.graalvm.polyglot.HostAccess
Represents the host access policy of a polyglot context. The host access policy specifies which
methods and fields are accessible to the guest application, whenever Java host objects are
accessed.
There are three predefined instances of host access policies:
EXPLICIT
- Java host methods or fields, must be public and be annotated with@Export
to make them accessible to the guest language.SCOPED
- Java host methods or fields, must be public and be annotated with@Export
to make them accessible to the guest language. Guest-to-host callback parameter validity is scoped to the duration of the callback by default.NONE
- Does not allow any access to methods or fields of host objects. Java host objects may still be passed into a context, but they cannot be accessed.ALL
- Does allow full unrestricted access to public methods or fields of host objects. Note that this policy allows unrestricted access to reflection. It is highly discouraged from using this policy in environments where the guest application is not fully trusted.CONSTRAINED
host access policy suitable for a context withCONSTRAINED
sandbox policy.ISOLATED
host access policy suitable for a context withISOLATED
sandbox policy.UNTRUSTED
host access policy suitable for a context withUNTRUSTED
sandbox policy.
newBuilder()
. The builder allows to
specify a custom export annotation and allowed and denied methods or fields.- Since:
- 19.0
-
Nested Class Summary
Modifier and TypeClassDescriptionfinal class
Builder to create a customhost access policy
.static @interface
IfSCOPED
is used, placing this annotation on an exported host function excludes it from parameter scoping, i.e.static @interface
Annotation used by the predefinedEXPLICIT
access policy to mark public constructors, methods and fields in public classes that should be accessible by the guest application.static @interface
Allows guest language to implement a Java type.static enum
List of default host object mappings of mutable target types available inValue.as(Class)
.static enum
Represents the precedence of a target type mapping. -
Field Summary
Modifier and TypeFieldDescriptionstatic final HostAccess
Predefined host access policy that allows full unrestricted access to public methods or fields of public host classes.static final HostAccess
Predefined host access policy used by Context with aSandboxPolicy.CONSTRAINED
sandbox policy when the host access policy is not explicitly specified by the embedder.static final HostAccess
Predefined host access policy that allows access to public host methods or fields that were annotated with @Export and were declared in public class.static final HostAccess
Predefined host access policy used by Context with anSandboxPolicy.ISOLATED
sandbox policy when the host access policy is not explicitly specified by the embedder.static final HostAccess
Predefined host access policy that disallows any access to public host methods or fields.static final HostAccess
Predefined host access policy that is the same as EXPLICIT and enables method scoping of callback parameter values on top.static final HostAccess
Predefined host access policy used by Context with anSandboxPolicy.UNTRUSTED
sandbox policy when the host access policy is not explicitly specified by the embedder. -
Method Summary
Modifier and TypeMethodDescriptionboolean
int
hashCode()
static HostAccess.Builder
Creates a new builder that allows to create a custom host access policy.static HostAccess.Builder
newBuilder
(HostAccess conf) Creates a new builder that allows to create a custom host access policy based of a preset configuration.toString()
-
Field Details
-
EXPLICIT
Predefined host access policy that allows access to public host methods or fields that were annotated with @Export and were declared in public class. This is the default configuration ifContext.Builder.allowAllAccess(boolean)
isfalse
.Equivalent of using the following builder configuration:
HostAccess.newBuilder().allowAccessAnnotatedBy(HostAccess.Export.class). allowImplementationsAnnotatedBy(HostAccess.Implementable.class). allowImplementationsAnnotatedBy(FunctionalInterface.class). .build();
- Since:
- 19.0
-
SCOPED
Predefined host access policy that is the same as EXPLICIT and enables method scoping of callback parameter values on top. Methods that are annotated withHostAccess.DisableMethodScoping
are exempt from scoping.Equivalent of using the following builder configuration:
HostAccess.newBuilder().allowAccessAnnotatedBy(HostAccess.Export.class). allowImplementationsAnnotatedBy(HostAccess.Implementable.class). allowImplementationsAnnotatedBy(FunctionalInterface.class). methodScoping(true). disableMethodScopingAnnotatedBy(HostAccess.DisableMethodScoping.class) .build();
- Since:
- 21.3
-
ALL
Predefined host access policy that allows full unrestricted access to public methods or fields of public host classes. Note that this policy allows unrestricted access to reflection. It is highly discouraged from using this policy in environments where the guest application is not fully trusted. This is the default configuration ifContext.Builder.allowAllAccess(boolean)
istrue
.Equivalent of using the following builder configuration:
HostAccess.newBuilder() allowPublicAccess(true). allowAllImplementations(true). allowAllClassImplementations(true). allowArrayAccess(true). allowListAccess(true). allowBufferAccess(true). allowIterableAccess(true). allowIteratorAccess(true). allowMapAccess(true). allowAccessInheritance(true). .build();
- Since:
- 19.0
-
NONE
Predefined host access policy that disallows any access to public host methods or fields.Equivalent of using the following builder configuration:
HostAccess.newBuilder().build();
- Since:
- 19.0
-
CONSTRAINED
Predefined host access policy used by Context with aSandboxPolicy.CONSTRAINED
sandbox policy when the host access policy is not explicitly specified by the embedder.Equivalent of using the following builder configuration:
HostAccess.newBuilder(). allowAccessAnnotatedBy(Export.class). allowImplementationsAnnotatedBy(Implementable.class). allowMutableTargetMappings().build();
- Since:
- 23.0
-
ISOLATED
Predefined host access policy used by Context with anSandboxPolicy.ISOLATED
sandbox policy when the host access policy is not explicitly specified by the embedder.Equivalent of using the following builder configuration:
HostAccess.newBuilder(CONSTRAINED). methodScoping(true).build();
- Since:
- 23.0
-
UNTRUSTED
Predefined host access policy used by Context with anSandboxPolicy.UNTRUSTED
sandbox policy when the host access policy is not explicitly specified by the embedder.Equivalent of using the following builder configuration:
HostAccess.newBuilder(). allowAccessAnnotatedBy(Export.class). allowMutableTargetMappings(). methodScoping(true).build();
- Since:
- 23.0
-
-
Method Details
-
equals
-
hashCode
public int hashCode() -
newBuilder
Creates a new builder that allows to create a custom host access policy. The builder configuration needs to be completed using themethod
.- Since:
- 19.0
-
newBuilder
Creates a new builder that allows to create a custom host access policy based of a preset configuration. The preset configuration is copied and used as a template for the returned buidler. The builder configuration needs to be completed using themethod
.- Since:
- 19.0
-
toString
-