directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1588274 - in /directory: apacheds/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/operations/search/ shared/trunk/dsml/parser/src/main/java/org/apache/directory/api/dsmlv2/request/ shared/trunk/ldap/client/api/s...
Date Thu, 17 Apr 2014 15:07:07 GMT
Author: elecharny
Date: Thu Apr 17 15:07:06 2014
New Revision: 1588274

URL: http://svn.apache.org/r1588274
Log:
o Added support for Referral ignore in the API
o Added some enum to support the referrals Following soon

Added:
    directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/message/ReferralsPolicyEnum.java
Modified:
    directory/apacheds/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/operations/search/SearchWithReferralsTest.java
    directory/shared/trunk/dsml/parser/src/main/java/org/apache/directory/api/dsmlv2/request/SearchRequestDsml.java
    directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/LdapNetworkConnection.java
    directory/shared/trunk/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/decorators/SearchRequestDecorator.java
    directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/message/SearchRequest.java
    directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/message/SearchRequestImpl.java

Modified: directory/apacheds/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/operations/search/SearchWithReferralsTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/operations/search/SearchWithReferralsTest.java?rev=1588274&r1=1588273&r2=1588274&view=diff
==============================================================================
--- directory/apacheds/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/operations/search/SearchWithReferralsTest.java
(original)
+++ directory/apacheds/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/operations/search/SearchWithReferralsTest.java
Thu Apr 17 15:07:06 2014
@@ -31,11 +31,15 @@ import java.util.List;
 
 import org.apache.directory.api.ldap.model.cursor.CursorLdapReferralException;
 import org.apache.directory.api.ldap.model.cursor.EntryCursor;
+import org.apache.directory.api.ldap.model.cursor.SearchCursor;
 import org.apache.directory.api.ldap.model.entry.DefaultEntry;
 import org.apache.directory.api.ldap.model.entry.Entry;
 import org.apache.directory.api.ldap.model.ldif.LdifEntry;
 import org.apache.directory.api.ldap.model.ldif.LdifReader;
+import org.apache.directory.api.ldap.model.message.SearchRequest;
+import org.apache.directory.api.ldap.model.message.SearchRequestImpl;
 import org.apache.directory.api.ldap.model.message.SearchScope;
+import org.apache.directory.api.ldap.model.name.Dn;
 import org.apache.directory.ldap.client.api.LdapNetworkConnection;
 import org.apache.directory.server.annotations.CreateLdapServer;
 import org.apache.directory.server.annotations.CreateTransport;
