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