Package com.unboundid.ldap.sdk
Class Filter
java.lang.Object
com.unboundid.ldap.sdk.Filter
- All Implemented Interfaces:
Serializable
@NotMutable
@ThreadSafety(level=COMPLETELY_THREADSAFE)
public final class Filter
extends Object
implements Serializable
This class provides a data structure that represents an LDAP search filter.
It provides methods for creating various types of filters, as well as parsing
a filter from a string. See
RFC 4515 for more
information about representing search filters as strings.
The following filter types are defined:
There are two primary ways to create a search filter. The first is to create a filter from its string representation with the
Creating a filter from its string representation is a common approach and seems to be relatively straightforward, but it does have some hidden dangers. This primarily comes from the potential for special characters in the filter string which need to be properly escaped. If this isn't done, then the search may fail or behave unexpectedly, or worse it could lead to a vulnerability in the application in which a malicious user could trick the application into retrieving more information than it should have. To avoid these problems, it may be better to construct filters from their individual components rather than their string representations, like:
The following filter types are defined:
- AND -- This is used to indicate that a filter should match an entry only if all of the embedded filter components match that entry. An AND filter with zero embedded filter components is considered an LDAP TRUE filter as defined in RFC 4526 and will match any entry. AND filters contain only a set of embedded filter components, and each of those embedded components can itself be any type of filter, including an AND, OR, or NOT filter with additional embedded components.
- OR -- This is used to indicate that a filter should match an entry only if at least one of the embedded filter components matches that entry. An OR filter with zero embedded filter components is considered an LDAP FALSE filter as defined in RFC 4526 and will never match any entry. OR filters contain only a set of embedded filter components, and each of those embedded components can itself be any type of filter, including an AND, OR, or NOT filter with additional embedded components.
- NOT -- This is used to indicate that a filter should match an entry only if the embedded NOT component does not match the entry. A NOT filter contains only a single embedded NOT filter component, but that embedded component can itself be any type of filter, including an AND, OR, or NOT filter with additional embedded components.
- EQUALITY -- This is used to indicate that a filter should match an entry only if the entry contains a value for the specified attribute that is equal to the provided assertion value. An equality filter contains only an attribute name and an assertion value.
- SUBSTRING -- This is used to indicate that a filter should match
an entry only if the entry contains at least one value for the
specified attribute that matches the provided substring assertion. The
substring assertion must contain at least one element of the following
types:
- subInitial -- This indicates that the specified string must appear at the beginning of the attribute value. There can be at most one subInitial element in a substring assertion.
- subAny -- This indicates that the specified string may appear anywhere in the attribute value. There can be any number of substring subAny elements in a substring assertion. If there are multiple subAny elements, then they must match in the order that they are provided.
- subFinal -- This indicates that the specified string must appear at the end of the attribute value. There can be at most one subFinal element in a substring assertion.
- GREATER-OR-EQUAL -- This is used to indicate that a filter should match an entry only if that entry contains at least one value for the specified attribute that is greater than or equal to the provided assertion value. A greater-or-equal filter contains only an attribute name and an assertion value.
- LESS-OR-EQUAL -- This is used to indicate that a filter should match an entry only if that entry contains at least one value for the specified attribute that is less than or equal to the provided assertion value. A less-or-equal filter contains only an attribute name and an assertion value.
- PRESENCE -- This is used to indicate that a filter should match an entry only if the entry contains at least one value for the specified attribute. A presence filter contains only an attribute name.
- APPROXIMATE-MATCH -- This is used to indicate that a filter should match an entry only if the entry contains at least one value for the specified attribute that is approximately equal to the provided assertion value. The definition of "approximately equal to" may vary from one server to another, and from one attribute to another, but it is often implemented as a "sounds like" match using a variant of the metaphone or double-metaphone algorithm. An approximate-match filter contains only an attribute name and an assertion value.
- EXTENSIBLE-MATCH -- This is used to perform advanced types of
matching against entries, according to the following criteria:
- If an attribute name is provided, then the assertion value must match one of the values for that attribute (potentially including values contained in the entry's DN). If a matching rule ID is also provided, then the associated matching rule will be used to determine whether there is a match; otherwise the default equality matching rule for that attribute will be used.
- If no attribute name is provided, then a matching rule ID must be given, and the corresponding matching rule will be used to determine whether any attribute in the target entry (potentially including attributes contained in the entry's DN) has at least one value that matches the provided assertion value.
- If the dnAttributes flag is set, then attributes contained in the entry's DN will also be evaluated to determine if they match the filter criteria. If it is not set, then attributes contained in the entry's DN (other than those contained in its RDN which are also present as separate attributes in the entry) will not be examined.
There are two primary ways to create a search filter. The first is to create a filter from its string representation with the
create(String) method, using the syntax described in RFC 4515.
For example:
Filter f1 = Filter.create("(objectClass=*)");
Filter f2 = Filter.create("(uid=john.doe)");
Filter f3 = Filter.create("(|(givenName=John)(givenName=Johnathan))");
Creating a filter from its string representation is a common approach and seems to be relatively straightforward, but it does have some hidden dangers. This primarily comes from the potential for special characters in the filter string which need to be properly escaped. If this isn't done, then the search may fail or behave unexpectedly, or worse it could lead to a vulnerability in the application in which a malicious user could trick the application into retrieving more information than it should have. To avoid these problems, it may be better to construct filters from their individual components rather than their string representations, like:
Filter f1 = Filter.present("objectClass");
Filter f2 = Filter.equals("uid", "john.doe");
Filter f3 = Filter.or(
Filter.equals("givenName", "John"),
Filter.equals("givenName", "Johnathan"));
In general, it is recommended to avoid creating filters from their string
representations if any of that string representation may include
user-provided data or special characters including non-ASCII characters,
parentheses, asterisks, or backslashes.- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final byteThe BER type for AND search filters.static final byteThe BER type for approximate match search filters.static final byteThe BER type for equality search filters.static final byteThe BER type for extensible match search filters.static final byteThe BER type for greaterOrEqual search filters.static final byteThe BER type for lessOrEqual search filters.static final byteThe BER type for NOT search filters.static final byteThe BER type for OR search filters.static final byteThe BER type for presence search filters.static final byteThe BER type for substring search filters. -
Method Summary
Modifier and TypeMethodDescriptionstatic FilterCreates a new AND search filter with the provided components.static Filterand(Collection<Filter> andComponents) Creates a new AND search filter with the provided components.static FilterapproximateMatch(String attributeName, byte[] assertionValue) Creates a new approximate match search filter with the provided information.static FilterapproximateMatch(String attributeName, String assertionValue) Creates a new approximate match search filter with the provided information.static FilterCreates a new search filter from the provided string representation.static FiltercreateANDFilter(Filter... andComponents) Creates a new AND search filter with the provided components.static FiltercreateANDFilter(Collection<Filter> andComponents) Creates a new AND search filter with the provided components.static FiltercreateANDFilter(List<Filter> andComponents) Creates a new AND search filter with the provided components.static FiltercreateApproximateMatchFilter(String attributeName, byte[] assertionValue) Creates a new approximate match search filter with the provided information.static FiltercreateApproximateMatchFilter(String attributeName, String assertionValue) Creates a new approximate match search filter with the provided information.static FiltercreateEqualityFilter(String attributeName, byte[] assertionValue) Creates a new equality search filter with the provided information.static FiltercreateEqualityFilter(String attributeName, String assertionValue) Creates a new equality search filter with the provided information.static FiltercreateExtensibleMatchFilter(String attributeName, String matchingRuleID, boolean dnAttributes, byte[] assertionValue) Creates a new extensible match search filter with the provided information.static FiltercreateExtensibleMatchFilter(String attributeName, String matchingRuleID, boolean dnAttributes, String assertionValue) Creates a new extensible match search filter with the provided information.static FiltercreateGreaterOrEqualFilter(String attributeName, byte[] assertionValue) Creates a new greater-or-equal search filter with the provided information.static FiltercreateGreaterOrEqualFilter(String attributeName, String assertionValue) Creates a new greater-or-equal search filter with the provided information.static FiltercreateLessOrEqualFilter(String attributeName, byte[] assertionValue) Creates a new less-or-equal search filter with the provided information.static FiltercreateLessOrEqualFilter(String attributeName, String assertionValue) Creates a new less-or-equal search filter with the provided information.static FiltercreateNOTFilter(Filter notComponent) Creates a new NOT search filter with the provided component.static FiltercreateORFilter(Filter... orComponents) Creates a new OR search filter with the provided components.static FiltercreateORFilter(Collection<Filter> orComponents) Creates a new OR search filter with the provided components.static FiltercreateORFilter(List<Filter> orComponents) Creates a new OR search filter with the provided components.static FiltercreatePresenceFilter(String attributeName) Creates a new presence search filter with the provided information.static FiltercreateSubAnyFilter(String attributeName, byte[]... subAny) Creates a new substring search filter with only a subAny (contains) component.static FiltercreateSubAnyFilter(String attributeName, String... subAny) Creates a new substring search filter with only a subAny (contains) component.static FiltercreateSubFinalFilter(String attributeName, byte[] subFinal) Creates a new substring search filter with only a subFinal (ends with) component.static FiltercreateSubFinalFilter(String attributeName, String subFinal) Creates a new substring search filter with only a subFinal (ends with) component.static FiltercreateSubInitialFilter(String attributeName, byte[] subInitial) Creates a new substring search filter with only a subInitial (starts with) component.static FiltercreateSubInitialFilter(String attributeName, String subInitial) Creates a new substring search filter with only a subInitial (starts with) component.static StringcreateSubstringAssertion(byte[] subInitial, byte[][] subAny, byte[] subFinal) Creates the string representation of a substring assertion with the provided components.static StringcreateSubstringAssertion(String subInitial, String[] subAny, String subFinal) Creates the string representation of a substring assertion with the provided components.static FiltercreateSubstringFilter(String attributeName, byte[] subInitial, byte[][] subAny, byte[] subFinal) Creates a new substring search filter with the provided information.static FiltercreateSubstringFilter(String attributeName, String subInitial, String[] subAny, String subFinal) Creates a new substring search filter with the provided information.static Filterdecode(ASN1Element filterElement) Decodes the provided ASN.1 element as a search filter.encode()Encodes this search filter to an ASN.1 element suitable for inclusion in an LDAP search request protocol op.static StringencodeValue(byte[] value) Encodes the provided value into a form suitable for use as the assertion value in the string representation of a search filter.static voidencodeValue(ASN1OctetString value, StringBuilder buffer) Appends the assertion value for this filter to the provided buffer, encoding any special characters as necessary.static StringencodeValue(String value) Encodes the provided value into a form suitable for use as the assertion value in the string representation of a search filter.booleanIndicates whether the provided object is equal to this search filter.static FilterCreates a new equality search filter with the provided information.static FilterCreates a new equality search filter with the provided information.static FilterextensibleMatch(String attributeName, String matchingRuleID, boolean dnAttributes, byte[] assertionValue) Creates a new extensible match search filter with the provided information.static FilterextensibleMatch(String attributeName, String matchingRuleID, boolean dnAttributes, String assertionValue) Creates a new extensible match search filter with the provided information.Retrieves the string representation of the assertion value for this search filter.byte[]Retrieves the binary representation of the assertion value for this search filter.Retrieves the name of the attribute type for this search filter.Filter[]Retrieves the set of filter components used in this AND or OR filter.booleanRetrieves the dnAttributes flag for this extensible match filter.byteRetrieves the filter type for this filter.Retrieves the matching rule ID for this extensible match filter.Retrieves the filter component used in this NOT filter.Retrieves the raw assertion value for this search filter as an ASN.1 octet string.Retrieves the raw subAny values for this substring filter.Retrieves the raw subFinal element for this filter as an ASN.1 octet string.Retrieves the raw subInitial element for this filter as an ASN.1 octet string.byte[][]Retrieves the binary representations of the subAny elements for this substring filter.String[]Retrieves the string representations of the subAny elements for this substring filter.byte[]Retrieves the binary representation of the subFinal element for this substring filter.Retrieves the string representation of the subFinal element for this substring filter.byte[]Retrieves the binary representation of the subInitial element for this substring filter.Retrieves the string representation of the subInitial element for this substring filter.static FiltergreaterOrEqual(String attributeName, byte[] assertionValue) Creates a new greater-or-equal search filter with the provided information.static FiltergreaterOrEqual(String attributeName, String assertionValue) Creates a new greater-or-equal search filter with the provided information.inthashCode()Generates a hash code for this search filter.static FilterlessOrEqual(String attributeName, byte[] assertionValue) Creates a new less-or-equal search filter with the provided information.static FilterlessOrEqual(String attributeName, String assertionValue) Creates a new less-or-equal search filter with the provided information.booleanmatchesEntry(Entry entry) Indicates whether this filter matches the provided entry.booleanmatchesEntry(Entry entry, Schema schema) Indicates whether this filter matches the provided entry.static FilterCreates a new NOT search filter with the provided component.static FilterCreates a new OR search filter with the provided components.static Filteror(Collection<Filter> orComponents) Creates a new OR search filter with the provided components.static FilterCreates a new presence search filter with the provided information.static FilterreadFrom(ASN1StreamReader reader) Reads and decodes a search filter from the provided ASN.1 stream reader.static FiltersimplifyFilter(Filter filter, boolean reOrderElements) Attempts to simplify the provided filter to allow it to be more efficiently processed by the server.static FilterCreates a new substring search filter with only a subAny (contains) component.static FilterCreates a new substring search filter with only a subAny (contains) component.static FilterCreates a new substring search filter with only a subFinal (ends with) component.static FilterCreates a new substring search filter with only a subFinal (ends with) component.static FiltersubInitial(String attributeName, byte[] subInitial) Creates a new substring search filter with only a subInitial (starts with) component.static FiltersubInitial(String attributeName, String subInitial) Creates a new substring search filter with only a subInitial (starts with) component.static FilterCreates a new substring search filter with the provided information.static FilterCreates a new substring search filter with the provided information.voidAppends a number of lines comprising the Java source code that can be used to recreate this filter to the given list.Retrieves a normalized string representation of this search filter.voidtoNormalizedString(StringBuilder buffer) Appends a normalized string representation of this search filter to the provided buffer.toString()Retrieves a string representation of this search filter.voidtoString(StringBuilder buffer) Appends a string representation of this search filter to the provided buffer.voidwriteTo(ASN1Buffer buffer) Writes an ASN.1-encoded representation of this filter to the provided ASN.1 buffer.
-
Field Details
-
FILTER_TYPE_AND
The BER type for AND search filters.- See Also:
-
FILTER_TYPE_OR
The BER type for OR search filters.- See Also:
-
FILTER_TYPE_NOT
The BER type for NOT search filters.- See Also:
-
FILTER_TYPE_EQUALITY
The BER type for equality search filters.- See Also:
-
FILTER_TYPE_SUBSTRING
The BER type for substring search filters.- See Also:
-
FILTER_TYPE_GREATER_OR_EQUAL
The BER type for greaterOrEqual search filters.- See Also:
-
FILTER_TYPE_LESS_OR_EQUAL
The BER type for lessOrEqual search filters.- See Also:
-
FILTER_TYPE_PRESENCE
The BER type for presence search filters.- See Also:
-
FILTER_TYPE_APPROXIMATE_MATCH
The BER type for approximate match search filters.- See Also:
-
FILTER_TYPE_EXTENSIBLE_MATCH
The BER type for extensible match search filters.- See Also:
-
-
Method Details
-
and
Creates a new AND search filter with the provided components.
This method does exactly the same thing ascreateANDFilter(Filter...), but with a shorter method name for convenience.- Parameters:
andComponents- The set of filter components to include in the AND filter. It must not benull.- Returns:
- The created AND search filter.
-
and
Creates a new AND search filter with the provided components.
This method does exactly the same thing ascreateANDFilter(Collection), but with a shorter method name for convenience.- Parameters:
andComponents- The set of filter components to include in the AND filter. It must not benull.- Returns:
- The created AND search filter.
-
createANDFilter
Creates a new AND search filter with the provided components.- Parameters:
andComponents- The set of filter components to include in the AND filter. It must not benull.- Returns:
- The created AND search filter.
-
createANDFilter
Creates a new AND search filter with the provided components.- Parameters:
andComponents- The set of filter components to include in the AND filter. It must not benull.- Returns:
- The created AND search filter.
-
createANDFilter
Creates a new AND search filter with the provided components.- Parameters:
andComponents- The set of filter components to include in the AND filter. It must not benull.- Returns:
- The created AND search filter.
-
or
Creates a new OR search filter with the provided components.
This method does exactly the same thing ascreateORFilter(Filter...), but with a shorter method name for convenience.- Parameters:
orComponents- The set of filter components to include in the OR filter. It must not benull.- Returns:
- The created OR search filter.
-
or
Creates a new OR search filter with the provided components.
This method does exactly the same thing ascreateORFilter(Collection), but with a shorter method name for convenience.- Parameters:
orComponents- The set of filter components to include in the OR filter. It must not benull.- Returns:
- The created OR search filter.
-
createORFilter
Creates a new OR search filter with the provided components.- Parameters:
orComponents- The set of filter components to include in the OR filter. It must not benull.- Returns:
- The created OR search filter.
-
createORFilter
Creates a new OR search filter with the provided components.- Parameters:
orComponents- The set of filter components to include in the OR filter. It must not benull.- Returns:
- The created OR search filter.
-
createORFilter
Creates a new OR search filter with the provided components.- Parameters:
orComponents- The set of filter components to include in the OR filter. It must not benull.- Returns:
- The created OR search filter.
-
not
Creates a new NOT search filter with the provided component.
This method does exactly the same thing ascreateNOTFilter(Filter), but with a shorter method name for convenience.- Parameters:
notComponent- The filter component to include in this NOT filter. It must not benull.- Returns:
- The created NOT search filter.
-
createNOTFilter
Creates a new NOT search filter with the provided component.- Parameters:
notComponent- The filter component to include in this NOT filter. It must not benull.- Returns:
- The created NOT search filter.
-
equals
Creates a new equality search filter with the provided information.
This method does exactly the same thing ascreateEqualityFilter(String,String), but with a shorter method name for convenience.- Parameters:
attributeName- The attribute name for this equality filter. It must not benull.assertionValue- The assertion value for this equality filter. It must not benull.- Returns:
- The created equality search filter.
-
equals
Creates a new equality search filter with the provided information.
This method does exactly the same thing ascreateEqualityFilter(String,byte[]), but with a shorter method name for convenience.- Parameters:
attributeName- The attribute name for this equality filter. It must not benull.assertionValue- The assertion value for this equality filter. It must not benull.- Returns:
- The created equality search filter.
-
createEqualityFilter
@NotNull public static Filter createEqualityFilter(@NotNull String attributeName, @NotNull String assertionValue) Creates a new equality search filter with the provided information.- Parameters:
attributeName- The attribute name for this equality filter. It must not benull.assertionValue- The assertion value for this equality filter. It must not benull.- Returns:
- The created equality search filter.
-
createEqualityFilter
@NotNull public static Filter createEqualityFilter(@NotNull String attributeName, @NotNull byte[] assertionValue) Creates a new equality search filter with the provided information.- Parameters:
attributeName- The attribute name for this equality filter. It must not benull.assertionValue- The assertion value for this equality filter. It must not benull.- Returns:
- The created equality search filter.
-
substring
@NotNull public static Filter substring(@NotNull String attributeName, @Nullable String subInitial, @Nullable String[] subAny, @Nullable String subFinal) Creates a new substring search filter with the provided information. At least one of the subInitial, subAny, and subFinal components must not benull.
This method does exactly the same thing ascreateSubstringFilter(String,String,String[],String), but with a shorter method name for convenience.- Parameters:
attributeName- The attribute name for this substring filter. It must not benull.subInitial- The subInitial component for this substring filter. It may benullif there is no subInitial component, but it must not be empty.subAny- The set of subAny components for this substring filter. It may benullor empty if there are no subAny components.subFinal- The subFinal component for this substring filter. It may benullif there is no subFinal component, but it must not be empty.- Returns:
- The created substring search filter.
-
substring
@NotNull public static Filter substring(@NotNull String attributeName, @Nullable byte[] subInitial, @Nullable byte[][] subAny, @Nullable byte[] subFinal) Creates a new substring search filter with the provided information. At least one of the subInitial, subAny, and subFinal components must not benull.
This method does exactly the same thing ascreateSubstringFilter(String,byte[],byte[][],byte[]), but with a shorter method name for convenience.- Parameters:
attributeName- The attribute name for this substring filter. It must not benull.subInitial- The subInitial component for this substring filter. It may benullif there is no subInitial component, but it must not be empty.subAny- The set of subAny components for this substring filter. It may benullor empty if there are no subAny components.subFinal- The subFinal component for this substring filter. It may benullif there is no subFinal component, but it must not be empty.- Returns:
- The created substring search filter.
-
createSubstringFilter
@NotNull public static Filter createSubstringFilter(@NotNull String attributeName, @Nullable String subInitial, @Nullable String[] subAny, @Nullable String subFinal) Creates a new substring search filter with the provided information. At least one of the subInitial, subAny, and subFinal components must not benull.- Parameters:
attributeName- The attribute name for this substring filter. It must not benull.subInitial- The subInitial component for this substring filter. It may benullif there is no subInitial component, but it must not be empty.subAny- The set of subAny components for this substring filter. It may benullor empty if there are no subAny components.subFinal- The subFinal component for this substring filter. It may benullif there is no subFinal component, but it must not be empty.- Returns:
- The created substring search filter.
-
createSubstringFilter
@NotNull public static Filter createSubstringFilter(@NotNull String attributeName, @Nullable byte[] subInitial, @Nullable byte[][] subAny, @Nullable byte[] subFinal) Creates a new substring search filter with the provided information. At least one of the subInitial, subAny, and subFinal components must not benull.- Parameters:
attributeName- The attribute name for this substring filter. It must not benull.subInitial- The subInitial component for this substring filter. It may benullif there is no subInitial component, but it must not be empty.subAny- The set of subAny components for this substring filter. It may benullor empty if there are no subAny components.subFinal- The subFinal component for this substring filter. It may benullif there is no subFinal component, but it must not be empty.- Returns:
- The created substring search filter.
-
subInitial
Creates a new substring search filter with only a subInitial (starts with) component.
This method does exactly the same thing ascreateSubInitialFilter(String,String), but with a shorter method name for convenience.- Parameters:
attributeName- The attribute name for this substring filter. It must not benull.subInitial- The subInitial component for this substring filter. It must not benullor empty.- Returns:
- The created substring search filter.
-
subInitial
Creates a new substring search filter with only a subInitial (starts with) component.
This method does exactly the same thing ascreateSubInitialFilter(String,byte[]), but with a shorter method name for convenience.- Parameters:
attributeName- The attribute name for this substring filter. It must not benull.subInitial- The subInitial component for this substring filter. It must not benullor empty.- Returns:
- The created substring search filter.
-
createSubInitialFilter
@NotNull public static Filter createSubInitialFilter(@NotNull String attributeName, @NotNull String subInitial) Creates a new substring search filter with only a subInitial (starts with) component.- Parameters:
attributeName- The attribute name for this substring filter. It must not benull.subInitial- The subInitial component for this substring filter. It must not benullor empty.- Returns:
- The created substring search filter.
-
createSubInitialFilter
@NotNull public static Filter createSubInitialFilter(@NotNull String attributeName, @NotNull byte[] subInitial) Creates a new substring search filter with only a subInitial (starts with) component.- Parameters:
attributeName- The attribute name for this substring filter. It must not benull.subInitial- The subInitial component for this substring filter. It must not benullor empty.- Returns:
- The created substring search filter.
-
subAny
Creates a new substring search filter with only a subAny (contains) component.
This method does exactly the same thing ascreateSubAnyFilter(String,String...), but with a shorter method name for convenience.- Parameters:
attributeName- The attribute name for this substring filter. It must not benull.subAny- The subAny values for this substring filter. It must not benullor empty.- Returns:
- The created substring search filter.
-
subAny
Creates a new substring search filter with only a subAny (contains) component.
This method does exactly the same thing ascreateSubAnyFilter(String,byte[][]), but with a shorter method name for convenience.- Parameters:
attributeName- The attribute name for this substring filter. It must not benull.subAny- The subAny values for this substring filter. It must not benullor empty.- Returns:
- The created substring search filter.
-
createSubAnyFilter
@NotNull public static Filter createSubAnyFilter(@NotNull String attributeName, @NotNull String... subAny) Creates a new substring search filter with only a subAny (contains) component.- Parameters:
attributeName- The attribute name for this substring filter. It must not benull.subAny- The subAny values for this substring filter. It must not benullor empty.- Returns:
- The created substring search filter.
-
createSubAnyFilter
@NotNull public static Filter createSubAnyFilter(@NotNull String attributeName, @NotNull byte[]... subAny) Creates a new substring search filter with only a subAny (contains) component.- Parameters:
attributeName- The attribute name for this substring filter. It must not benull.subAny- The subAny values for this substring filter. It must not benullor empty.- Returns:
- The created substring search filter.
-
subFinal
Creates a new substring search filter with only a subFinal (ends with) component.
This method does exactly the same thing ascreateSubFinalFilter(String,String), but with a shorter method name for convenience.- Parameters:
attributeName- The attribute name for this substring filter. It must not benull.subFinal- The subFinal component for this substring filter. It must not benullor empty.- Returns:
- The created substring search filter.
-
subFinal
Creates a new substring search filter with only a subFinal (ends with) component.
This method does exactly the same thing ascreateSubFinalFilter(String,byte[]), but with a shorter method name for convenience.- Parameters:
attributeName- The attribute name for this substring filter. It must not benull.subFinal- The subFinal component for this substring filter. It must not benullor empty.- Returns:
- The created substring search filter.
-
createSubFinalFilter
@NotNull public static Filter createSubFinalFilter(@NotNull String attributeName, @NotNull String subFinal) Creates a new substring search filter with only a subFinal (ends with) component.- Parameters:
attributeName- The attribute name for this substring filter. It must not benull.subFinal- The subFinal component for this substring filter. It must not benullor empty.- Returns:
- The created substring search filter.
-
createSubFinalFilter
@NotNull public static Filter createSubFinalFilter(@NotNull String attributeName, @NotNull byte[] subFinal) Creates a new substring search filter with only a subFinal (ends with) component.- Parameters:
attributeName- The attribute name for this substring filter. It must not benull.subFinal- The subFinal component for this substring filter. It must not benullor empty.- Returns:
- The created substring search filter.
-
greaterOrEqual
@NotNull public static Filter greaterOrEqual(@NotNull String attributeName, @NotNull String assertionValue) Creates a new greater-or-equal search filter with the provided information.
This method does exactly the same thing ascreateGreaterOrEqualFilter(String,String), but with a shorter method name for convenience.- Parameters:
attributeName- The attribute name for this greater-or-equal filter. It must not benull.assertionValue- The assertion value for this greater-or-equal filter. It must not benull.- Returns:
- The created greater-or-equal search filter.
-
greaterOrEqual
@NotNull public static Filter greaterOrEqual(@NotNull String attributeName, @NotNull byte[] assertionValue) Creates a new greater-or-equal search filter with the provided information.
This method does exactly the same thing ascreateGreaterOrEqualFilter(String,byte[]), but with a shorter method name for convenience.- Parameters:
attributeName- The attribute name for this greater-or-equal filter. It must not benull.assertionValue- The assertion value for this greater-or-equal filter. It must not benull.- Returns:
- The created greater-or-equal search filter.
-
createGreaterOrEqualFilter
@NotNull public static Filter createGreaterOrEqualFilter(@NotNull String attributeName, @NotNull String assertionValue) Creates a new greater-or-equal search filter with the provided information.- Parameters:
attributeName- The attribute name for this greater-or-equal filter. It must not benull.assertionValue- The assertion value for this greater-or-equal filter. It must not benull.- Returns:
- The created greater-or-equal search filter.
-
createGreaterOrEqualFilter
@NotNull public static Filter createGreaterOrEqualFilter(@NotNull String attributeName, @NotNull byte[] assertionValue) Creates a new greater-or-equal search filter with the provided information.- Parameters:
attributeName- The attribute name for this greater-or-equal filter. It must not benull.assertionValue- The assertion value for this greater-or-equal filter. It must not benull.- Returns:
- The created greater-or-equal search filter.
-
lessOrEqual
@NotNull public static Filter lessOrEqual(@NotNull String attributeName, @NotNull String assertionValue) Creates a new less-or-equal search filter with the provided information.
This method does exactly the same thing ascreateLessOrEqualFilter(String,String), but with a shorter method name for convenience.- Parameters:
attributeName- The attribute name for this less-or-equal filter. It must not benull.assertionValue- The assertion value for this less-or-equal filter. It must not benull.- Returns:
- The created less-or-equal search filter.
-
lessOrEqual
@NotNull public static Filter lessOrEqual(@NotNull String attributeName, @NotNull byte[] assertionValue) Creates a new less-or-equal search filter with the provided information.
This method does exactly the same thing ascreateLessOrEqualFilter(String,byte[]), but with a shorter method name for convenience.- Parameters:
attributeName- The attribute name for this less-or-equal filter. It must not benull.assertionValue- The assertion value for this less-or-equal filter. It must not benull.- Returns:
- The created less-or-equal search filter.
-
createLessOrEqualFilter
@NotNull public static Filter createLessOrEqualFilter(@NotNull String attributeName, @NotNull String assertionValue) Creates a new less-or-equal search filter with the provided information.- Parameters:
attributeName- The attribute name for this less-or-equal filter. It must not benull.assertionValue- The assertion value for this less-or-equal filter. It must not benull.- Returns:
- The created less-or-equal search filter.
-
createLessOrEqualFilter
@NotNull public static Filter createLessOrEqualFilter(@NotNull String attributeName, @NotNull byte[] assertionValue) Creates a new less-or-equal search filter with the provided information.- Parameters:
attributeName- The attribute name for this less-or-equal filter. It must not benull.assertionValue- The assertion value for this less-or-equal filter. It must not benull.- Returns:
- The created less-or-equal search filter.
-
present
Creates a new presence search filter with the provided information.
This method does exactly the same thing ascreatePresenceFilter(String), but with a shorter method name for convenience.- Parameters:
attributeName- The attribute name for this presence filter. It must not benull.- Returns:
- The created presence search filter.
-
createPresenceFilter
Creates a new presence search filter with the provided information.- Parameters:
attributeName- The attribute name for this presence filter. It must not benull.- Returns:
- The created presence search filter.
-
approximateMatch
@NotNull public static Filter approximateMatch(@NotNull String attributeName, @NotNull String assertionValue) Creates a new approximate match search filter with the provided information.
This method does exactly the same thing ascreateApproximateMatchFilter(String,String), but with a shorter method name for convenience.- Parameters:
attributeName- The attribute name for this approximate match filter. It must not benull.assertionValue- The assertion value for this approximate match filter. It must not benull.- Returns:
- The created approximate match search filter.
-
approximateMatch
@NotNull public static Filter approximateMatch(@NotNull String attributeName, @NotNull byte[] assertionValue) Creates a new approximate match search filter with the provided information.
This method does exactly the same thing ascreateApproximateMatchFilter(String,byte[]), but with a shorter method name for convenience.- Parameters:
attributeName- The attribute name for this approximate match filter. It must not benull.assertionValue- The assertion value for this approximate match filter. It must not benull.- Returns:
- The created approximate match search filter.
-
createApproximateMatchFilter
@NotNull public static Filter createApproximateMatchFilter(@NotNull String attributeName, @NotNull String assertionValue) Creates a new approximate match search filter with the provided information.- Parameters:
attributeName- The attribute name for this approximate match filter. It must not benull.assertionValue- The assertion value for this approximate match filter. It must not benull.- Returns:
- The created approximate match search filter.
-
createApproximateMatchFilter
@NotNull public static Filter createApproximateMatchFilter(@NotNull String attributeName, @NotNull byte[] assertionValue) Creates a new approximate match search filter with the provided information.- Parameters:
attributeName- The attribute name for this approximate match filter. It must not benull.assertionValue- The assertion value for this approximate match filter. It must not benull.- Returns:
- The created approximate match search filter.
-
extensibleMatch
@NotNull public static Filter extensibleMatch(@Nullable String attributeName, @Nullable String matchingRuleID, boolean dnAttributes, @NotNull String assertionValue) Creates a new extensible match search filter with the provided information. At least one of the attribute name and matching rule ID must be specified, and the assertion value must always be present.
This method does exactly the same thing ascreateExtensibleMatchFilter(String,String,boolean,String), but with a shorter method name for convenience.- Parameters:
attributeName- The attribute name for this extensible match filter.matchingRuleID- The matching rule ID for this extensible match filter.dnAttributes- Indicates whether the match should be performed against attributes in the target entry's DN.assertionValue- The assertion value for this extensible match filter. It must not benull.- Returns:
- The created extensible match search filter.
-
extensibleMatch
@NotNull public static Filter extensibleMatch(@Nullable String attributeName, @Nullable String matchingRuleID, boolean dnAttributes, @NotNull byte[] assertionValue) Creates a new extensible match search filter with the provided information. At least one of the attribute name and matching rule ID must be specified, and the assertion value must always be present.
This method does exactly the same thing ascreateExtensibleMatchFilter(String,String,boolean,byte[]), but with a shorter method name for convenience.- Parameters:
attributeName- The attribute name for this extensible match filter.matchingRuleID- The matching rule ID for this extensible match filter.dnAttributes- Indicates whether the match should be performed against attributes in the target entry's DN.assertionValue- The assertion value for this extensible match filter. It must not benull.- Returns:
- The created extensible match search filter.
-
createExtensibleMatchFilter
@NotNull public static Filter createExtensibleMatchFilter(@Nullable String attributeName, @Nullable String matchingRuleID, boolean dnAttributes, @NotNull String assertionValue) Creates a new extensible match search filter with the provided information. At least one of the attribute name and matching rule ID must be specified, and the assertion value must always be present.- Parameters:
attributeName- The attribute name for this extensible match filter.matchingRuleID- The matching rule ID for this extensible match filter.dnAttributes- Indicates whether the match should be performed against attributes in the target entry's DN.assertionValue- The assertion value for this extensible match filter. It must not benull.- Returns:
- The created extensible match search filter.
-
createExtensibleMatchFilter
@NotNull public static Filter createExtensibleMatchFilter(@Nullable String attributeName, @Nullable String matchingRuleID, boolean dnAttributes, @NotNull byte[] assertionValue) Creates a new extensible match search filter with the provided information. At least one of the attribute name and matching rule ID must be specified, and the assertion value must always be present.- Parameters:
attributeName- The attribute name for this extensible match filter.matchingRuleID- The matching rule ID for this extensible match filter.dnAttributes- Indicates whether the match should be performed against attributes in the target entry's DN.assertionValue- The assertion value for this extensible match filter. It must not benull.- Returns:
- The created extensible match search filter.
-
create
Creates a new search filter from the provided string representation.- Parameters:
filterString- The string representation of the filter to create. It must not benull.- Returns:
- The search filter decoded from the provided filter string.
- Throws:
LDAPException- If the provided string cannot be decoded as a valid LDAP search filter.
-
writeTo
Writes an ASN.1-encoded representation of this filter to the provided ASN.1 buffer.- Parameters:
buffer- The ASN.1 buffer to which the encoded representation should be written.
-
encode
Encodes this search filter to an ASN.1 element suitable for inclusion in an LDAP search request protocol op.- Returns:
- An ASN.1 element containing the encoded search filter.
-
readFrom
Reads and decodes a search filter from the provided ASN.1 stream reader.- Parameters:
reader- The ASN.1 stream reader from which to read the filter.- Returns:
- The decoded search filter.
- Throws:
LDAPException- If an error occurs while reading or parsing the search filter.
-
decode
Decodes the provided ASN.1 element as a search filter.- Parameters:
filterElement- The ASN.1 element containing the encoded search filter.- Returns:
- The decoded search filter.
- Throws:
LDAPException- If the provided ASN.1 element cannot be decoded as a search filter.
-
getFilterType
Retrieves the filter type for this filter.- Returns:
- The filter type for this filter.
-
getComponents
Retrieves the set of filter components used in this AND or OR filter. This is not applicable for any other filter type.- Returns:
- The set of filter components used in this AND or OR filter, or an empty array if this is some other type of filter or if there are no components (i.e., as in an LDAP TRUE or LDAP FALSE filter).
-
getNOTComponent
Retrieves the filter component used in this NOT filter. This is not applicable for any other filter type.- Returns:
- The filter component used in this NOT filter, or
nullif this is some other type of filter.
-
getAttributeName
Retrieves the name of the attribute type for this search filter. This is applicable for the following types of filters:- Equality
- Substring
- Greater or Equal
- Less or Equal
- Presence
- Approximate Match
- Extensible Match
- Returns:
- The name of the attribute type for this search filter, or
nullif it is not applicable for this type of filter.
-
getAssertionValue
Retrieves the string representation of the assertion value for this search filter. This is applicable for the following types of filters:- Equality
- Greater or Equal
- Less or Equal
- Approximate Match
- Extensible Match
- Returns:
- The string representation of the assertion value for this search
filter, or
nullif it is not applicable for this type of filter.
-
getAssertionValueBytes
Retrieves the binary representation of the assertion value for this search filter. This is applicable for the following types of filters:- Equality
- Greater or Equal
- Less or Equal
- Approximate Match
- Extensible Match
- Returns:
- The binary representation of the assertion value for this search
filter, or
nullif it is not applicable for this type of filter.
-
getRawAssertionValue
Retrieves the raw assertion value for this search filter as an ASN.1 octet string. This is applicable for the following types of filters:- Equality
- Greater or Equal
- Less or Equal
- Approximate Match
- Extensible Match
- Returns:
- The raw assertion value for this search filter as an ASN.1 octet
string, or
nullif it is not applicable for this type of filter.
-
getSubInitialString
Retrieves the string representation of the subInitial element for this substring filter. This is not applicable for any other filter type.- Returns:
- The string representation of the subInitial element for this
substring filter, or
nullif this is some other type of filter, or if it is a substring filter with no subInitial element.
-
getSubInitialBytes
Retrieves the binary representation of the subInitial element for this substring filter. This is not applicable for any other filter type.- Returns:
- The binary representation of the subInitial element for this
substring filter, or
nullif this is some other type of filter, or if it is a substring filter with no subInitial element.
-
getRawSubInitialValue
Retrieves the raw subInitial element for this filter as an ASN.1 octet string. This is not applicable for any other filter type.- Returns:
- The raw subInitial element for this filter as an ASN.1 octet
string, or
nullif this is not a substring filter, or if it is a substring filter with no subInitial element.
-
getSubAnyStrings
Retrieves the string representations of the subAny elements for this substring filter. This is not applicable for any other filter type.- Returns:
- The string representations of the subAny elements for this substring filter, or an empty array if this is some other type of filter, or if it is a substring filter with no subFinal element.
-
getSubAnyBytes
Retrieves the binary representations of the subAny elements for this substring filter. This is not applicable for any other filter type.- Returns:
- The binary representations of the subAny elements for this substring filter, or an empty array if this is some other type of filter, or if it is a substring filter with no subFinal element.
-
getRawSubAnyValues
Retrieves the raw subAny values for this substring filter. This is not applicable for any other filter type.- Returns:
- The raw subAny values for this substring filter, or an empty array if this is some other type of filter, or if it is a substring filter with no subFinal element.
-
getSubFinalString
Retrieves the string representation of the subFinal element for this substring filter. This is not applicable for any other filter type.- Returns:
- The string representation of the subFinal element for this
substring filter, or
nullif this is some other type of filter, or if it is a substring filter with no subFinal element.
-
getSubFinalBytes
Retrieves the binary representation of the subFinal element for this substring filter. This is not applicable for any other filter type.- Returns:
- The binary representation of the subFinal element for this
substring filter, or
nullif this is some other type of filter, or if it is a substring filter with no subFinal element.
-
getRawSubFinalValue
Retrieves the raw subFinal element for this filter as an ASN.1 octet string. This is not applicable for any other filter type.- Returns:
- The raw subFinal element for this filter as an ASN.1 octet
string, or
nullif this is not a substring filter, or if it is a substring filter with no subFinal element.
-
getMatchingRuleID
Retrieves the matching rule ID for this extensible match filter. This is not applicable for any other filter type.- Returns:
- The matching rule ID for this extensible match filter, or
nullif this is some other type of filter, or if this extensible match filter does not have a matching rule ID.
-
getDNAttributes
Retrieves the dnAttributes flag for this extensible match filter. This is not applicable for any other filter type.- Returns:
- The dnAttributes flag for this extensible match filter.
-
matchesEntry
Indicates whether this filter matches the provided entry. Note that this is a best-guess effort and may not be completely accurate in all cases. All matching will be performed using case-ignore string matching, which may yield an unexpected result for values that should not be treated as simple strings. For example:- Two DN values which are logically equivalent may not be considered matches if they have different spacing.
- Ordering comparisons against numeric values may yield unexpected results (e.g., "2" will be considered greater than "10" because the character "2" has a larger ASCII value than the character "1").
In addition to the above constraints, it should be noted that neither approximate matching nor extensible matching are currently supported.- Parameters:
entry- The entry for which to make the determination. It must not benull.- Returns:
trueif this filter appears to match the provided entry, orfalseif not.- Throws:
LDAPException- If a problem occurs while trying to make the determination.
-
matchesEntry
Indicates whether this filter matches the provided entry. Note that this is a best-guess effort and may not be completely accurate in all cases. If provided, the given schema will be used in an attempt to determine the appropriate matching rule for making the determinations, but some corner cases may not be handled accurately. Neither approximate matching nor extensible matching are currently supported.- Parameters:
entry- The entry for which to make the determination. It must not benull.schema- The schema to use when making the determination. If this isnull, then all matching will be performed using a case-ignore matching rule.- Returns:
trueif this filter appears to match the provided entry, orfalseif not.- Throws:
LDAPException- If a problem occurs while trying to make the determination.
-
simplifyFilter
Attempts to simplify the provided filter to allow it to be more efficiently processed by the server. The simplifications it will make include:- Any AND or OR filter that contains only a single filter component will be converted to just that embedded filter component to eliminate the unnecessary AND or OR wrapper. For example, the filter "(&(uid=john.doe))" will be converted to just "(uid=john.doe)".
- Any AND components inside of an AND filter will be merged into the outer AND filter. Any OR components inside of an OR filter will be merged into the outer OR filter. For example, the filter "(&(objectClass=person)(&(givenName=John)(sn=Doe)))" will be converted to "(&(objectClass=person)(givenName=John)(sn=Doe))".
- Any AND filter that contains an LDAP false filter will be converted to just an LDAP false filter.
- Any OR filter that contains an LDAP true filter will be converted to just an LDAP true filter.
- If
reOrderElementsis true, then this method will attempt to re-order the elements inside AND and OR filters in an attempt to ensure that the components which are likely to be the most efficient come earlier than those which are likely to be the least efficient. This can speed up processing in servers that process filter components in a left-to-right order.
The simplification will happen recursively, in an attempt to generate a filter that is as simple and efficient as possible.- Parameters:
filter- The filter to attempt to simplify.reOrderElements- Indicates whether this method may re-order the elements in the filter so that, in a server that evaluates the components in a left-to-right order, the components which are likely to be more efficient to process will be listed before those which are likely to be less efficient.- Returns:
- The simplified filter, or the original filter if the provided filter is not one that can be simplified any further.
-
hashCode
Generates a hash code for this search filter. -
equals
Indicates whether the provided object is equal to this search filter. -
toString
Retrieves a string representation of this search filter. -
toString
Appends a string representation of this search filter to the provided buffer.- Parameters:
buffer- The buffer to which to append a string representation of this search filter.
-
toNormalizedString
Retrieves a normalized string representation of this search filter.- Returns:
- A normalized string representation of this search filter.
-
toNormalizedString
Appends a normalized string representation of this search filter to the provided buffer.- Parameters:
buffer- The buffer to which to append a normalized string representation of this search filter.
-
encodeValue
Encodes the provided value into a form suitable for use as the assertion value in the string representation of a search filter. Parentheses, asterisks, backslashes, null characters, and any non-ASCII characters will be escaped using a backslash before the hexadecimal representation of each byte in the character to escape.- Parameters:
value- The value to be encoded. It must not benull.- Returns:
- The encoded representation of the provided string.
-
createSubstringAssertion
@NotNull public static String createSubstringAssertion(@Nullable String subInitial, @Nullable String[] subAny, @Nullable String subFinal) Creates the string representation of a substring assertion with the provided components.- Parameters:
subInitial- The subInitial component for this substring filter. It may benullif there is no subInitial component, but it must not be empty.subAny- The set of subAny components for this substring filter. It may benullor empty if there are no subAny components.subFinal- The subFinal component for this substring filter. It may benullif there is no subFinal component, but it must not be empty.- Returns:
- The string representation of a substring assertion with the provided components.
-
createSubstringAssertion
@NotNull public static String createSubstringAssertion(@Nullable byte[] subInitial, @Nullable byte[][] subAny, @Nullable byte[] subFinal) Creates the string representation of a substring assertion with the provided components.- Parameters:
subInitial- The subInitial component for this substring filter. It may benullif there is no subInitial component, but it must not be empty.subAny- The set of subAny components for this substring filter. It may benullor empty if there are no subAny components.subFinal- The subFinal component for this substring filter. It may benullif there is no subFinal component, but it must not be empty.- Returns:
- The string representation of a substring assertion with the provided components.
-
encodeValue
Encodes the provided value into a form suitable for use as the assertion value in the string representation of a search filter. Parentheses, asterisks, backslashes, null characters, and any non-ASCII characters will be escaped using a backslash before the hexadecimal representation of each byte in the character to escape.- Parameters:
value- The value to be encoded. It must not benull.- Returns:
- The encoded representation of the provided string.
-
encodeValue
Appends the assertion value for this filter to the provided buffer, encoding any special characters as necessary.- Parameters:
value- The value to be encoded.buffer- The buffer to which the assertion value should be appended.
-
toCode
public void toCode(@NotNull List<String> lineList, int indentSpaces, @Nullable String firstLinePrefix, @Nullable String lastLineSuffix) Appends a number of lines comprising the Java source code that can be used to recreate this filter to the given list. Note that unless a first line prefix and/or last line suffix are provided, this will just include the code for the static method used to create the filter, starting with "Filter.createXFilter(" and ending with the closing parenthesis for that method call.- Parameters:
lineList- The list to which the source code lines should be added.indentSpaces- The number of spaces that should be used to indent the generated code. It must not be negative.firstLinePrefix- An optional string that should precede the static method call (e.g., it could be used for an attribute assignment, like "Filter f = "). It may benullor empty if there should be no first line prefix.lastLineSuffix- An optional suffix that should follow the closing parenthesis of the static method call (e.g., it could be a semicolon to represent the end of a Java statement). It may benullor empty if there should be no last line suffix.
-