Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nested ldap queries #811

Merged
merged 43 commits into from
Mar 15, 2023
Merged
Show file tree
Hide file tree
Changes from 42 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
3066fe1
Fixed undefined behavior in Any::operator==(value)
carneyweb Jan 9, 2023
c8866bc
Revert "Fixed undefined behavior in Any::operator==(value)"
carneyweb Jan 9, 2023
6db4dbb
Merge branch 'development' of https://github.com/CppMicroServices/Cpp…
carneyweb Jan 26, 2023
72d905a
Merge branch 'development' of https://github.com/CppMicroServices/Cpp…
carneyweb Feb 6, 2023
44207d0
New algorithm for matching nested values
carneyweb Feb 6, 2023
d114627
remove commented out include files.
carneyweb Feb 6, 2023
9b1917c
removed some comment out lines.
carneyweb Feb 6, 2023
c491c01
removed some unneeded debug output
carneyweb Feb 6, 2023
b393b05
Added some fixes to resolve test failures
achristoforides Feb 6, 2023
7834923
More speed ups to string splitting
achristoforides Feb 6, 2023
f5432d5
checkpoint.
carneyweb Feb 7, 2023
b206276
modified the string_split algorithm.
carneyweb Feb 7, 2023
c23864d
more code cleanup for readability
carneyweb Feb 7, 2023
e73ae46
More code cleanup.
carneyweb Feb 7, 2023
a7b974b
more cleanup.
carneyweb Feb 8, 2023
b8538df
remove unnecessary kruft from manifest
carneyweb Feb 9, 2023
8faba6a
Added a test case
carneyweb Feb 9, 2023
5af8363
responding to code review feedback.
carneyweb Feb 10, 2023
7002cb5
update comment for LDAPFilter to better describe algorithm.
carneyweb Feb 15, 2023
8aa8a9c
Updated some comments.
carneyweb Feb 15, 2023
dc7a904
Merge branch 'development' of https://github.com/CppMicroServices/Cpp…
carneyweb Feb 15, 2023
efe7b45
New algorithm for matching nested values
carneyweb Feb 6, 2023
81fdcb0
remove commented out include files.
carneyweb Feb 6, 2023
e1a9c31
removed some comment out lines.
carneyweb Feb 6, 2023
2767e40
removed some unneeded debug output
carneyweb Feb 6, 2023
054cf09
Added some fixes to resolve test failures
achristoforides Feb 6, 2023
af8c849
More speed ups to string splitting
achristoforides Feb 6, 2023
2a4205f
checkpoint.
carneyweb Feb 7, 2023
b18b26b
modified the string_split algorithm.
carneyweb Feb 7, 2023
a97fd15
more code cleanup for readability
carneyweb Feb 7, 2023
b7633c8
More code cleanup.
carneyweb Feb 7, 2023
4d4d4e7
more cleanup.
carneyweb Feb 8, 2023
3c027d2
remove unnecessary kruft from manifest
carneyweb Feb 9, 2023
7e751b3
Added a test case
carneyweb Feb 9, 2023
773bdb2
responding to code review feedback.
carneyweb Feb 10, 2023
4ce6ad2
update comment for LDAPFilter to better describe algorithm.
carneyweb Feb 15, 2023
422e175
Updated some comments.
carneyweb Feb 15, 2023
dfafbce
Merge branch 'nested_ldap_queries' of https://github.com/CppMicroServ…
carneyweb Feb 15, 2023
76fd1eb
Added more details to the description of the new algorithm.
carneyweb Feb 15, 2023
6dcc117
disable support for nested filtering
carneyweb Mar 8, 2023
b3c47b7
Merge branch 'development' of https://github.com/CppMicroServices/Cpp…
carneyweb Mar 8, 2023
97cb79e
Merge branch 'development' into nested_ldap_queries
carneyweb Mar 8, 2023
4a6b786
Added comment describing enabling nested ldap queries.
carneyweb Mar 13, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions framework/include/cppmicroservices/LDAPFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,24 +61,24 @@ namespace cppmicroservices
* - "(o=univ*of*mich*)"
*
* LDAPFilters have been extended to make it easier to query nested JSON keys. Keys which
* contain the "." character may refer to nested values. We first look at the top level for a
* matching entry, and if one isn't found, we decompose the nested key and "walk down" the JSON
* structure looking for a match.
* contain the "." character may refer to nested values. The top level is checked first for a
jeffdiclemente marked this conversation as resolved.
Show resolved Hide resolved
* matching entry. If one isn't found, the key is decomposed and the JSON structure "walked down"
* to look for a match.
*
* Keys are decomposed into individual segments using the "." character as a segment
* separator. For example, given a key "a.b.c.d", if a value exists in the top level map with
* that key, we return it. if a value is not found at the top level with that key, we decompose
* that key 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, we first look at the top
* level map for a submap at key "a". If a value rather than a map is found there, there is no
* path to "d", so we stop with an unsuccessful lookup. If a map does exist, we look in that map
* for a key of "b" and continue from there with the same algorithm (looking at that submap for
* keys "b", "b.c", and "b.c.d"). If not, we then look for a submap at the top level at key
* "a.b". Again, if a value is found rather than a map, there is no path to "d" so we halt the
* 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 algorithem. If a map is found there, we finally
* look for a value at "d" in that map.
* "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:
*
Expand All @@ -92,7 +92,7 @@ namespace cppmicroservices
*
* \remarks This class is thread safe.
*
* \sa Use LDAPProp API to conveniently generate LDAP filter strings
* \sa Use LDAPProp class to conveniently generate LDAP filter strings
*
*/
class US_Framework_EXPORT LDAPFilter
Expand Down
7 changes: 6 additions & 1 deletion framework/src/util/LDAPExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ namespace cppmicroservices
{
namespace
{
#ifdef SUPPORT_NESTED_LOOKUP
/**
* @brief split a delimited string into a vector of values
*
Expand Down Expand Up @@ -104,6 +105,7 @@ namespace cppmicroservices

return result;
}
#endif

/**
* @brief Find value for attrName in map
Expand Down Expand Up @@ -135,7 +137,9 @@ namespace cppmicroservices
{
return lookup;
}

#ifndef SUPPORT_NESTED_LOOKUP
return std::nullopt;
#else
// If not found at the full attrname, decompose the path and do a full check.
// First, split the m_attrName into a vector at the . separator and reverse it.
auto scope = string_split(attrName, ".");
Expand Down Expand Up @@ -203,6 +207,7 @@ namespace cppmicroservices
// return an empty object... we did not find a named attrName in the map.
return std::nullopt;
}
#endif
}
} // namespace

Expand Down
2 changes: 2 additions & 0 deletions framework/test/gtest/LDAPQueryTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ TEST_F(LDAPQueryTest, TestLDAPFilterMatchServiceReferenceBase)
ASSERT_TRUE(ldapMatchCase.Match(sr));
}

#ifdef SUPPORT_NESTED_LOOKUP
TEST_F(LDAPQueryTest, TestNestedData)
{
LDAPFilter filter1(LDAPProp("a.b.c.d") == 5);
Expand Down Expand Up @@ -193,3 +194,4 @@ TEST_F(LDAPQueryTest, TestNestedData)
ASSERT_TRUE(filter11.Match(omTestMap));
ASSERT_FALSE(filter11.MatchCase(omTestMap));
}
#endif