@@ -112,91 +116,129 @@ import org.junit.runner.RunWith;
 })
 public class SearchWithReferralsTest extends AbstractLdapTestUnit
 {
-private LdapNetworkConnection connection;
-
-
-@Before
-public void setupReferrals() throws Exception
-{
-    String ldif =
-        "dn: c=europ,ou=Countries,ou=system\n" +
-            "objectClass: top\n" +
-            "objectClass: referral\n" +
-            "objectClass: extensibleObject\n" +
-            "c: europ\n" +
-            "ref: ldap://localhost:52489/c=france,ou=system\n\n" +
-
-            "dn: c=america,ou=Countries,ou=system\n" +
-            "objectClass: top\n" +
-            "objectClass: referral\n" +
-            "objectClass: extensibleObject\n" +
-            "c: america\n" +
-            "ref: ldap://localhost:52489/c=usa,ou=system\n\n";
-
-    LdifReader reader = new LdifReader( new StringReader( ldif ) );
-
-    while ( reader.hasNext() )
+    private LdapNetworkConnection connection;
+    
+    
+    @Before
+    public void setupReferrals() throws Exception
     {
-        LdifEntry entry = reader.next();
-        getLdapServer().getDirectoryService().getAdminSession().add(
-            new DefaultEntry( getLdapServer().getDirectoryService().getSchemaManager(), entry.getEntry()
) );
-    }
-
-    reader.close();
-
-    connection = ( LdapNetworkConnection ) LdapApiIntegrationUtils.getPooledAdminConnection(
getLdapServer() );
-}
-
-
-@After
-public void shutdown() throws Exception
-{
-    LdapApiIntegrationUtils.releasePooledAdminConnection( connection, getLdapServer() );
-}
-
-
-/**
- * Test of an search operation with a referral
- *
- * search for "cn=alex karasulu" on "c=america, ou=system"
- * we should get a referral URL thrown, which point to
- * "c=usa, ou=system", and ask for a subtree search
- */
-@Test
-public void testSearchWithReferralThrow() throws Exception
-{
-    EntryCursor cursor = connection.search( "ou=Countries,ou=system", "(objectClass=*)",
-        SearchScope.SUBTREE, "*", "+" );
-    int count = 0;
-    Entry entry = null;
-    List<String> refs = new ArrayList<String>();
-
-    while ( cursor.next() )
-    {
-        try
+        String ldif =
+            "dn: c=europ,ou=Countries,ou=system\n" +
+                "objectClass: top\n" +
+                "objectClass: referral\n" +
+                "objectClass: extensibleObject\n" +
+                "c: europ\n" +
+                "ref: ldap://localhost:52489/c=france,ou=system\n\n" +
+    
+                "dn: c=america,ou=Countries,ou=system\n" +
+                "objectClass: top\n" +
+                "objectClass: referral\n" +
+                "objectClass: extensibleObject\n" +
+                "c: america\n" +
+                "ref: ldap://localhost:52489/c=usa,ou=system\n\n";
+    
+        LdifReader reader = new LdifReader( new StringReader( ldif ) );
+    
+        while ( reader.hasNext() )
         {
-            entry = cursor.get();
-
-            assertNotNull( entry );
-            count++;
+            LdifEntry entry = reader.next();
+            getLdapServer().getDirectoryService().getAdminSession().add(
+                new DefaultEntry( getLdapServer().getDirectoryService().getSchemaManager(),
entry.getEntry() ) );
         }
-        catch ( CursorLdapReferralException clre )
+    
+        reader.close();
+    
+        connection = ( LdapNetworkConnection ) LdapApiIntegrationUtils.getPooledAdminConnection(
getLdapServer() );
+    }
+    
+    
+    @After
+    public void shutdown() throws Exception
+    {
+        LdapApiIntegrationUtils.releasePooledAdminConnection( connection, getLdapServer()
);
+    }
+    
+    
+    /**
+     * Test of an search operation with a referral
+     *
+     * search for "cn=alex karasulu" on "c=america, ou=system"
+     * we should get a referral URL thrown, which point to
+     * "c=usa, ou=system", and ask for a subtree search
+     */
+    @Test
+    public void testSearchWithReferralThrow() throws Exception
+    {
+        EntryCursor cursor = connection.search( "ou=Countries,ou=system", "(objectClass=*)",
+            SearchScope.SUBTREE, "*", "+" );
+        int count = 0;
+        Entry entry = null;
+        List<String> refs = new ArrayList<String>();
+    
+        while ( cursor.next() )
         {
-            count++;
-
-            do
+            try
             {
-                String ref = clre.getReferralInfo();
-                refs.add( ref );
+                entry = cursor.get();
+    
+                assertNotNull( entry );
+                count++;
+            }
+            catch ( CursorLdapReferralException clre )
+            {
+                count++;
+    
+                do
+                {
+                    String ref = clre.getReferralInfo();
+                    refs.add( ref );
+                }
+                while ( clre.skipReferral() );
             }
-            while ( clre.skipReferral() );
         }
+    
+        assertEquals( 3, count );
+        assertEquals( 2, refs.size() );
+        assertTrue( refs.contains( "ldap://localhost:52489/c=usa,ou=system??sub" ) );
+        assertTrue( refs.contains( "ldap://localhost:52489/c=france,ou=system??sub" ) );
+        cursor.close();
     }
+    
+    
+    /**
+     * Test of an search operation with a referral and a follow
+     *
+     * search for "cn=alex karasulu" on "c=america, ou=system"
+     * we should get a referral URL thrown, which point to
+     * "c=usa, ou=system", and ask for a subtree search
+     */
+    @Test
+    public void testSearchWithReferralAsIs() throws Exception
+    {
+        // We will ask the referal to be returned as is
+        SearchRequest searchRequest = new SearchRequestImpl();
+        searchRequest.setBase( new Dn( "ou=Countries,ou=system" ) );
+        searchRequest.setFilter( "(objectClass=*)" );
+        searchRequest.setScope( SearchScope.SUBTREE );
+        searchRequest.addAttributes( "*", "+" );
+        
+        searchRequest.ignoreReferrals();
+        
+        SearchCursor cursor = connection.search( searchRequest );
+        int count = 0;
+        Entry entry = null;
+        List<String> refs = new ArrayList<String>();
+    
+        while ( cursor.next() )
+        {
+            entry = cursor.getEntry();
 
-    assertEquals( 3, count );
-    assertEquals( 2, refs.size() );
-    assertTrue( refs.contains( "ldap://localhost:52489/c=usa,ou=system??sub" ) );
-    assertTrue( refs.contains( "ldap://localhost:52489/c=france,ou=system??sub" ) );
-    cursor.close();
-}
+            assertNotNull( entry );
+            count++;
+        }
+    
+        assertEquals( 3, count );
+        assertEquals( 0, refs.size() );
+        cursor.close();
+    }
 }

