necouchman commented on a change in pull request #345: GUACAMOLE-234: Migrate 
to Apache Directory API for LDAP Extension
URL: https://github.com/apache/guacamole-client/pull/345#discussion_r251181940
 
 

 ##########
 File path: 
extensions/guacamole-auth-ldap/src/main/java/org/apache/guacamole/auth/ldap/ObjectQueryService.java
 ##########
 @@ -188,46 +183,50 @@ public String generateQuery(String filter,
      *     information required to execute the query cannot be read from
      *     guacamole.properties.
      */
-    public List<LDAPEntry> search(LDAPConnection ldapConnection,
-            String baseDN, String query) throws GuacamoleException {
+    public List<Entry> search(LdapConnection ldapConnection,
+            Dn baseDN, ExprNode query) throws GuacamoleException {
 
         logger.debug("Searching \"{}\" for objects matching \"{}\".", baseDN, 
query);
 
         try {
 
+            LdapConnectionConfig ldapConnectionConfig =
+                    ((LdapNetworkConnection) ldapConnection).getConfig();
+            
             // Search within subtree of given base DN
-            LDAPSearchResults results = ldapConnection.search(baseDN,
-                    LDAPConnection.SCOPE_SUB, query, null, false,
-                    confService.getLDAPSearchConstraints());
+            SearchRequest request = ldapService.getSearchRequest(baseDN,
+                    query);
+            
+            SearchCursor results = ldapConnection.search(request);
 
             // Produce list of all entries in the search result, automatically
             // following referrals if configured to do so
-            List<LDAPEntry> entries = new ArrayList<>(results.getCount());
-            while (results.hasMore()) {
+            List<Entry> entries = new ArrayList<>();
+            while (results.next()) {
 
-                try {
-                    entries.add(results.next());
+                Response response = results.get();
+                if (response instanceof SearchResultEntry) {
+                    entries.add(((SearchResultEntry) response).getEntry());
                 }
-
-                // Warn if referrals cannot be followed
-                catch (LDAPReferralException e) {
-                    if (confService.getFollowReferrals()) {
-                        logger.error("Could not follow referral: {}", 
e.getFailedReferral());
-                        logger.debug("Error encountered trying to follow 
referral.", e);
-                        throw new GuacamoleServerException("Could not follow 
LDAP referral.", e);
-                    }
-                    else {
-                        logger.warn("Given a referral, but referrals are 
disabled. Error was: {}", e.getMessage());
-                        logger.debug("Got a referral, but configured to not 
follow them.", e);
+                else if (response instanceof SearchResultReference &&
+                        request.isFollowReferrals()) {
+                    
+                    Referral referral = ((SearchResultReference) 
response).getReferral();
+                    int referralHop = 0;
+                    for (String url : referral.getLdapUrls()) {
+                        LdapConnection referralConnection = 
ldapService.referralConnection(
+                            new LdapUrl(url), ldapConnectionConfig, 
referralHop++);
+                        entries.addAll(search(referralConnection, baseDN, 
query));
 
 Review comment:
   ping @mike-jumper 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to