Class Permissions
- All Implemented Interfaces:
JexlPermissions
The default implementation does this by checking if an element has been annotated with NoJexl.
The NoJexl annotation allows a fine grain permission on executable objects (methods, fields, constructors).
- NoJexl of a package implies all classes (including derived classes), and all interfaces of that package are invisible to JEXL.
- NoJexl on a class implies this class, and all its derived classes are invisible to JEXL.
- NoJexl on a (public) field makes it not visible as a property to JEXL.
- NoJexl on a constructor prevents that constructor to be used to instantiate through 'new'.
- NoJexl on a method prevents that method and any of its overrides to be visible to JEXL.
- NoJexl on an interface prevents all methods of that interface and their overrides to be visible to JEXL.
It is possible to define permissions on external library classes used for which the source code
cannot be altered using an instance of permissions using JexlPermissions.parse(String...).
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static classA class that is positively allowed in its package yet carries deny-list member semantics.(package private) static interfaceRepresents the ability to create a copy of an object.(package private) static classA package where ALL unlisted classes are denied.(package private) static classA positive NoJexl construct that defines what is denied by absence in the set.(package private) static classA package where classes are allowed by default.(package private) static final classHolder for the singleton allow/deny markers and theUNRESTRICTEDpermission.(package private) static classEquivalent of @NoJexl on a ctor, a method, or a field in a class.protected static classEquivalent of @NoJexl on a class in a package.Nested classes/interfaces inherited from interface org.apache.commons.jexl3.introspection.JexlPermissions
JexlPermissions.ClassPermissions, JexlPermissions.Delegate, JexlPermissions.LoggingPermissions -
Field Summary
FieldsModifier and TypeFieldDescriptionThe allowed package patterns (wildcards or exact package names).(package private) static final Permissions.NoJexlClassMarker for allowed class.(package private) static final Permissions.NoJexlPackageMarker for fully allowed package.(package private) static final Permissions.NoJexlClassMarker for whole NoJexl class.(package private) static final Permissions.NoJexlClassMarker for a NoJexl class that only scopes nested-class declarations.(package private) static final Permissions.NoJexlPackageMarker for @NoJexl package.private final Map<String,Permissions.NoJexlPackage> The @NoJexl execution-time map.Fields inherited from interface org.apache.commons.jexl3.introspection.JexlPermissions
NONE, RESTRICTED, SECURE, UNRESTRICTED -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAllow inheritance.protectedPermissions(Set<String> perimeter, Map<String, Permissions.NoJexlPackage> nojexl) Default ctor. -
Method Summary
Modifier and TypeMethodDescriptionbooleanChecks whether a class or one of its super-classes or implemented interfaces explicitly allows JEXL introspection.booleanChecks whether a field explicitly allows JEXL introspection.booleanChecks whether a method allows JEXL introspection.private booleanCheck whether a method is allowed to be introspected in one superclass or interface.booleanChecks whether a package explicitly disallows JEXL introspection.booleanallow(Constructor<?> ctor) Checks whether a constructor explicitly allows JEXL introspection.booleanChecks whether a field explicitly allows JEXL introspection.booleanChecks whether a method explicitly allows JEXL introspection.private booleanallowedClass(Class<?> clazz) Whether a class is allowed by its own package or class-level declaration.private booleanallowedPackage(String packageName) Whether a package belongs to the allowed perimeter.(package private) static StringCreates a class key joining enclosing ascendants with '$'.(package private) static StringclassKey(Class<?> clazz, StringBuilder strb) Creates a class key joining enclosing ascendants with '$'.Creates a new set of permissions by composing these permissions with a new set of rules.(package private) static <T extends Permissions.Copyable<T>>
Map<String,T> Creates a copy of a map containing copyable values.private booleanTests whether a whole class is denied Jexl visibility.private booleanTests whether a whole package is denied Jexl visibility.private booleandeny(Constructor<?> ctor) Tests whether a constructor is denied Jexl visibility.private booleanTests whether a field is denied Jexl visibility.private booleanTests whether a method is denied Jexl visibility.private booleandenyMethod(Method method) Tests whether a method is denied.private Permissions.NoJexlClassGets the class constraints.private Permissions.NoJexlClassgetNoJexl(Class<?> clazz, Permissions.NoJexlClass ifNone) private Permissions.NoJexlPackagegetNoJexlPackage(String packageName) Gets the package constraints.(package private) Map<String,Permissions.NoJexlPackage> private <T> booleanspecifiedAllow(Class<?> clazz, T name, BiPredicate<Permissions.NoJexlClass, T> check) Determines whether a specified permission check is allowed for a given class.(package private) static booleanwildcardAllow(Set<String> allowed, String name) Whether the wildcard set of packages allows a given package to be introspected.
-
Field Details
-
NOJEXL_CLASS
Marker for whole NoJexl class. -
NOJEXL_CONTAINER
Marker for a NoJexl class that only scopes nested-class declarations. -
JEXL_CLASS
Marker for allowed class. -
NOJEXL_PACKAGE
Marker for @NoJexl package. -
JEXL_PACKAGE
Marker for fully allowed package. -
packages
The @NoJexl execution-time map. -
allowed
The allowed package patterns (wildcards or exact package names).Empty together with an empty
packagesmap means open-world: every package is accessible and only explicitly denied elements are carved out — the behavior ofPermissions.Markers.UNRESTRICTED. Empty with a non-emptypackagesmap, or non-empty, means closed-world: only declared packages are accessible.
-
-
Constructor Details
-
Permissions
protected Permissions()Allow inheritance. -
Permissions
Default ctor.- Parameters:
perimeter- The allowed wildcard set of packagesnojexl- The NoJexl external map
-
-
Method Details
-
copyMap
Creates a copy of a map containing copyable values.- Type Parameters:
T- The type of Copyable values- Parameters:
map- The map to copy- Returns:
- The copy of the map
-
compose
Creates a new set of permissions by composing these permissions with a new set of rules.- Specified by:
composein interfaceJexlPermissions- Parameters:
src- The rules- Returns:
- The new permissions
-
classKey
Creates a class key joining enclosing ascendants with '$'.As in
outer$innerforclass outer { class inner....- Parameters:
clazz- The clazz- Returns:
- The clazz key
-
classKey
Creates a class key joining enclosing ascendants with '$'.As in
outer$innerforclass outer { class inner....- Parameters:
clazz- The clazzstrb- The buffer to compose the key- Returns:
- The clazz key
-
wildcardAllow
Whether the wildcard set of packages allows a given package to be introspected.- Parameters:
allowed- The allowed set (not null, may be empty)name- The package name (not null)- Returns:
- true if allowed, false otherwise
-
getNoJexlPackage
Gets the package constraints.- Parameters:
packageName- The package name- Returns:
- The package constraints instance, not-null.
-
getPackages
Map<String,Permissions.NoJexlPackage> getPackages()- Returns:
- The packages
-
getWildcards
- Returns:
- The wildcards
-
allowedPackage
Whether a package belongs to the allowed perimeter.Open-world (
Permissions.Markers.UNRESTRICTED: no rules at all) allows every package. Closed-world requires the package to match an entry inallowed; an empty perimeter in closed-world matches nothing.- Parameters:
packageName- The package name (not null)- Returns:
- true if allowed, false otherwise
-
specifiedAllow
private <T> boolean specifiedAllow(Class<?> clazz, T name, BiPredicate<Permissions.NoJexlClass, T> check) Determines whether a specified permission check is allowed for a given class. The check involves verifying if a class or its corresponding package explicitly permits a name (e.g., method) based on a given condition.- Type Parameters:
T- The type of the name to check (e.g., method, constructor)- Parameters:
clazz- The class to evaluate (not null)name- The name to verify (not null)check- The condition to test whether the specified name is allowed (not null)- Returns:
- true if the specified name is allowed based on the condition, false otherwise
-
allow
Checks whether a class or one of its super-classes or implemented interfaces explicitly allows JEXL introspection.- Specified by:
allowin interfaceJexlPermissions- Parameters:
clazz- The class to check- Returns:
- true if JEXL is allowed to introspect, false otherwise
-
allowedClass
Whether a class is allowed by its own package or class-level declaration.- Parameters:
clazz- The class to check (not null)- Returns:
- true if explicitly allowed
-
allow
Check whether a method is allowed to be introspected in one superclass or interface.- Parameters:
clazz- The superclass or interface to checkmethod- The methodexplicit- carries whether the package holding the method is explicitly allowed- Returns:
- true if JEXL is allowed to introspect, false otherwise
-
allow
Checks whether a constructor explicitly allows JEXL introspection.- Specified by:
allowin interfaceJexlPermissions- Parameters:
ctor- The constructor to check- Returns:
- true if JEXL is allowed to introspect, false otherwise
-
allow
Checks whether a field explicitly allows JEXL introspection.- Specified by:
allowin interfaceJexlPermissions- Parameters:
field- The field to check- Returns:
- true if JEXL is allowed to introspect, false otherwise
-
allow
Description copied from interface:JexlPermissionsChecks whether a method allows JEXL introspection.If a method is not allowed, it cannot be resolved and called in scripts or expressions.
Since methods can be overridden and overloaded, this checks that this class explicitly allows this method - superseding any superclass or interface specified permissions.
- Specified by:
allowin interfaceJexlPermissions- Parameters:
clazz- The class from which the method is accessed, used to check that the method is allowed for this classmethod- The method to check- Returns:
- true if JEXL is allowed to introspect, false otherwise
-
allow
Description copied from interface:JexlPermissionsChecks whether a field explicitly allows JEXL introspection.If a field is not allowed, it cannot be resolved and accessed in scripts or expressions.
- Specified by:
allowin interfaceJexlPermissions- Parameters:
clazz- The class from which the field is accessed, used to check that the field is allowed for this classfield- The field to check- Returns:
- true if JEXL is allowed to introspect, false otherwise
-
allow
Checks whether a method explicitly allows JEXL introspection.Since methods can be overridden, this also checks that no superclass or interface explicitly disallows this method.
- Specified by:
allowin interfaceJexlPermissions- Parameters:
method- The method to check- Returns:
- true if JEXL is allowed to introspect, false otherwise
-
allow
Checks whether a package explicitly disallows JEXL introspection.- Specified by:
allowin interfaceJexlPermissions- Parameters:
pack- The package- Returns:
- true if JEXL is allowed to introspect, false otherwise
-
deny
Tests whether a whole class is denied Jexl visibility.Also checks package visibility.
- Parameters:
clazz- The class- Returns:
- true if denied, false otherwise
-
deny
Tests whether a constructor is denied Jexl visibility.- Parameters:
ctor- The constructor- Returns:
- true if denied, false otherwise
-
deny
Tests whether a field is denied Jexl visibility.- Parameters:
field- The field- Returns:
- true if denied, false otherwise
-
deny
Tests whether a method is denied Jexl visibility.- Parameters:
method- The method- Returns:
- true if denied, false otherwise
-
deny
Tests whether a whole package is denied Jexl visibility.- Parameters:
pack- The package- Returns:
- true if denied, false otherwise
-
denyMethod
Tests whether a method is denied.- Parameters:
method- The method- Returns:
- true if it has been disallowed through annotation or declaration
-
getNoJexl
Gets the class constraints.If nothing was explicitly forbidden, everything is allowed.
- Parameters:
clazz- The class- Returns:
- The class constraints instance, not-null.
-
getNoJexl
-