public final class FilterParser extends Object
| Modifier | Constructor and Description |
|---|---|
private |
FilterParser() |
| Modifier and Type | Method and Description |
|---|---|
static ExprNode |
parse(SchemaManager schemaManager,
String filter)
Parses a search filter from it's string representation to an expression node object,
using the provided SchemaManager
|
static ExprNode |
parse(SchemaManager schemaManager,
String filter,
boolean relaxed)
Parses a search filter from it's string representation to an expression node object,
using the provided SchemaManager
|
static ExprNode |
parse(String filter)
Parses a search filter from it's string representation to an expression node object.
|
static ExprNode |
parse(String filter,
boolean relaxed)
Parses a search filter from it's string representation to an expression node object.
|
private static Value |
parseAssertionValue(SchemaManager schemaManager,
byte[] filterBytes,
org.apache.directory.api.util.Position pos)
An assertion value :
assertionvalue = valueencoding
valueencoding = 0*(normal / escaped)
normal = UTF1SUBSET / UTFMB
escaped = '\' HEX HEX
HEX = '0'-'9' / 'A'-'F' / 'a'-'f'
UTF1SUBSET = %x01-27 / %x2B-5B / %x5D-7F (Everything but '\0', '*', '(', ')' and '\')
UTFMB = UTF2 / UTF3 / UTF4
UTF0 = %x80-BF
UTF2 = %xC2-DF UTF0
UTF3 = %xE0 %xA0-BF UTF0 / %xE1-EC UTF0 UTF0 / %xED %x80-9F UTF0 / %xEE-EF UTF0 UTF0
UTF4 = %xF0 %x90-BF UTF0 UTF0 / %xF1-F3 UTF0 UTF0 UTF0 / %xF4 %x80-8F UTF0 UTF0
With the specific constraints (RFC 4515):
"The <valueencoding> rule ensures that the entire filter string is a"
"valid UTF-8 string and provides that the octets that represent the"
"ASCII characters "*" (ASCII 0x2a), "(" (ASCII 0x28), ")" (ASCII"
"0x29), "\" (ASCII 0x5c), and NUL (ASCII 0x00) are represented as a"
"backslash "\" (ASCII 0x5c) followed by the two hexadecimal digits"
"representing the value of the encoded octet."
|
private static Value |
parseAssertionValue(SchemaManager schemaManager,
String attribute,
byte[] filterBytes,
org.apache.directory.api.util.Position pos)
An assertion value :
assertionvalue = valueencoding
valueencoding = 0*(normal / escaped)
normal = UTF1SUBSET / UTFMB
escaped = '\' HEX HEX
HEX = '0'-'9' / 'A'-'F' / 'a'-'f'
UTF1SUBSET = %x01-27 / %x2B-5B / %x5D-7F (Everything but '\0', '*', '(', ')' and '\')
UTFMB = UTF2 / UTF3 / UTF4
UTF0 = %x80-BF
UTF2 = %xC2-DF UTF0
UTF3 = %xE0 %xA0-BF UTF0 / %xE1-EC UTF0 UTF0 / %xED %x80-9F UTF0 / %xEE-EF UTF0 UTF0
UTF4 = %xF0 %x90-BF UTF0 UTF0 / %xF1-F3 UTF0 UTF0 UTF0 / %xF4 %x80-8F UTF0 UTF0
With the specific constraints (RFC 4515):
"The <valueencoding< rule ensures that the entire filter string is a"
"valid UTF-8 string and provides that the octets that represent the"
"ASCII characters "*" (ASCII 0x2a), "(" (ASCII 0x28), ")" (ASCII"
"0x29), "\" (ASCII 0x5c), and NUL (ASCII 0x00) are represented as a"
"backslash "\" (ASCII 0x5c) followed by the two hexadecimal digits"
"representing the value of the encoded octet."
|
private static ExprNode |
parseBranchNode(SchemaManager schemaManager,
ExprNode node,
byte[] filterBytes,
org.apache.directory.api.util.Position pos,
boolean relaxed)
Parse AND, OR and NOT nodes :
and = '&' filterlist
or = '|' filterlist
not = '!'
|
private static ExprNode |
parseExtensible(SchemaManager schemaManager,
String attribute,
byte[] filterBytes,
org.apache.directory.api.util.Position pos,
boolean relaxed)
Parse an extensible
extensible = ( attr [":dn"] [':' oid] ":=" assertionvalue )
/ ( [":dn"] ':' oid ":=" assertionvalue )
matchingrule = ":" oid
|
private static ExprNode |
parseFilterComp(SchemaManager schemaManager,
byte[] filterBytes,
org.apache.directory.api.util.Position pos,
boolean relaxed)
filtercomp = and / or / not / item
and = '&' WSP* filterlist
or = '|' WSP* filterlist
not = '!'
|
private static ExprNode |
parseFilterInternal(SchemaManager schemaManager,
byte[] filterBytes,
org.apache.directory.api.util.Position pos,
boolean relaxed)
Parse the grammar rule :
filter ::= WSP* '(' WSP* filterComp WSP* ')' WSP*
|
private static ExprNode |
parseItem(SchemaManager schemaManager,
byte[] filterBytes,
org.apache.directory.api.util.Position pos,
byte b,
boolean relaxed)
Parse the following grammar :
item = simple / present / substring / extensible
simple = attr WSP* filtertype WSP* assertionvalue
filtertype = '=' / '~=' / '>=' / '<='
present = attr WSP* '=' '*'
substring = attr WSP* '=' WSP* [initial] any [final]
extensible = ( attr [":dn"] [':' oid] ":=" assertionvalue )
/ ( [":dn"] ':' oid ":=" assertionvalue )
matchingrule = ":" oid
An item starts with an attribute or a colon.
|
private static ExprNode |
parsePresenceEqOrSubstring(SchemaManager schemaManager,
String attribute,
byte[] filterBytes,
org.apache.directory.api.util.Position pos)
Here is the grammar to parse :
simple ::= '=' assertionValue
present ::= '=' '*'
substring ::= '=' [initial] any [final]
initial ::= assertionValue
any ::= '*' ( assertionValue '*')*
As we can see, there is an ambiguity in the grammar : attr=* can be
seen as a present or as a substring.
|
private static ExprNode |
parseSubstring(SchemaManager schemaManager,
String attribute,
Value initial,
byte[] filterBytes,
org.apache.directory.api.util.Position pos)
Parse a substring
|
private static void |
skipWhiteSpaces(byte[] filter,
org.apache.directory.api.util.Position pos)
Skip the white spaces (0x20, 0x09, 0x0a and 0x0d)
|
public static ExprNode parse(String filter) throws ParseException
filter - the search filter in it's string representationParseException - If the filter is invalidpublic static ExprNode parse(String filter, boolean relaxed) throws ParseException
relaxed mode the filter may violate RFC 4515, e.g. the underscore in attribute names is allowed.filter - the search filter in it's string representationrelaxed - true to parse the filter in relaxed modeParseException - If the filter is invalidpublic static ExprNode parse(SchemaManager schemaManager, String filter) throws ParseException
schemaManager - The SchemaManager to usefilter - the search filter in it's string representationParseException - If the filter is invalidprivate static void skipWhiteSpaces(byte[] filter,
org.apache.directory.api.util.Position pos)
filter - The filter being parsedpos - The current position in the filterpublic static ExprNode parse(SchemaManager schemaManager, String filter, boolean relaxed) throws ParseException
schemaManager - The SchemaManager to usefilter - the search filter in it's string representationrelaxed - true to parse the filter in relaxed modeParseException - If the filter is invalidprivate static ExprNode parseExtensible(SchemaManager schemaManager, String attribute, byte[] filterBytes, org.apache.directory.api.util.Position pos, boolean relaxed) throws LdapException, ParseException
extensible = ( attr [":dn"] [':' oid] ":=" assertionvalue )
/ ( [":dn"] ':' oid ":=" assertionvalue )
matchingrule = ":" oid
schemaManager - The SchemaManagerattribute - The filter's attributefilterBytes - The filter bytes to parsepos - The position in the filter bytesrelaxed - If the filter is analyzed in relaxed mode or notExprNodeParseException - If the Node can't be parsedLdapException - If we met an error while parsing a filter elementprivate static Value parseAssertionValue(SchemaManager schemaManager, String attribute, byte[] filterBytes, org.apache.directory.api.util.Position pos) throws ParseException, LdapInvalidAttributeValueException
assertionvalue = valueencoding
valueencoding = 0*(normal / escaped)
normal = UTF1SUBSET / UTFMB
escaped = '\' HEX HEX
HEX = '0'-'9' / 'A'-'F' / 'a'-'f'
UTF1SUBSET = %x01-27 / %x2B-5B / %x5D-7F (Everything but '\0', '*', '(', ')' and '\')
UTFMB = UTF2 / UTF3 / UTF4
UTF0 = %x80-BF
UTF2 = %xC2-DF UTF0
UTF3 = %xE0 %xA0-BF UTF0 / %xE1-EC UTF0 UTF0 / %xED %x80-9F UTF0 / %xEE-EF UTF0 UTF0
UTF4 = %xF0 %x90-BF UTF0 UTF0 / %xF1-F3 UTF0 UTF0 UTF0 / %xF4 %x80-8F UTF0 UTF0
With the specific constraints (RFC 4515):
"The <valueencoding< rule ensures that the entire filter string is a"
"valid UTF-8 string and provides that the octets that represent the"
"ASCII characters "*" (ASCII 0x2a), "(" (ASCII 0x28), ")" (ASCII"
"0x29), "\" (ASCII 0x5c), and NUL (ASCII 0x00) are represented as a"
"backslash "\" (ASCII 0x5c) followed by the two hexadecimal digits"
"representing the value of the encoded octet."
The incoming String is already transformed from UTF-8 to unicode, so we must assume that the
grammar we have to check is the following :
assertionvalue = valueencoding valueencoding = 0*(normal / escaped) normal = unicodeSubset escaped = '\' HEX HEX HEX = '0'-'9' / 'A'-'F' / 'a'-'f' unicodeSubset = %x01-27 / %x2B-5B / %x5D-FFFF
schemaManager - The SchemaManagerattribute - The associated AttributefilterBytes - The filter bytes to parsepos - The position in the filter bytesParseException - If the value can't be parsedLdapInvalidAttributeValueException - If the value is invalidprivate static Value parseAssertionValue(SchemaManager schemaManager, byte[] filterBytes, org.apache.directory.api.util.Position pos) throws ParseException
assertionvalue = valueencoding
valueencoding = 0*(normal / escaped)
normal = UTF1SUBSET / UTFMB
escaped = '\' HEX HEX
HEX = '0'-'9' / 'A'-'F' / 'a'-'f'
UTF1SUBSET = %x01-27 / %x2B-5B / %x5D-7F (Everything but '\0', '*', '(', ')' and '\')
UTFMB = UTF2 / UTF3 / UTF4
UTF0 = %x80-BF
UTF2 = %xC2-DF UTF0
UTF3 = %xE0 %xA0-BF UTF0 / %xE1-EC UTF0 UTF0 / %xED %x80-9F UTF0 / %xEE-EF UTF0 UTF0
UTF4 = %xF0 %x90-BF UTF0 UTF0 / %xF1-F3 UTF0 UTF0 UTF0 / %xF4 %x80-8F UTF0 UTF0
With the specific constraints (RFC 4515):
"The <valueencoding> rule ensures that the entire filter string is a"
"valid UTF-8 string and provides that the octets that represent the"
"ASCII characters "*" (ASCII 0x2a), "(" (ASCII 0x28), ")" (ASCII"
"0x29), "\" (ASCII 0x5c), and NUL (ASCII 0x00) are represented as a"
"backslash "\" (ASCII 0x5c) followed by the two hexadecimal digits"
"representing the value of the encoded octet."
The incoming String is already transformed from UTF-8 to unicode, so we must assume that the
grammar we have to check is the following :
assertionvalue = valueencoding valueencoding = 0*(normal / escaped) normal = unicodeSubset escaped = '\' HEX HEX HEX = '0'-'9' / 'A'-'F' / 'a'-'f' unicodeSubset = %x01-27 / %x2B-5B / %x5D-FFFF
schemaManager - The SchemaManagerfilterBytes - The filter bytes to parsepos - The position in the filter bytesParseException - If the value can't be parsedprivate static ExprNode parseSubstring(SchemaManager schemaManager, String attribute, Value initial, byte[] filterBytes, org.apache.directory.api.util.Position pos) throws ParseException, LdapException
schemaManager - The SchemaManagerattribute - The filter's attributeinitial - The filter's initial partfilterBytes - The filter bytes to parsepos - The position in the filter bytesExprNodeParseException - If the Node can't be parsedLdapException - If we met an error while parsing a filter elementprivate static ExprNode parsePresenceEqOrSubstring(SchemaManager schemaManager, String attribute, byte[] filterBytes, org.apache.directory.api.util.Position pos) throws ParseException, LdapException
simple ::= '=' assertionValue present ::= '=' '*' substring ::= '=' [initial] any [final] initial ::= assertionValue any ::= '*' ( assertionValue '*')*As we can see, there is an ambiguity in the grammar : attr=* can be seen as a present or as a substring. As stated in the RFC :
"Note that although both the <substring> and <present> productions in" "the grammar above can produce the "attr=*" construct, this construct" "is used only to denote a presence filter." (RFC 4515, 3)We have also to consider the difference between a substring and the equality node : this last node does not contain a '*'
schemaManager - The SchemaManagerattribute - The filter's attributefilterBytes - The filter bytes to parsepos - The position in the filter bytesExprNodeParseException - If the Node can't be parsedLdapException - If we met an error while parsing a filter elementprivate static ExprNode parseItem(SchemaManager schemaManager, byte[] filterBytes, org.apache.directory.api.util.Position pos, byte b, boolean relaxed) throws ParseException, LdapException
item = simple / present / substring / extensible
simple = attr WSP* filtertype WSP* assertionvalue
filtertype = '=' / '~=' / '>=' / '<='
present = attr WSP* '=' '*'
substring = attr WSP* '=' WSP* [initial] any [final]
extensible = ( attr [":dn"] [':' oid] ":=" assertionvalue )
/ ( [":dn"] ':' oid ":=" assertionvalue )
matchingrule = ":" oid
An item starts with an attribute or a colon.schemaManager - The SchemaManagerfilterBytes - The filter bytes to parsepos - The position in the filter bytesb - The type of itemrelaxed - If the filter is analyzed in relaxed mode or notExprNodeParseException - If the Node can't be parsedLdapException - If we met an error while parsing a filter elementprivate static ExprNode parseBranchNode(SchemaManager schemaManager, ExprNode node, byte[] filterBytes, org.apache.directory.api.util.Position pos, boolean relaxed) throws ParseException, LdapException
and = '&' filterlist or = '|' filterlist not = '!' filter filterlist = 1*filter
schemaManager - The SchemaManagernode - The node to feedfilterBytes - The filter bytes to parsepos - The position in the filter bytesrelaxed - If the filter is analyzed in relaxed mode or notExprNodeParseException - If the Node can't be parsedLdapException - If we met an error while parsing a filter elementprivate static ExprNode parseFilterComp(SchemaManager schemaManager, byte[] filterBytes, org.apache.directory.api.util.Position pos, boolean relaxed) throws ParseException, LdapException
filtercomp = and / or / not / item
and = '&' WSP* filterlist
or = '|' WSP* filterlist
not = '!' WSP* filter
item = simple / present / substring / extensible
simple = attr WSP* filtertype WSP* assertionvalue
present = attr WSP* EQUALS ASTERISK
substring = attr WSP* EQUALS WSP* [initial] any [final]
extensible = ( attr [dnattrs]
[matchingrule] COLON EQUALS assertionvalue )
/ ( [dnattrs]
matchingrule COLON EQUALS assertionvalue )
schemaManager - The SchemaManagerfilterBytes - The filter bytes to parsepos - The position in the filter bytesrelaxed - If the filter is analyzed in relaxed mode or notExprNodeParseException - If the Node can't be parsedLdapException - If we met an error while parsing a filter elementprivate static ExprNode parseFilterInternal(SchemaManager schemaManager, byte[] filterBytes, org.apache.directory.api.util.Position pos, boolean relaxed) throws ParseException, LdapException
filter ::= WSP* '(' WSP* filterComp WSP* ')' WSP*
schemaManager - The SchemaManagerfilterBytes - The filter bytes to parsepos - The position in the filter bytesrelaxed - If the filter is analyzed in relaxed mode or notExprNodeParseException - If the Node can't be parsedLdapException - If we met an error while parsing a filter elementCopyright © 2003–2022 The Apache Software Foundation. All rights reserved.