java.lang.Object
org.apache.commons.jexl3.internal.introspection.Permissions
All Implemented Interfaces:
JexlPermissions

public class Permissions extends Object implements JexlPermissions
Checks whether an element (ctor, field, or method) is visible by JEXL introspection.

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...).

  • Field Details

  • Constructor Details

    • Permissions

      protected Permissions()
      Allow inheritance.
    • Permissions

      protected Permissions(Set<String> perimeter, Map<String,Permissions.NoJexlPackage> nojexl)
      Default ctor.
      Parameters:
      perimeter - The allowed wildcard set of packages
      nojexl - The NoJexl external map
  • Method Details

    • copyMap

      static <T extends Permissions.Copyable<T>> Map<String,T> copyMap(Map<String,T> map)
      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

      public Permissions compose(String... src)
      Creates a new set of permissions by composing these permissions with a new set of rules.
      Specified by:
      compose in interface JexlPermissions
      Parameters:
      src - The rules
      Returns:
      The new permissions
    • classKey

      static String classKey(Class<?> clazz)
      Creates a class key joining enclosing ascendants with '$'.

      As in outer$inner for class outer { class inner....

      Parameters:
      clazz - The clazz
      Returns:
      The clazz key
    • classKey

      static String classKey(Class<?> clazz, StringBuilder strb)
      Creates a class key joining enclosing ascendants with '$'.

      As in outer$inner for class outer { class inner....

      Parameters:
      clazz - The clazz
      strb - The buffer to compose the key
      Returns:
      The clazz key
    • wildcardAllow

      static boolean wildcardAllow(Set<String> allowed, String name)
      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

      private Permissions.NoJexlPackage getNoJexlPackage(String packageName)
      Gets the package constraints.
      Parameters:
      packageName - The package name
      Returns:
      The package constraints instance, not-null.
    • getPackages

      Returns:
      The packages
    • getWildcards

      Set<String> getWildcards()
      Returns:
      The wildcards
    • allowedPackage

      private boolean allowedPackage(String packageName)
      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 in allowed; 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

      public boolean allow(Class<?> clazz)
      Checks whether a class or one of its super-classes or implemented interfaces explicitly allows JEXL introspection.
      Specified by:
      allow in interface JexlPermissions
      Parameters:
      clazz - The class to check
      Returns:
      true if JEXL is allowed to introspect, false otherwise
    • allowedClass

      private boolean allowedClass(Class<?> clazz)
      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

      private boolean allow(Class<?> clazz, Method method, boolean[] explicit)
      Check whether a method is allowed to be introspected in one superclass or interface.
      Parameters:
      clazz - The superclass or interface to check
      method - The method
      explicit - carries whether the package holding the method is explicitly allowed
      Returns:
      true if JEXL is allowed to introspect, false otherwise
    • allow

      public boolean allow(Constructor<?> ctor)
      Checks whether a constructor explicitly allows JEXL introspection.
      Specified by:
      allow in interface JexlPermissions
      Parameters:
      ctor - The constructor to check
      Returns:
      true if JEXL is allowed to introspect, false otherwise
    • allow

      public boolean allow(Field field)
      Checks whether a field explicitly allows JEXL introspection.
      Specified by:
      allow in interface JexlPermissions
      Parameters:
      field - The field to check
      Returns:
      true if JEXL is allowed to introspect, false otherwise
    • allow

      public boolean allow(Class<?> clazz, Method method)
      Description copied from interface: JexlPermissions
      Checks 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:
      allow in interface JexlPermissions
      Parameters:
      clazz - The class from which the method is accessed, used to check that the method is allowed for this class
      method - The method to check
      Returns:
      true if JEXL is allowed to introspect, false otherwise
    • allow

      public boolean allow(Class<?> clazz, Field field)
      Description copied from interface: JexlPermissions
      Checks 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:
      allow in interface JexlPermissions
      Parameters:
      clazz - The class from which the field is accessed, used to check that the field is allowed for this class
      field - The field to check
      Returns:
      true if JEXL is allowed to introspect, false otherwise
    • allow

      public boolean allow(Method method)
      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:
      allow in interface JexlPermissions
      Parameters:
      method - The method to check
      Returns:
      true if JEXL is allowed to introspect, false otherwise
    • allow

      public boolean allow(Package pack)
      Checks whether a package explicitly disallows JEXL introspection.
      Specified by:
      allow in interface JexlPermissions
      Parameters:
      pack - The package
      Returns:
      true if JEXL is allowed to introspect, false otherwise
    • deny

      private boolean deny(Class<?> clazz)
      Tests whether a whole class is denied Jexl visibility.

      Also checks package visibility.

      Parameters:
      clazz - The class
      Returns:
      true if denied, false otherwise
    • deny

      private boolean deny(Constructor<?> ctor)
      Tests whether a constructor is denied Jexl visibility.
      Parameters:
      ctor - The constructor
      Returns:
      true if denied, false otherwise
    • deny

      private boolean deny(Field field)
      Tests whether a field is denied Jexl visibility.
      Parameters:
      field - The field
      Returns:
      true if denied, false otherwise
    • deny

      private boolean deny(Method method)
      Tests whether a method is denied Jexl visibility.
      Parameters:
      method - The method
      Returns:
      true if denied, false otherwise
    • deny

      private boolean deny(Package pack)
      Tests whether a whole package is denied Jexl visibility.
      Parameters:
      pack - The package
      Returns:
      true if denied, false otherwise
    • denyMethod

      private boolean denyMethod(Method method)
      Tests whether a method is denied.
      Parameters:
      method - The method
      Returns:
      true if it has been disallowed through annotation or declaration
    • getNoJexl

      private Permissions.NoJexlClass getNoJexl(Class<?> clazz)
      Gets the class constraints.

      If nothing was explicitly forbidden, everything is allowed.

      Parameters:
      clazz - The class
      Returns:
      The class constraints instance, not-null.
    • getNoJexl

      private Permissions.NoJexlClass getNoJexl(Class<?> clazz, Permissions.NoJexlClass ifNone)