Class PermissionsParser

java.lang.Object
org.apache.commons.jexl3.internal.introspection.PermissionsParser

public class PermissionsParser extends Object
A crude parser to configure permissions akin to NoJexl annotations. The syntax recognizes 2 types of permissions:
  • restricting access to packages, classes (and inner classes), methods and fields
  • allowing access to a wildcard restricted set of packages

Example:

  my.allowed.packages.*
  another.allowed.package.*
  # nojexl like restrictions
  my.package {
   class0 {...
     class1 {...}
     class2 {
        ...
         class3 {}
     }
     # and eol comment
     class0(); # constructors
     method(); # method is not allowed
     field; # field
   } # end class0
   +class1 {
     method(); // only allowed method of class1
   }
 } # end package my.package
 
  • Field Details

    • src

      private String src
      The source.
    • size

      private int size
      The source size.
    • packages

      The @NoJexl execution-time map.
    • wildcards

      private Set<String> wildcards
      The set of wildcard imports.
  • Constructor Details

    • PermissionsParser

      public PermissionsParser()
      Basic ctor.
  • Method Details

    • clear

      private void clear()
      Clears this parser internals.
    • parse

      Permissions parse(Set<String> wildcards, Map<String,Permissions.NoJexlPackage> packages, String... srcs)
      Parses permissions from a source.
      Parameters:
      wildcards - the set of allowed packages
      packages - the map of restricted elements
      srcs - the sources
      Returns:
      the permissions map
    • parse

      public Permissions parse(String... srcs)
      Parses permissions from a source.
      Parameters:
      srcs - the sources
      Returns:
      the permissions map
    • readClass

      private int readClass(Permissions.NoJexlPackage njpackage, boolean nojexl, String outer, String inner, int offset)
      Reads a class permission.
      Parameters:
      njpackage - the owning package
      nojexl - whether the restriction is explicitly denying (true) or allowing (false) members
      outer - the outer class (if any)
      inner - the inner class name (if any)
      offset - the initial parsing position in the source
      Returns:
      the new parsing position
    • readEol

      private int readEol(int offset)
      Reads a comment till end-of-line.
      Parameters:
      offset - initial position
      Returns:
      position after comment
    • readIdentifier

      private int readIdentifier(StringBuilder id, int offset)
      Reads an identifier (optionally dot-separated).
      Parameters:
      id - the builder to fill the identifier character with
      offset - the initial reading position
      Returns:
      the position after the identifier
    • readIdentifier

      private int readIdentifier(StringBuilder id, int offset, boolean dot, boolean star)
      Reads an identifier (optionally dot-separated).
      Parameters:
      id - the builder to fill the identifier character with
      offset - the initial reading position
      dot - whether dots (.) are allowed
      star - whether stars (*) are allowed
      Returns:
      the position after the identifier
    • readPackages

      private void readPackages()
      Reads a package permission.
    • readSpaces

      private int readSpaces(int offset)
      Reads spaces.
      Parameters:
      offset - initial position
      Returns:
      position after spaces
    • unexpected

      private String unexpected(char c, int i)
      Compose a parsing error message.
      Parameters:
      c - the offending character
      i - the offset position
      Returns:
      the error message