You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2011/01/19 23:42:04 UTC

svn commit: r1061041 - in /directory: apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/ apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/interceptor/context/ apacheds/trunk/core-api/src/test/java/org/apache/d...

Author: elecharny
Date: Wed Jan 19 22:42:03 2011
New Revision: 1061041

URL: http://svn.apache.org/viewvc?rev=1061041&view=rev
Log:
o The lookup() methods in CoreSession and in LdapConnection now takes Controls as a parameter
o Added some tests for lookup with controls

Modified:
    directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/CoreSession.java
    directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/LdapCoreSessionConnection.java
    directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/interceptor/context/SearchingOperationContext.java
    directory/apacheds/trunk/core-api/src/test/java/org/apache/directory/server/core/MockCoreSession.java
    directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/subtree/SubentryServiceIT.java
    directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/DefaultCoreSession.java
    directory/shared/trunk/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/LdapConnection.java
    directory/shared/trunk/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/LdapNetworkConnection.java

Modified: directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/CoreSession.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/CoreSession.java?rev=1061041&r1=1061040&r2=1061041&view=diff
==============================================================================
--- directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/CoreSession.java (original)
+++ directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/CoreSession.java Wed Jan 19 22:42:03 2011
@@ -363,15 +363,28 @@ public interface CoreSession
      */
     Entry lookup( DN dn ) throws LdapException;
 
+    
+    /**
+     * Looks up an entry in the server returning all attributes: both user and
+     * operational attributes.
+     *
+     * @param dn the name of the entry to lookup
+     * @param atIds The list of attributes to return
+     * @throws Exception if there are failures while looking up the entry
+     */
+    Entry lookup( DN dn, String... atIds ) throws LdapException;
+
+    
     /**
      * Looks up an entry in the server returning all attributes: both user and
      * operational attributes.
      *
      * @param dn the name of the entry to lookup
+     * @param controls the Controls to use 
      * @param atIds The list of attributes to return
      * @throws Exception if there are failures while looking up the entry
      */
