handavid commented on code in PR #1522:
URL: https://github.com/apache/knox/pull/1522#discussion_r4621611317


##########
gateway-server/src/main/java/org/apache/knox/gateway/services/ldap/interceptor/LDAPRolesLookupInterceptor.java:
##########
@@ -277,18 +296,125 @@ private EntryFilteringCursor 
handleSearch(SearchOperationContext ctx) throws Lda
             
ctx.setReturningAttributes(withAttributes(originalReturningAttributes, 
augmentedAttributes));
         }
 
+        int numUserAndGroupEntries = 0;
         final List<Entry> entries = new ArrayList<>();
         try (EntryFilteringCursor cursor = next(ctx)) {
             while (cursor.next()) {
+                Entry entry = cursor.get();
+                if (LdapUtils.isUserEntry(entry) || 
LdapUtils.isGroupEntry(entry)) {
+                    numUserAndGroupEntries++;
+                }
                 entries.add(cursor.get());
             }
         } catch (Exception e) {
             LOG.ldapRolesLookupFailed(LdapUtils.extractGroupName(ctx.getDn()), 
e);
             throw new LdapException(e);
         }
 
+        // Populating the roles through lookup results in one lookup request 
per entry.
+        // It is more efficient to list all the roles when the number of 
entries is large.
+        final List<Entry> resultEntries = numUserAndGroupEntries > numRoles ?

Review Comment:
   I initialized `numRoles` to -1 and treat this as "unknown". However, I added 
a single `listRoles` request during interceptor initialization since this would 
otherwise require an all-groups search to set `numRoles`.
   I make `FileBasedLdapRolesReverseLookup` null-safe and updated the unit 
tests.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to