Class PermissionsParser
java.lang.Object
org.apache.commons.jexl3.internal.introspection.PermissionsParser
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 Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate voidclear()Clears this parser internals.private static Permissions.NoJexlPackagemergePackage(Permissions.NoJexlPackage existing, boolean deny, boolean denyAll) Creates or merges a package entry when a '{' block is opened.Parses permissions from a source.(package private) PermissionsParses permissions from a source.private intreadClass(Permissions.NoJexlPackage njpackage, boolean nojexl, String outer, String inner, int offset) Reads a class permission.private intreadEol(int offset) Reads a comment till end-of-line.private intreadIdentifier(StringBuilder id, int offset) Reads an identifier (optionally dot-separated).private intreadIdentifier(StringBuilder id, int offset, boolean dot, boolean star) Reads an identifier (optionally dot-separated).private voidReads a package permission.private intreadSpaces(int offset) Reads spaces.private Stringunexpected(char c, int i) Compose a parsing error message.
-
Field Details
-
src
The source. -
size
private int sizeThe source size. -
packages
The @NoJexl execution-time map. -
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 packagespackages- The map of restricted elementssrcs- The sources- Returns:
- The permissions map
-
parse
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 packagenojexl- whether the restriction is explicitly denying (true) or allowing (false) membersouter- 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
Reads an identifier (optionally dot-separated).- Parameters:
id- The builder to fill the identifier character withoffset- The initial reading position- Returns:
- The position after the identifier
-
readIdentifier
Reads an identifier (optionally dot-separated).- Parameters:
id- The builder to fill the identifier character withoffset- The initial reading positiondot- whether dots (.) are allowedstar- whether stars (*) are allowed- Returns:
- The position after the identifier
-
mergePackage
private static Permissions.NoJexlPackage mergePackage(Permissions.NoJexlPackage existing, boolean deny, boolean denyAll) Creates or merges a package entry when a '{' block is opened.- Parameters:
existing- the current value in the packages map, ornullif absentdeny- whether the new entry is deny-orienteddenyAll- whether unlisted classes should be denied (preserve deny-all-unlisted semantics)- Returns:
- the package instance to store
-
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
Compose a parsing error message.- Parameters:
c- The offending characteri- The offset position- Returns:
- The error message
-