-    Entry lookup( DN dn, String[] atIds ) throws LdapException;
+    Entry lookup( DN dn, Control[] controls, String... atIds ) throws LdapException;
 
     
     /**

Modified: directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/LdapCoreSessionConnection.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/LdapCoreSessionConnection.java?rev=1061041&r1=1061040&r2=1061041&view=diff
==============================================================================
--- directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/LdapCoreSessionConnection.java (original)
+++ directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/LdapCoreSessionConnection.java Wed Jan 19 22:42:03 2011
@@ -452,7 +452,34 @@ public class LdapCoreSessionConnection i
      */
     public Entry lookup( DN dn, String... attributes ) throws LdapException
     {
-        return _lookup( dn, attributes );
+        return _lookup( dn, null, attributes );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public Entry lookup( DN dn, Control[] controls, String... attributes ) throws LdapException
+    {
+        return _lookup( dn, controls, attributes );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public Entry lookup( String dn, String... attributes ) throws LdapException
+    {
+        return _lookup( new DN( dn ), null, attributes );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public Entry lookup( String dn, Control[] controls, String... attributes ) throws LdapException
+    {
+        return _lookup( new DN( dn ), controls, attributes );
     }
 
 
@@ -460,7 +487,7 @@ public class LdapCoreSessionConnection i
      * this method exists solely for the purpose of calling from
      * lookup(DN dn) avoiding the varargs,
      */
-    private Entry _lookup( DN dn, String... attributes )
+    private Entry _lookup( DN dn, Control[] controls, String... attributes )
     {
         messageId.incrementAndGet();
 
@@ -468,14 +495,7 @@ public class LdapCoreSessionConnection i
 
         try
         {
-            if ( attributes == null )
-            {
-                entry = session.lookup( dn );
-            }
-            else
-            {
-                entry = session.lookup( dn, attributes );
-            }
+            entry = session.lookup( dn, controls, attributes );
         }
         catch ( LdapException e )
         {
@@ -489,15 +509,6 @@ public class LdapCoreSessionConnection i
     /**
      * {@inheritDoc}
      */
-    public Entry lookup( String dn, String... attributes ) throws LdapException
-    {
-        return _lookup( new DN( dn ), attributes );
-    }
-
-
-    /**
-     * {@inheritDoc}
-     */
     public boolean exists( String dn ) throws LdapException
     {
         return exists( new DN( dn ) );
@@ -532,7 +543,7 @@ public class LdapCoreSessionConnection i
      */
     public Entry lookup( DN dn ) throws LdapException
     {
-        return _lookup( dn );
+        return _lookup( dn, null );
     }
 
 
@@ -541,7 +552,7 @@ public class LdapCoreSessionConnection i
      */
     public Entry lookup( String dn ) throws LdapException
     {
-        return _lookup( new DN( dn ) );
+        return _lookup( new DN( dn ), null );
     }
 
 

Modified: directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/interceptor/context/SearchingOperationContext.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/interceptor/context/SearchingOperationContext.java?rev=1061041&r1=1061040&r2=1061041&view=diff
==============================================================================
--- directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/interceptor/context/SearchingOperationContext.java (original)
+++ directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/interceptor/context/SearchingOperationContext.java Wed Jan 19 22:42:03 2011
@@ -127,7 +127,7 @@ public abstract class SearchingOperation
     }
     
     
-    protected void setReturningAttributes( String[] attributesIds ) throws LdapException
+    public void setReturningAttributes( String[] attributesIds ) throws LdapException
     {
         if ( attributesIds != null && attributesIds.length != 0 )
         {

Modified: directory/apacheds/trunk/core-api/src/test/java/org/apache/directory/server/core/MockCoreSession.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-api/src/test/java/org/apache/directory/server/core/MockCoreSession.java?rev=1061041&r1=1061040&r2=1061041&view=diff
==============================================================================
--- directory/apacheds/trunk/core-api/src/test/java/org/apache/directory/server/core/MockCoreSession.java (original)
+++ directory/apacheds/trunk/core-api/src/test/java/org/apache/directory/server/core/MockCoreSession.java Wed Jan 19 22:42:03 2011
@@ -480,10 +480,23 @@ public class MockCoreSession implements 
     /**
      * {@inheritDoc}
      */
-    public Entry lookup( DN dn, String[] attrId ) throws LdapException
+    public Entry lookup( DN dn, String... attrIds ) throws LdapException
     {
         OperationManager operationManager = directoryService.getOperationManager();
-        return operationManager.lookup( new LookupOperationContext( this, dn, attrId ) );
+        return operationManager.lookup( new LookupOperationContext( this, dn, attrIds ) );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public Entry lookup( DN dn, Control[] controls, String... attrIds ) throws LdapException
+    {
+        OperationManager operationManager = directoryService.getOperationManager();
+        LookupOperationContext lookupContext = new LookupOperationContext( this, dn, attrIds );
+        lookupContext.addRequestControls( controls );
+        
+        return operationManager.lookup( lookupContext );
     }
 
 

Modified: directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/subtree/SubentryServiceIT.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/subtree/SubentryServiceIT.java?rev=1061041&r1=1061040&r2=1061041&view=diff
==============================================================================
--- directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/subtree/SubentryServiceIT.java (original)
+++ directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/subtree/SubentryServiceIT.java Wed Jan 19 22:42:03 2011
@@ -51,6 +51,7 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.cursor.Cursor;
 import org.apache.directory.shared.ldap.entry.Entry;
 import org.apache.directory.shared.ldap.entry.EntryAttribute;
+import org.apache.directory.shared.ldap.exception.LdapException;
 import org.apache.directory.shared.ldap.filter.SearchScope;
 import org.apache.directory.shared.ldap.ldif.LdifUtils;
 import org.apache.directory.shared.ldap.message.AddResponse;
@@ -171,6 +172,25 @@ public class SubentryServiceIT extends A
     // The shared LDAP user connection
     protected static LdapConnection userConnection;
 
+    private class JndiSubentriesControl implements javax.naming.ldap.Control
+    {
+
+        public boolean isCritical()
+        {
+            return false;
+        }
+
+        public byte[] getEncodedValue()
+        {
+            return new byte[]{0x01, 0x01, (byte)0xFF};
+        }
+
+        public String getID()
+        {
+            return "1.3.6.1.4.1.4203.1.10.1";
+        }
+    }
+
 
     public Attributes getTestEntry( String cn )
     {
@@ -226,6 +246,20 @@ public class SubentryServiceIT extends A
     }
 
 
+    public Entry getTestSubentryWithExclusion( String dn ) throws LdapException
+    {
+        Entry subentry = LdifUtils.createEntry( new DN( dn ),
+            "objectClass: top",
+            "objectClass: subentry",
+            "objectClass: collectiveAttributeSubentry",
+            "subtreeSpecification: { base \"ou=configuration\", specificExclusions { chopBefore:\"cn=unmarked\" } }",
+            "c-o: Test Org",
+            "cn: testsubentry" );
+        
+        return subentry;
+    }
+
+
     private void addAdministrativeRole( String role ) throws Exception
     {
         LdapContext sysRoot = getSystemContext( service );
@@ -1295,31 +1329,12 @@ public class SubentryServiceIT extends A
     @Test
     public void testSubtreeScopeSearchSubentryVisibilityWithTheSubentriesControl() throws Exception
     {
-        class SubentriesControl implements javax.naming.ldap.Control
-        {
-
-            public boolean isCritical()
-            {
-                return false;
-            }
-
-            public byte[] getEncodedValue()
-            {
-                return new byte[]{0x01, 0x01, (byte)0xFF};
-            }
-
-            public String getID()
-            {
-                return "1.3.6.1.4.1.4203.1.10.1";
-            }
-        }
-        
         LdapContext sysRoot = getSystemContext( service );
         addAdministrativeRole( "collectiveAttributeSpecificArea" );
         sysRoot.createSubcontext( "cn=testsubentry", getTestSubentryWithExclusion() );
         SearchControls searchControls = new SearchControls();
         searchControls.setSearchScope( SearchControls.SUBTREE_SCOPE );
-        sysRoot.setRequestControls( new javax.naming.ldap.Control[]{ new SubentriesControl() } );
+        sysRoot.setRequestControls( new javax.naming.ldap.Control[]{ new JndiSubentriesControl() } );
         Map<String, SearchResult> entries = new HashMap<String, SearchResult>();
         NamingEnumeration<SearchResult> list = sysRoot.search( "cn=testsubentry", "(objectClass=subentry)",
             searchControls );
@@ -1336,6 +1351,54 @@ public class SubentryServiceIT extends A
 
 
     @Test
+    public void testLookupSubentryWithTheSubentriesControl() throws Exception
+    {
+        LdapContext sysRoot = getSystemContext( service );
+        addAdministrativeRole( "collectiveAttributeSpecificArea" );
+        sysRoot.createSubcontext( "cn=testsubentry", getTestSubentryWithExclusion() );
+        
+        sysRoot.setRequestControls( new javax.naming.ldap.Control[]{ new JndiSubentriesControl() } );
+        Attributes attributes = sysRoot.getAttributes( "cn=testsubentry", new String[]{"subtreeSpecification"} );
+
+        assertNotNull( attributes );
+        Attribute ss = attributes.get( "SubtreeSpecification" );
+        assertNotNull( ss );
+    }
+
+
+    @Test
+    public void testLookupSubentryAPIWithTheSubentriesControl() throws Exception
+    {
+        LdapConnection connection = IntegrationUtils.getAdminConnection( service );
+
+        addAdministrativeRole( "collectiveAttributeSpecificArea" );
+        connection.add( getTestSubentryWithExclusion( "cn=testsubentry,ou=system" ) );
+        
+        Entry result = connection.lookup( "cn=testsubentry,ou=system", new Control[]{ new SubentriesControl()},"subtreeSpecification" );
+
+        assertNotNull( result );
+        String ss = result.get( "SubtreeSpecification" ).getString();
+        assertNotNull( ss );
+    }
+
+
+    @Test
+    public void testLookupSubentryAPIWithoutTheSubentriesControl() throws Exception
+    {
+        LdapConnection connection = IntegrationUtils.getAdminConnection( service );
+
+        addAdministrativeRole( "collectiveAttributeSpecificArea" );
+        connection.add( getTestSubentryWithExclusion( "cn=testsubentry,ou=system" ) );
+        
+        Entry result = connection.lookup( "cn=testsubentry,ou=system", "subtreeSpecification" );
+
+        assertNotNull( result );
+        String ss = result.get( "SubtreeSpecification" ).getString();
+        assertNotNull( ss );
+    }
+
+
+    @Test
     public void testUserInjectAccessControlSubentries() throws Exception
     {
         userConnection = IntegrationUtils.getConnectionAs( service, "cn=testUser,ou=system", "test" );

Modified: directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/DefaultCoreSession.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/DefaultCoreSession.java?rev=1061041&r1=1061040&r2=1061041&view=diff
==============================================================================
--- directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/DefaultCoreSession.java (original)
+++ directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/DefaultCoreSession.java Wed Jan 19 22:42:03 2011
@@ -488,10 +488,29 @@ public class DefaultCoreSession implemen
     /**
      * {@inheritDoc}
      */
-    public Entry lookup( DN dn, String[] attrId ) throws LdapException
+    public Entry lookup( DN dn, String... attrIds ) throws LdapException
     {
         OperationManager operationManager = directoryService.getOperationManager();
-        LookupOperationContext lookupContext = new LookupOperationContext( this, dn, attrId );
+        LookupOperationContext lookupContext = new LookupOperationContext( this, dn, attrIds );
+
+        Entry entry = operationManager.lookup( lookupContext );
+
+        return entry;
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public Entry lookup( DN dn, Control[] controls, String... attrIds ) throws LdapException
+    {
+        OperationManager operationManager = directoryService.getOperationManager();
+        LookupOperationContext lookupContext = new LookupOperationContext( this, dn, attrIds );
+        
+        if ( controls != null )
+        {
+            lookupContext.addRequestControls( controls );
+        }
 
         Entry entry = operationManager.lookup( lookupContext );
 

Modified: directory/shared/trunk/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/LdapConnection.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/LdapConnection.java?rev=1061041&r1=1061040&r2=1061041&view=diff
==============================================================================
--- directory/shared/trunk/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/LdapConnection.java (original)
+++ directory/shared/trunk/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/LdapConnection.java Wed Jan 19 22:42:03 2011
@@ -47,6 +47,7 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.message.ModifyRequest;
 import org.apache.directory.shared.ldap.message.ModifyResponse;
 import org.apache.directory.shared.ldap.message.SearchRequest;
+import org.apache.directory.shared.ldap.message.control.Control;
 import org.apache.directory.shared.ldap.name.DN;
 import org.apache.directory.shared.ldap.name.RDN;
 import org.apache.directory.shared.ldap.schema.SchemaManager;
@@ -673,6 +674,19 @@ public interface LdapConnection
      * Searches for an entry having the given DN.
      *
      * @param dn the DN of the entry to be fetched
+     * @param controls the controls to use
+     * @param attributes the attributes to be returned along with entry
+     * @return the Entry with the given DN or null if no entry exists with that DN
+     * @throws LdapException in case of any problems while searching for the DN or if the returned response contains a referral
+     */
+    Entry lookup( DN dn, Control[] controls, String... attributes ) throws LdapException;
+
+
+
+    /**
+     * Searches for an entry having the given DN.
+     *
+     * @param dn the DN of the entry to be fetched
      * @param attributes the attributes to be returned along with entry
      * @return the Entry with the given DN or null if no entry exists with that DN
      * @throws LdapException in case of any problems while searching for the DN or if the returned response contains a referral
@@ -682,6 +696,19 @@ public interface LdapConnection
 
 
     /**
+     * Searches for an entry having the given DN.
+     *
+     * @param dn the DN of the entry to be fetched
+     * @param controls the controls to use
+     * @param attributes the attributes to be returned along with entry
+     * @return the Entry with the given DN or null if no entry exists with that DN
+     * @throws LdapException in case of any problems while searching for the DN or if the returned response contains a referral
+     * @see #lookup(DN, String...)
+     */
+    Entry lookup( String dn, Control[] controls, String... attributes ) throws LdapException;
+
+
+    /**
      * Checks if a control with the given OID is supported.
      *
      * @param controlOID the OID of the control

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=1061041&r1=1061040&r2=1061041&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 Wed Jan 19 22:42:03 2011
@@ -3048,11 +3048,33 @@ public class LdapNetworkConnection exten
      */
     public Entry lookup( DN dn, String... attributes ) throws LdapException
     {
+        return lookup( dn, null, attributes );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public Entry lookup( DN dn, Control[] controls, String... attributes ) throws LdapException
+    {
         Entry entry = null;
 
         try
         {
-            Cursor<Response> cursor = search( dn, "(objectClass=*)", SearchScope.OBJECT, attributes );
+            SearchRequest searchRequest = new SearchRequestImpl();
+
+            searchRequest.setBase( dn );
+            searchRequest.setFilter( "(objectClass=*)" );
+            searchRequest.setScope( SearchScope.OBJECT );
+            searchRequest.addAttributes( attributes );
+            searchRequest.setDerefAliases( AliasDerefMode.DEREF_ALWAYS );
+            
+            if ( ( controls != null ) && ( controls.length > 0 ) )
+            {
+                searchRequest.addAllControls( controls );
+            }
+
+            Cursor<Response> cursor = search( searchRequest );
 
             // Read the response
             if ( cursor.next() )
@@ -3082,7 +3104,16 @@ public class LdapNetworkConnection exten
      */
     public Entry lookup( String dn, String... attributes ) throws LdapException
     {
-        return lookup( new DN( dn ), attributes );
+        return lookup( new DN( dn ), null, attributes );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public Entry lookup( String dn, Control[] controls, String... attributes ) throws LdapException
+    {
+        return lookup( new DN( dn ), controls, attributes );
     }