Class PermissionsParser
- java.lang.Object
-
- org.apache.commons.jexl3.internal.introspection.PermissionsParser
-
public class PermissionsParser extends java.lang.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 Summary
Fields Modifier and Type Field Description private java.util.Map<java.lang.String,Permissions.NoJexlPackage>
packages
The @NoJexl execution-time map.private int
size
The source size.private java.lang.String
src
The source.private java.util.Set<java.lang.String>
wildcards
The set of wildcard imports.
-
Constructor Summary
Constructors Constructor Description PermissionsParser()
Basic ctor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
clear()
Clears this parser internals.Permissions
parse(java.lang.String... srcs)
Parses permissions from a source.(package private) Permissions
parse(java.util.Set<java.lang.String> wildcards, java.util.Map<java.lang.String,Permissions.NoJexlPackage> packages, java.lang.String... srcs)
Parses permissions from a source.private int
readClass(Permissions.NoJexlPackage njpackage, boolean nojexl, java.lang.String outer, java.lang.String inner, int offset)
Reads a class permission.private int
readEol(int offset)
Reads a comment till end-of-line.private int
readIdentifier(java.lang.StringBuilder id, int offset)
Reads an identifier (optionally dot-separated).private int
readIdentifier(java.lang.StringBuilder id, int offset, boolean dot, boolean star)
Reads an identifier (optionally dot-separated).private void
readPackages()
Reads a package permission.private int
readSpaces(int offset)
Reads spaces.private java.lang.String
unexpected(char c, int i)
Compose a parsing error message.
-
-
-
Field Detail
-
src
private java.lang.String src
The source.
-
size
private int size
The source size.
-
packages
private java.util.Map<java.lang.String,Permissions.NoJexlPackage> packages
The @NoJexl execution-time map.
-
wildcards
private java.util.Set<java.lang.String> wildcards
The set of wildcard imports.
-
-
Method Detail
-
clear
private void clear()
Clears this parser internals.
-
parse
Permissions parse(java.util.Set<java.lang.String> wildcards, java.util.Map<java.lang.String,Permissions.NoJexlPackage> packages, java.lang.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
public Permissions parse(java.lang.String... srcs)
Parses permissions from a source.- Parameters:
srcs
- the sources- Returns:
- the permissions map
-
readClass
private int readClass(Permissions.NoJexlPackage njpackage, boolean nojexl, java.lang.String outer, java.lang.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
private int readIdentifier(java.lang.StringBuilder id, int offset)
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
private int readIdentifier(java.lang.StringBuilder id, int offset, boolean dot, boolean star)
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
private java.lang.String unexpected(char c, int i)
Compose a parsing error message.- Parameters:
c
- the offending characteri
- the offset position- Returns:
- the error message
-
-