directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1136242 - /directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/SearchHandler.java
Date Wed, 15 Jun 2011 23:07:04 GMT
Author: elecharny
Date: Wed Jun 15 23:07:04 2011
New Revision: 1136242

URL: http://svn.apache.org/viewvc?rev=1136242&view=rev
Log:
Prepared the loop on aliases in the doSimpleSearch method.

Modified:
    directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/SearchHandler.java

Modified: directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/SearchHandler.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/SearchHandler.java?rev=1136242&r1=1136241&r2=1136242&view=diff
==============================================================================
--- directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/SearchHandler.java
(original)
+++ directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/SearchHandler.java
Wed Jun 15 23:07:04 2011
@@ -24,6 +24,8 @@ import static java.lang.Math.min;
 import static org.apache.directory.server.ldap.LdapServer.NO_SIZE_LIMIT;
 import static org.apache.directory.server.ldap.LdapServer.NO_TIME_LIMIT;
 
+import java.util.ArrayList;
+import java.util.List;
 import java.util.concurrent.TimeUnit;
 
 import org.apache.commons.lang.exception.ExceptionUtils;
@@ -358,10 +360,11 @@ public class SearchHandler extends LdapR
     }
 
 
-    private void readResults( LdapSession session, SearchRequest req, LdapResult ldapResult,
+    private List<Dn> readResults( LdapSession session, SearchRequest req, LdapResult
ldapResult,
         EntryFilteringCursor cursor, long sizeLimit ) throws Exception
     {
         long count = 0;
+        List<Dn> aliasList = new ArrayList<Dn>();
 
         while ( ( count < sizeLimit ) && cursor.next() )
         {
@@ -380,7 +383,14 @@ public class SearchHandler extends LdapR
                 break;
             }
 
-            ClonedServerEntry entry = cursor.get();
+            Entry entry = cursor.get();
+            
+            // Here, we have to check if the candidate is an alias or not
+            if ( entry.contains( OBJECT_CLASS_AT, SchemaConstants.ALIAS_OC ) )
+            {
+                aliasList.add( entry.getDn() );
+            }
+            
             session.getIoSession().write( generateResponse( session, req, entry ) );
             LOG.debug( "Sending {}", entry.getDn() );
             count++;
@@ -398,6 +408,8 @@ public class SearchHandler extends LdapR
             // Special case if the user has requested more elements than the request size
limit
             ldapResult.setResultCode( ResultCodeEnum.SIZE_LIMIT_EXCEEDED );
         }
+        
+        return aliasList;
     }
 
 
@@ -768,44 +780,65 @@ public class SearchHandler extends LdapR
         }
 
         // A normal search
-        // Check that we have a cursor or not.
-        // No cursor : do a search.
-        EntryFilteringCursor cursor = session.getCoreSession().search( req );
-
-        // Position the cursor at the beginning
-        cursor.beforeFirst();
-
-        /*
-         * Iterate through all search results building and sending back responses
-         * for each search result returned.
-         */
-        try
+        // We have to process all the found aliases
+        List<Dn> searchDnList = new ArrayList<Dn>();
+        searchDnList.add( req.getBase() );
+        
+        int currentSearch = 0;
+        
+        while ( currentSearch < searchDnList.size() )
         {
-            // Get the size limits
-            // Don't bother setting size limits for administrators that don't ask for it
-            long serverLimit = getServerSizeLimit( session, req );
-
-            long requestLimit = req.getSizeLimit() == 0L ? Long.MAX_VALUE : req.getSizeLimit();
-
-            req.addAbandonListener( new SearchAbandonListener( ldapServer, cursor ) );
-            setTimeLimitsOnCursor( req, session, cursor );
-            LOG.debug( "using <{},{}> for size limit", requestLimit, serverLimit );
-            long sizeLimit = min( requestLimit, serverLimit );
+            if ( req.getBase() == null )
+            {
+                req.setBase( searchDnList.get( currentSearch ) );
+            }
+    
+            EntryFilteringCursor cursor = session.getCoreSession().search( req );
 
-            readResults( session, req, ldapResult, cursor, sizeLimit );
-        }
-        finally
-        {
-            if ( cursor != null )
+            // Position the cursor at the beginning
+            cursor.beforeFirst();
+    
+            /*
+             * Iterate through all search results building and sending back responses
+             * for each search result returned.
+             */
+            try
             {
-                try
+                // Get the size limits
+                // Don't bother setting size limits for administrators that don't ask for
it
+                long serverLimit = getServerSizeLimit( session, req );
+    
+                long requestLimit = req.getSizeLimit() == 0L ? Long.MAX_VALUE : req.getSizeLimit();
+    
+                req.addAbandonListener( new SearchAbandonListener( ldapServer, cursor ) );
+                setTimeLimitsOnCursor( req, session, cursor );
+                LOG.debug( "using <{},{}> for size limit", requestLimit, serverLimit
);
+                long sizeLimit = min( requestLimit, serverLimit );
+    
+                List<Dn> aliasList = readResults( session, req, ldapResult, cursor,
sizeLimit );
+                
+                currentSearch++;
+                
+                if ( aliasList.size() != 0 )
                 {
-                    cursor.close();
+                    searchDnList.addAll( aliasList );
                 }
-                catch ( Exception e )
+            }
+            finally
+            {
+                if ( cursor != null )
                 {
-                    LOG.error( I18n.err( I18n.ERR_168 ), e );
+                    try
+                    {
+                        cursor.close();
+                    }
+                    catch ( Exception e )
+                    {
+                        LOG.error( I18n.err( I18n.ERR_168 ), e );
+                    }
                 }
+                
+                req.setBase( null );
             }
         }
 
@@ -1171,7 +1204,6 @@ public class SearchHandler extends LdapR
             // if the entry is null we still have to check for a referral ancestor
             // also the referrals need to be adjusted based on the ancestor's ref
             // values to yield the correct path to the entry in the target DSAs
-
             else
             {
                 // The entry is null : it has a parent referral.



Mime
View raw message