LDAPFilter¶
-
std::ostream &operator<<(std::ostream &os, LDAPFilter const &filter)¶
Streams the string representation of
filterinto the streamosvia LDAPFilter::ToString().
-
LDAPPropExpr operator==(std::string const &s) const¶
-
LDAPPropExpr operator==(bool b) const¶
-
LDAPPropExpr operator!=(std::string const &s) const¶
-
LDAPPropExpr operator>=(std::string const &s) const¶
-
LDAPPropExpr operator<=(std::string const &s) const¶
-
LDAPPropExpr Approx(std::string const &s) const¶
-
cppmicroservices::LDAPPropExpr operator&&(cppmicroservices::LDAPPropExpr const &left, cppmicroservices::LDAPPropExpr const &right)¶
LDAP logical and ‘&’.
- Parameters:
left – A LDAP expression.
right – A LDAP expression.
- Returns:
A LDAP expression
-
cppmicroservices::LDAPPropExpr operator||(cppmicroservices::LDAPPropExpr const &left, cppmicroservices::LDAPPropExpr const &right)¶
LDAP logical or ‘|’.
- Parameters:
left – A LDAP expression.
right – A LDAP expression.
- Returns:
A LDAP expression
-
class LDAPFilter¶
- #include <cppmicroservices/LDAPFilter.h>
An RFC 1960-based Filter.
A
LDAPFiltercan be used numerous times to determine if the match argument matches the filter string that was used to create theLDAPFilter.Some examples of LDAP filters are:
“(cn=Babs Jensen)”
”(!(cn=Tim Howes))”
”(&(” + Constants::OBJECTCLASS + “=Person)(|(sn=Jensen)(cn=Babs J*)))”
”(o=univ*of*mich*)”
LDAPFilters have been extended to make it easier to query nested JSON keys. This is disabled by default. To enable this functionality, define SUPPORT_NESTED_LOOKUP at compile time. For example, if using “make” to build:
make clean make SUPPORT_NESTED_LOOKUP=1
Nested Lookup Description¶
Keys which contain the “.” character may refer to nested values. The top level is checked first for a matching entry. If one isn’t found, the key is decomposed and the JSON structure “walked down” to look for a match.
For example, given a key “a.b.c.d”, if a value exists in the top level map with that key, it’s retuned. If a value is not found at the top level with that key, it’s decomposed into a vector: [“a”,”b”,”c”,”d”]. Ultimately for the filter to be applied, there must be a value in a nested AnyMap with a key ending with “d”. So, the top level map is checked for the key “a”. If a value rather than a map is found there, there is no path to “d”, so the algorithm stops with an unsuccessful lookup. If a map does exist, the algorithm continues and looks for a key of “b” in that map and continues from there with the same algorithm (looking at that submap for keys “b”, “b.c”, and “b.c.d”). Finally, if nothing has been found for key “a”, the algorithm combines the first two keys together into “a.b” and looks for a submap. Again, if a value is found rather than a map, there is no path to “d” so we halt the lookup. If a submap is found there, we then look in that map for a key of “c” and continue from there. Finally, if there is no item in the to plevel map at “a.b”, we look at “a.b.c”. And again, a value there halts the algorithm. If a map is found there, it’s checked for a value at key “d”.
A real world example:
“(“bundle.symbolic_name=my_bundle)”. This will look for a match in two places. First it
will look in the JSON manifest for:
{ “bundle.symbolic_name” : “my_bundle” }
If not found there, this will be checked:
{ “bundle” : { “symbolic_name” : “my_bundle” } }
top level flat keys are preferred in order to preserve the behavior of existing filters.
Remark
This class is thread safe.
See also
Use LDAPProp class to conveniently generate LDAP filter strings
Public Functions
-
LDAPFilter()¶
Creates a valid
LDAPFilterobject that matches nothing.
-
LDAPFilter(std::string const &filter)¶
Creates a
LDAPFilterobject encapsulating the filter string.This
LDAPFilterobject may be used to match aServiceReferenceobject or aServicePropertiesobject.If the filter cannot be parsed, an std::invalid_argument will be thrown with a human readable message where the filter became unparsable.
See also
“Framework specification for a description of the filter string syntax.” TODO!
- Parameters:
filter – The filter string.
- Throws:
std::invalid_argument – If
filtercontains an invalid filter string that cannot be parsed.
-
LDAPFilter(LDAPFilter const &other)¶
-
~LDAPFilter()¶
-
explicit operator bool() const¶
-
bool Match(ServiceReferenceBase const &reference) const¶
Filter using a service’s properties.
This
LDAPFilteris executed using the keys and values of the referenced service’s properties. The keys are looked up in a case insensitive manner.- Parameters:
reference – The reference to the service whose properties are used in the match.
- Returns:
trueif the service’s properties match thisLDAPFilterfalseotherwise.
-
bool Match(Bundle const &bundle) const¶
Filter using a bundle’s manifest headers.
This
LDAPFilteris executed using the keys and values of the bundle’s manifest headers. The keys are looked up in a case insensitive manner.- Parameters:
bundle – The bundle whose manifest’s headers are used in the match.
- Throws:
std::runtime_error – If the number of keys of the bundle’s manifest headers exceeds the value returned by std::numeric_limits<int>::max().
- Returns:
trueif the bundle’s manifest headers match thisLDAPFilterfalseotherwise.
-
bool Match(AnyMap const &dictionary) const¶
Filter using a
AnyMapobject with case insensitive key lookup.This
LDAPFilteris executed using the specifiedAnyMap’s keys and values. The keys are looked up in a case insensitive manner.- Parameters:
dictionary – The
AnyMapwhose key/value pairs are used in the match.- Throws:
std::runtime_error – If the number of keys in the
dictionaryexceeds the value returned by std::numeric_limits<int>::max().std::runtime_error – If the
dictionarycontains case variants of the same key name.
- Returns:
trueif theAnyMap’s values match this filter;falseotherwise.
-
bool MatchCase(AnyMap const &dictionary) const¶
Filter using a
AnyMap.This
LDAPFilteris executed using the specifiedAnyMap’s keys and values. The keys are looked up in a normal manner respecting case.- Parameters:
dictionary – The
AnyMapwhose key/value pairs are used in the match.- Throws:
std::runtime_error – If the number of keys in the
dictionaryexceeds the value returned by std::numeric_limits<int>::max().std::runtime_error – If the
dictionarycontains case variants of the same key name.
- Returns:
trueif theAnyMap’s values match this filter;falseotherwise.
-
std::string ToString() const¶
Returns this
LDAPFilter’s filter string.The filter string is normalized by removing whitespace which does not affect the meaning of the filter.
- Returns:
This
LDAPFilter’s filter string.
-
bool operator==(LDAPFilter const &other) const¶
Compares this
LDAPFilterto anotherLDAPFilter.This implementation returns the result of calling
this->ToString() == other.ToString().- Parameters:
other – The object to compare against this
LDAPFilter.- Returns:
Returns the result of calling
this->ToString() == other.ToString().
-
LDAPFilter &operator=(LDAPFilter const &filter)¶
Protected Attributes
-
std::shared_ptr<LDAPFilterData> d¶
-
class LDAPProp¶
- #include <cppmicroservices/LDAPProp.h>
A fluent API for creating LDAP filter strings.
Examples for creating LDAPFilter objects:
// This creates the filter "(&(name=Ben)(!(count=1)))" LDAPFilter filter(LDAPProp("name") == "Ben" && !(LDAPProp("count") == 1)); // This creates the filter "(|(presence=*)(!(absence=*)))" LDAPFilter filter(LDAPProp("presence") || !LDAPProp("absence")); // This creates the filter "(&(ge>=-3)(approx~=hi))" LDAPFilter filter(LDAPProp("ge") >= -3 && LDAPProp("approx").Approx("hi"));See also