Modified: directory/shared/trunk/dsml/parser/src/main/java/org/apache/directory/api/dsmlv2/request/SearchRequestDsml.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/dsml/parser/src/main/java/org/apache/directory/api/dsmlv2/request/SearchRequestDsml.java?rev=1588274&r1=1588273&r2=1588274&view=diff
==============================================================================
--- directory/shared/trunk/dsml/parser/src/main/java/org/apache/directory/api/dsmlv2/request/SearchRequestDsml.java
(original)
+++ directory/shared/trunk/dsml/parser/src/main/java/org/apache/directory/api/dsmlv2/request/SearchRequestDsml.java
Thu Apr 17 15:07:06 2014
@@ -824,4 +824,40 @@ public class SearchRequestDsml
     {
         return ( SearchRequest ) super.removeControl( control );
     }
+    
+    
+    /**
+     * {@inheritDoc}
+     */
+    public boolean isFollowReferrals()
+    {
+        return getDecorated().isFollowReferrals();
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public SearchRequest followReferrals()
+    {
+        return getDecorated().followReferrals();
+    }
+    
+    
+    /**
+     * {@inheritDoc}
+     */
+    public boolean isIgnoreReferrals()
+    {
+        return getDecorated().isIgnoreReferrals();
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public SearchRequest ignoreReferrals()
+    {
+        return getDecorated().ignoreReferrals();
+    }
 }

Modified: directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/LdapNetworkConnection.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/LdapNetworkConnection.java?rev=1588274&r1=1588273&r2=1588274&view=diff
==============================================================================
--- directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/LdapNetworkConnection.java
(original)
+++ directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/LdapNetworkConnection.java
Thu Apr 17 15:07:06 2014
@@ -117,6 +117,7 @@ import org.apache.directory.api.ldap.mod
 import org.apache.directory.api.ldap.model.message.SearchScope;
 import org.apache.directory.api.ldap.model.message.UnbindRequest;
 import org.apache.directory.api.ldap.model.message.UnbindRequestImpl;
+import org.apache.directory.api.ldap.model.message.controls.ManageDsaITImpl;
 import org.apache.directory.api.ldap.model.message.controls.OpaqueControl;
 import org.apache.directory.api.ldap.model.message.extended.AddNoDResponse;
 import org.apache.directory.api.ldap.model.message.extended.BindNoDResponse;
@@ -1667,6 +1668,12 @@ public class LdapNetworkConnection exten
 
         int newId = messageId.incrementAndGet();
         searchRequest.setMessageId( newId );
+        
+        if ( searchRequest.isIgnoreReferrals() )
+        {
+            // We want to ignore the referral, inject the ManageDSAIT control in the request
+            searchRequest.addControl( new ManageDsaITImpl() );
+        }
 
         LOG.debug( "Sending request \n{}", searchRequest );
 

Modified: directory/shared/trunk/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/decorators/SearchRequestDecorator.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/decorators/SearchRequestDecorator.java?rev=1588274&r1=1588273&r2=1588274&view=diff
==============================================================================
--- directory/shared/trunk/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/decorators/SearchRequestDecorator.java
(original)
+++ directory/shared/trunk/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/decorators/SearchRequestDecorator.java
Thu Apr 17 15:07:06 2014
@@ -1127,4 +1127,40 @@ public class SearchRequestDecorator exte
     {
         return ( SearchRequest ) super.removeControl( control );
     }
+    
+    
+    /**
+     * {@inheritDoc}
+     */
+    public boolean isFollowReferrals()
+    {
+        return getDecorated().isFollowReferrals();
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public SearchRequest followReferrals()
+    {
+        return getDecorated().followReferrals();
+    }
+    
+    
+    /**
+     * {@inheritDoc}
+     */
+    public boolean isIgnoreReferrals()
+    {
+        return getDecorated().isIgnoreReferrals();
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public SearchRequest ignoreReferrals()
+    {
+        return getDecorated().ignoreReferrals();
+    }
 }

Added: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/message/ReferralsPolicyEnum.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/message/ReferralsPolicyEnum.java?rev=1588274&view=auto
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/message/ReferralsPolicyEnum.java
(added)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/message/ReferralsPolicyEnum.java
Thu Apr 17 15:07:06 2014
@@ -0,0 +1,36 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ * 
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ * 
+ */
+package org.apache.directory.api.ldap.model.message;
+
+/**
+ * An enum describing the three possible actions for referrals :
+ * <ul>
+ * <li>Ignore : The referrals will be retruned as is (ie, the 'ref' attribute type
will be present in the entry</li>
+ * <li>Follow : The referral will be chased by the client</li>
+ * <li>Throws : An LdapReferralException will be thrown</li>
+ * </ul>
+ * @author <a href="mailto:dev@directory.apache.org"> Apache Directory Project</a>
+ */
+public enum ReferralsPolicyEnum
+{
+    IGNORE,
+    FOLLOW,
+    THROW
+}

Modified: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/message/SearchRequest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/message/SearchRequest.java?rev=1588274&r1=1588273&r2=1588274&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/message/SearchRequest.java
(original)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/message/SearchRequest.java
Thu Apr 17 15:07:06 2014
@@ -270,4 +270,34 @@ public interface SearchRequest extends M
      * {@inheritDoc}
      */
     SearchRequest removeControl( Control control );
+    
+    
+    /**
+     * Tells the client if it should follow referrals instead of throwing exceptions
+     * @return true if we should follow the referrals
+     */
+    boolean isFollowReferrals();
+    
+    
+    /**
+     * Tells the client to follow referrals instead of throwing exceptions
+     * @return The SearchRequest instance
+     */
+    SearchRequest followReferrals();
+    
+    
+    /**
+     * Tells the client if it should ignore referrals instead of throwing exceptions
+     * @return true if we should ignore the referrals
+     */
+    boolean isIgnoreReferrals();
+    
+    
+    /**
+     * Tells the client to ignore referrals instead of throwing exceptions. The entry
+     * will contain the referral attributeType with the link.
+     * 
+     * @return The SearchRequest instance
+     */
+    SearchRequest ignoreReferrals();
 }

Modified: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/message/SearchRequestImpl.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/message/SearchRequestImpl.java?rev=1588274&r1=1588273&r2=1588274&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/message/SearchRequestImpl.java
(original)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/message/SearchRequestImpl.java
Thu Apr 17 15:07:06 2014
@@ -70,6 +70,9 @@ public class SearchRequestImpl extends A
 
     /** The final result containing SearchResponseDone response */
     private SearchResultDone response;
+    
+    /** A flag set to tell the search what to do wth referrals */
+    private ReferralsPolicyEnum referralHandling = ReferralsPolicyEnum.THROW;
 
 
     // -----------------------------------------------------------------------
@@ -588,4 +591,44 @@ public class SearchRequestImpl extends A
 
         return super.toString( sb.toString() );
     }
+    
+    
+    /**
+     * {@inheritDoc}
+     */
+    public boolean isFollowReferrals()
+    {
+        return referralHandling == ReferralsPolicyEnum.FOLLOW;
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public SearchRequest followReferrals()
+    {
+        referralHandling = ReferralsPolicyEnum.FOLLOW;
+        
+        return this;
+    }
+    
+    
+    /**
+     * {@inheritDoc}
+     */
+    public boolean isIgnoreReferrals()
+    {
+        return referralHandling == ReferralsPolicyEnum.IGNORE;
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public SearchRequest ignoreReferrals()
+    {
+        referralHandling = ReferralsPolicyEnum.IGNORE;
+        
+        return this;
+    }
 }
\ No newline at end of file



Mime
View raw message