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 field; # field } # end class0 } # 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

      public Permissions parse(String... srcs)
      Parses permissions from a source.
      Parameters:
      srcs - the sources
      Returns:
      the permissions map
    • 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
    • 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
    • readEol

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

      private int readSpaces(int offset)
      Reads spaces.
      Parameters:
      offset - initial position
      Returns:
      position after spaces
    • 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.
    • readClass

      private int readClass(Permissions.NoJexlPackage njpackage, String outer, String inner, int offset)
      Reads a class permission.
      Parameters:
      njpackage - the owning package
      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