smolnar82 commented on code in PR #1236:
URL: https://github.com/apache/knox/pull/1236#discussion_r3339674111


##########
gateway-server/src/main/java/org/apache/knox/gateway/services/ldap/backend/LdapProxyBackend.java:
##########
@@ -301,55 +307,148 @@ public List<String> getUserGroups(String username) 
throws Exception {
         LdapConnection connection = null;
         try {
             connection = getConnection();
-            if (useMemberOf) {
-                // Use memberOf attribute for efficient AD lookups
-                return getUserGroupsViaMemberOf(connection, username);
-            } else {
-                // Use traditional group search approach
-                String filter = userSearchFilter.replace("{username}", 
username);
-                EntryCursor cursor = connection.search(userSearchBase, filter, 
SearchScope.SUBTREE, "dn");
+            List<Entry> groups = getUserGroupsEntries(connection, username);
+            return getCnsFromEntries(groups);
+        } finally {
+            releaseConnection(connection);
+        }
+    }
 
+    private List<Entry> getUserGroupsEntries(LdapConnection connection, String 
username) throws Exception {
+        List<Entry> groups;
+        if (useMemberOf) {
+            // Use memberOf attribute for efficient AD lookups
+            groups = getUserGroupsViaMemberOfInternal(connection, username);
+        } else {
+            // Use traditional group search approach
+            String filter = userSearchFilter.replace("{username}", username);
+            try (EntryCursor cursor = connection.search(userSearchBase, 
filter, SearchScope.SUBTREE, "dn")) {
                 if (cursor.next()) {
                     String userDn = cursor.get().getDn().toString();
-                    cursor.close();
-                    return getCnsFromEntries(getUserGroupsInternal(connection, 
userDn, username));
+                    groups = getUserGroupsInternal(connection, userDn, 
username);
+                } else {
+                    groups = Collections.emptyList();
                 }
-
-                cursor.close();
             }
-            return Collections.emptyList();
-        } finally {
-            releaseConnection(connection);
         }
+
+        if (recursiveGroupResolution && !groups.isEmpty()) {
+            groups = resolveGroupsRecursive(connection, groups, username);
+        }
+        return groups;
     }
 
-    private List<String> getUserGroupsViaMemberOf(LdapConnection connection, 
String username) throws LdapException, CursorException, IOException {
-        List<String> groups = new ArrayList<>();
+    private List<Entry> getUserGroupsViaMemberOfInternal(LdapConnection 
connection, String username) throws LdapException, CursorException, IOException 
{

Review Comment:
   That a good observation, I made a change to fix this.



-- 
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