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 2010/09/06 19:28:19 UTC

svn commit: r993103 - 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/ apacheds/trunk/core-api/src/main/java/org/apache/directory/...

Author: elecharny
Date: Mon Sep  6 17:28:19 2010
New Revision: 993103

URL: http://svn.apache.org/viewvc?rev=993103&view=rev
Log:
o Added a LdapConnection.exists( DN ) method
o Fixed the lookup method so that it can be called with "1.1"

Added:
    directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/operations/exists/
    directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/operations/exists/ExistsIT.java
Modified:
    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/InterceptorChain.java
    directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/interceptor/context/LookupOperationContext.java
    directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/operations/lookup/LookupIT.java
    directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/operational/OperationalAttributeInterceptor.java
    directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/BTreePartition.java
    directory/clients/ldap/trunk/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/LdapConnection.java
    directory/clients/ldap/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/LdapCoreSessionConnection.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/LdapCoreSessionConnection.java?rev=993103&r1=993102&r2=993103&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 Mon Sep  6 17:28:19 2010
@@ -31,6 +31,7 @@ import org.apache.directory.ldap.client.
 import org.apache.directory.server.core.filtering.EntryFilteringCursor;
 import org.apache.directory.server.core.interceptor.context.BindOperationContext;
 import org.apache.directory.shared.asn1.primitives.OID;
+import org.apache.directory.shared.ldap.constants.SchemaConstants;
 import org.apache.directory.shared.ldap.cursor.Cursor;
 import org.apache.directory.shared.ldap.cursor.EmptyCursor;
 import org.apache.directory.shared.ldap.entry.DefaultModification;
@@ -40,6 +41,7 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.entry.ModificationOperation;
 import org.apache.directory.shared.ldap.entry.Value;
 import org.apache.directory.shared.ldap.exception.LdapException;
+import org.apache.directory.shared.ldap.exception.LdapNoPermissionException;
 import org.apache.directory.shared.ldap.exception.LdapOperationException;
 import org.apache.directory.shared.ldap.filter.SearchScope;
 import org.apache.directory.shared.ldap.message.AbandonRequest;
@@ -496,6 +498,38 @@ public class LdapCoreSessionConnection i
     /**
      * {@inheritDoc}
      */
+    public boolean exists( String dn ) throws LdapException
+    {
+        return exists( new DN( dn ) );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean exists( DN dn ) throws LdapException
+    {
+        try
+        {
+            Entry entry = lookup( dn, SchemaConstants.NO_ATTRIBUTE );
+
+            return entry != null;
+        }
+        catch ( LdapNoPermissionException lnpe )
+        {
+            // Special case to deal with insufficient permissions 
+            return false;
+        }
+        catch ( LdapException le )
+        {
+            throw le;
+        }
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
     public Entry lookup( DN dn ) throws LdapException
     {
         return _lookup( dn );

Modified: directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/interceptor/InterceptorChain.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/interceptor/InterceptorChain.java?rev=993103&r1=993102&r2=993103&view=diff
==============================================================================
--- directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/interceptor/InterceptorChain.java (original)
+++ directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/interceptor/InterceptorChain.java Mon Sep  6 17:28:19 2010
@@ -131,13 +131,15 @@ public class InterceptorChain
         }
 
 
-        public EntryFilteringCursor search( NextInterceptor next, SearchOperationContext searchContext ) throws LdapException
+        public EntryFilteringCursor search( NextInterceptor next, SearchOperationContext searchContext )
+            throws LdapException
         {
             return nexus.search( searchContext );
         }
 
 
-        public ClonedServerEntry lookup( NextInterceptor next, LookupOperationContext lookupContext ) throws LdapException
+        public ClonedServerEntry lookup( NextInterceptor next, LookupOperationContext lookupContext )
+            throws LdapException
         {
             return nexus.lookup( lookupContext );
         }
@@ -161,7 +163,8 @@ public class InterceptorChain
         }
 
 
-        public void moveAndRename( NextInterceptor next, MoveAndRenameOperationContext moveAndRenameContext ) throws LdapException
+        public void moveAndRename( NextInterceptor next, MoveAndRenameOperationContext moveAndRenameContext )
+            throws LdapException
         {
             nexus.moveAndRename( moveAndRenameContext );
         }
@@ -569,8 +572,8 @@ public class InterceptorChain
             // trouble reading the entry due to insufficient access rights
             CoreSession adminSession = opContext.getSession().getDirectoryService().getAdminSession();
 
-            Entry foundEntry = adminSession.lookup( opContext.getDn(),
-                SchemaConstants.ALL_OPERATIONAL_ATTRIBUTES_ARRAY );
+            Entry foundEntry = adminSession
+                .lookup( opContext.getDn(), SchemaConstants.ALL_OPERATIONAL_ATTRIBUTES_ARRAY );
 
             if ( foundEntry != null )
             {
@@ -580,13 +583,14 @@ public class InterceptorChain
                 }
                 else
                 {
-                    opContext.setEntry( (ClonedServerEntry)foundEntry );
+                    opContext.setEntry( ( ClonedServerEntry ) foundEntry );
                 }
             }
             else
             {
                 // This is an error : we *must* have an entry if we want to be able to rename.
-                LdapNoSuchObjectException ldnfe = new LdapNoSuchObjectException( I18n.err( I18n.ERR_256_NO_SUCH_OBJECT, opContext.getDn() ) );
+                LdapNoSuchObjectException ldnfe = new LdapNoSuchObjectException( I18n.err( I18n.ERR_256_NO_SUCH_OBJECT,
+                    opContext.getDn() ) );
 
                 throw ldnfe;
             }
@@ -600,8 +604,7 @@ public class InterceptorChain
         // trouble reading the entry due to insufficient access rights
         CoreSession adminSession = opContext.getSession().getDirectoryService().getAdminSession();
 
-        Entry foundEntry = adminSession.lookup( opContext.getDn(),
-            SchemaConstants.ALL_OPERATIONAL_ATTRIBUTES_ARRAY );
+        Entry foundEntry = adminSession.lookup( opContext.getDn(), SchemaConstants.ALL_OPERATIONAL_ATTRIBUTES_ARRAY );
 
         if ( foundEntry != null )
         {
@@ -610,7 +613,8 @@ public class InterceptorChain
         else
         {
             // This is an error : we *must* have an entry if we want to be able to rename.
-            LdapNoSuchObjectException ldnfe = new LdapNoSuchObjectException( I18n.err( I18n.ERR_256_NO_SUCH_OBJECT, opContext.getDn() ) );
+            LdapNoSuchObjectException ldnfe = new LdapNoSuchObjectException( I18n.err( I18n.ERR_256_NO_SUCH_OBJECT,
+                opContext.getDn() ) );
 
             throw ldnfe;
         }

Modified: directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/interceptor/context/LookupOperationContext.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/interceptor/context/LookupOperationContext.java?rev=993103&r1=993102&r2=993103&view=diff
==============================================================================
--- directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/interceptor/context/LookupOperationContext.java (original)
+++ directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/interceptor/context/LookupOperationContext.java Mon Sep  6 17:28:19 2010
@@ -18,7 +18,7 @@
  *  
  */
 package org.apache.directory.server.core.interceptor.context;
- 
+
 
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -38,16 +38,22 @@ import org.apache.directory.shared.ldap.
  */
 public class LookupOperationContext extends AbstractOperationContext
 {
-    private static final String[] EMPTY = new String[] {};
-    
+    private static final String[] EMPTY = new String[]
+        {};
+
     /** The list of attributes id to return */
     private List<String> attrsId = new ArrayList<String>();
-    
+
+    /** A flag set to true if the user has requested all the operational attributes ( "+" )*/
     private Boolean allOperational;
-    
+
+    /** A flag set to true if the user has requested all the user attributes ( "*" ) */
     private Boolean allUser;
-    
-    
+
+    /** A flag set to true if the user has requested no attribute to be returned */
+    private Boolean noAttribute;
+
+
     /**
      * 
      * Creates a new instance of LookupOperationContext.
@@ -57,7 +63,7 @@ public class LookupOperationContext exte
     {
         super( session );
     }
-    
+
 
     /**
      * 
@@ -68,7 +74,7 @@ public class LookupOperationContext exte
     {
         super( session, dn );
     }
-    
+
 
     /**
      * 
@@ -81,7 +87,7 @@ public class LookupOperationContext exte
         setAttrsId( attrsId );
     }
 
-    
+
     /**
      * 
      * Creates a new instance of LookupOperationContext.
@@ -93,7 +99,7 @@ public class LookupOperationContext exte
         setAttrsId( attrsId );
     }
 
-    
+
     /**
      * @return Get the attribute ids as a String array
      */
@@ -105,12 +111,12 @@ public class LookupOperationContext exte
         }
         else
         {
-            String[] attrs = new String[ attrsId.size()];
+            String[] attrs = new String[attrsId.size()];
             return attrsId.toArray( attrs );
         }
     }
 
-    
+
     /**
      * Set the attribute Ids
      *
@@ -118,10 +124,10 @@ public class LookupOperationContext exte
      */
     public void setAttrsId( String[] attrsId )
     {
-        if ( attrsId != null && attrsId.length > 0 )
+        if ( ( attrsId != null ) && ( attrsId.length > 0 ) )
         {
             this.attrsId = new ArrayList<String>( Arrays.asList( attrsId ) );
-            
+
             // filter out the '+' and '*' and set boolean parameters 
             for ( String id : this.attrsId )
             {
@@ -133,17 +139,31 @@ public class LookupOperationContext exte
                 {
                     allUser = true;
                 }
+                else if ( id.equals( SchemaConstants.NO_ATTRIBUTE ) )
+                {
+                    noAttribute = true;
+                    allOperational = null;
+                    allUser = null;
+
+                    // We can stop here
+                    break;
+                }
             }
 
-            if ( allOperational != null && allOperational )
+            if ( ( allOperational != null ) && allOperational )
             {
                 this.attrsId.remove( SchemaConstants.ALL_OPERATIONAL_ATTRIBUTES );
             }
-            
-            if ( allUser != null && allUser )
+
+            if ( ( allUser != null ) && allUser )
             {
                 this.attrsId.remove( SchemaConstants.ALL_USER_ATTRIBUTES );
             }
+
+            if ( noAttribute != null )
+            {
+                this.attrsId.clear();
+            }
         }
     }
 
@@ -155,27 +175,44 @@ public class LookupOperationContext exte
      */
     public void addAttrsId( String attrId )
     {
-        if ( attrId.equals( SchemaConstants.ALL_USER_ATTRIBUTES ) )
-        {
-            allUser = true;
-            return;
-        }
-        
-        if ( attrId.equals( SchemaConstants.ALL_OPERATIONAL_ATTRIBUTES ) )
+        if ( noAttribute == null )
         {
-            allOperational = true;
-            return;
-        }
-        
-        if ( attrsId == null )
-        {
-            attrsId = new ArrayList<String>(); 
+            if ( attrId.equals( SchemaConstants.NO_ATTRIBUTE ) )
+            {
+                noAttribute = true;
+
+                if ( attrsId != null )
+                {
+                    attrsId.clear();
+                }
+
+                return;
+            }
+
+            if ( attrId.equals( SchemaConstants.ALL_USER_ATTRIBUTES ) )
+            {
+                allUser = true;
+
+                return;
+            }
+
+            if ( attrId.equals( SchemaConstants.ALL_OPERATIONAL_ATTRIBUTES ) )
+            {
+                allOperational = true;
+
+                return;
+            }
+
+            if ( attrsId == null )
+            {
+                attrsId = new ArrayList<String>();
+            }
+
+            attrsId.add( attrId );
         }
-        
-        attrsId.add( attrId );
     }
 
-    
+
     /**
      * @return The attribute IDs list
      */
@@ -184,18 +221,33 @@ public class LookupOperationContext exte
         return attrsId;
     }
 
-    
-    public Boolean getAllUser()
+
+    /**
+     * @return The flag telling if the "*" attribute has been used
+     */
+    public boolean hasAllUser()
+    {
+        return ( allUser != null ) && allUser;
+    }
+
+
+    /**
+     * @return The flag telling if the "+" attribute has been used
+     */
+    public boolean hasAllOperational()
     {
-        return allUser;
+        return ( allOperational != null ) && allOperational;
     }
-    
 
-    public Boolean getAllOperational()
+
+    /**
+     * @return The flag telling if the "+" attribute has been used
+     */
+    public boolean hasNoAttribute()
     {
-        return allOperational;
+        return ( noAttribute != null );
     }
-    
+
 
     /**
      * @return the operation name
@@ -205,12 +257,13 @@ public class LookupOperationContext exte
         return "Lookup";
     }
 
-    
+
     /**
      * @see Object#toString()
      */
     public String toString()
     {
-        return "LookupContext for DN '" + getDn().getName() + "'" + ( ( attrsId != null ) ? ", attributes : <" + StringTools.listToString( attrsId ) + ">" : "" );
+        return "LookupContext for DN '" + getDn().getName() + "'"
+            + ( ( attrsId != null ) ? ", attributes : <" + StringTools.listToString( attrsId ) + ">" : "" );
     }
 }

Added: directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/operations/exists/ExistsIT.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/operations/exists/ExistsIT.java?rev=993103&view=auto
==============================================================================
--- directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/operations/exists/ExistsIT.java (added)
+++ directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/operations/exists/ExistsIT.java Mon Sep  6 17:28:19 2010
@@ -0,0 +1,89 @@
+/*
+ *  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.server.core.operations.exists;
+
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.apache.directory.ldap.client.api.LdapConnection;
+import org.apache.directory.server.core.annotations.ApplyLdifs;
+import org.apache.directory.server.core.integ.AbstractLdapTestUnit;
+import org.apache.directory.server.core.integ.FrameworkRunner;
+import org.apache.directory.server.core.integ.IntegrationUtils;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+
+/**
+ * Test the exists operation
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+@RunWith(FrameworkRunner.class)
+@ApplyLdifs(
+    {
+        // Entry # 1
+        "dn: cn=test,ou=system", 
+        "objectClass: person", 
+        "cn: test", 
+        "sn: sn_test" 
+    })
+public class ExistsIT extends AbstractLdapTestUnit
+{
+    /** The ldap connection */
+    private LdapConnection connection;
+
+
+    @Before
+    public void setup() throws Exception
+    {
+        connection = IntegrationUtils.getAdminConnection( service );
+    }
+
+
+    @After
+    public void shutdown() throws Exception
+    {
+        connection.close();
+    }
+
+
+    /**
+     * Test a exists( DN ) operation
+     */
+    @Test
+    public void testExists() throws Exception
+    {
+        assertTrue( connection.exists( "cn=test,ou=system" ) );
+    }
+
+
+    /**
+     * Test a wrong exists( DN ) operation
+     */
+    @Test
+    public void testNotExists() throws Exception
+    {
+        assertFalse( connection.exists( "cn=test2,ou=system" ) );
+    }
+}

Modified: directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/operations/lookup/LookupIT.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/operations/lookup/LookupIT.java?rev=993103&r1=993102&r2=993103&view=diff
==============================================================================
--- directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/operations/lookup/LookupIT.java (original)
+++ directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/operations/lookup/LookupIT.java Mon Sep  6 17:28:19 2010
@@ -31,7 +31,6 @@ import org.apache.directory.server.core.
 import org.apache.directory.server.core.integ.FrameworkRunner;
 import org.apache.directory.server.core.integ.IntegrationUtils;
 import org.apache.directory.shared.ldap.entry.Entry;
-import org.apache.directory.shared.ldap.message.SearchResultEntry;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Ignore;
@@ -172,4 +171,19 @@ public class LookupIT extends AbstractLd
         assertEquals( "sn_test", entry.get( "sn" ).getString() );
         assertFalse( entry.containsAttribute( "objectClass" ) );
     }
+
+
+    /**
+     * Test a lookup( DN ) operation with no attributes
+     */
+    @Test
+    @Ignore
+    public void testLookupWithNoAttrs() throws Exception
+    {
+        Entry entry = connection.lookup( "cn=test,ou=system", "1.1" );
+        assertNotNull( entry );
+
+        // We should have 0 attributes
+        assertEquals( 0, entry.size() );
+    }
 }

Modified: directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/operational/OperationalAttributeInterceptor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/operational/OperationalAttributeInterceptor.java?rev=993103&r1=993102&r2=993103&view=diff
==============================================================================
--- directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/operational/OperationalAttributeInterceptor.java (original)
+++ directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/operational/OperationalAttributeInterceptor.java Mon Sep  6 17:28:19 2010
@@ -285,8 +285,8 @@ public class OperationalAttributeInterce
                     modifiedTimeAtPresent = true;
                 }
             }
-            
-            if( PWD_POLICY_STATE_ATTRIBUTE_TYPES.contains( attributeType ) && !isAdmin )
+
+            if ( PWD_POLICY_STATE_ATTRIBUTE_TYPES.contains( attributeType ) && !isAdmin )
             {
                 String message = I18n.err( I18n.ERR_32 );
                 LOG.error( message );
@@ -323,7 +323,7 @@ public class OperationalAttributeInterce
 
     public void rename( NextInterceptor nextInterceptor, RenameOperationContext renameContext ) throws LdapException
     {
-        Entry entry = ((ClonedServerEntry)renameContext.getEntry() ).getClonedEntry();
+        Entry entry = ( ( ClonedServerEntry ) renameContext.getEntry() ).getClonedEntry();
         entry.put( SchemaConstants.MODIFIERS_NAME_AT, getPrincipal().getName() );
         entry.put( SchemaConstants.MODIFY_TIMESTAMP_AT, DateUtils.getGeneralizedTime() );
 
@@ -341,7 +341,7 @@ public class OperationalAttributeInterce
         modifiedEntry.put( SchemaConstants.MODIFY_TIMESTAMP_AT, DateUtils.getGeneralizedTime() );
         modifiedEntry.setDn( moveContext.getNewDn() );
         moveContext.setModifiedEntry( modifiedEntry );
-        
+
         nextInterceptor.move( moveContext );
     }
 
@@ -372,7 +372,7 @@ public class OperationalAttributeInterce
         {
             filterOperationalAttributes( result );
         }
-        else if ( ( lookupContext.getAllOperational() == null ) || ( lookupContext.getAllOperational() == false ) )
+        else if ( !lookupContext.hasAllOperational() )
         {
             filter( lookupContext, result );
         }

Modified: directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/BTreePartition.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/BTreePartition.java?rev=993103&r1=993102&r2=993103&view=diff
==============================================================================
--- directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/BTreePartition.java (original)
+++ directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/BTreePartition.java Mon Sep  6 17:28:19 2010
@@ -303,6 +303,14 @@ public abstract class BTreePartition<ID>
 
         ClonedServerEntry entry = lookup( id );
 
+        // Remove all the attributes if the NO_ATTRIBUTE flag is set
+        if ( lookupContext.hasNoAttribute() )
+        {
+            entry.clear();
+
+            return entry;
+        }
+
         if ( ( lookupContext.getAttrsId() == null ) || ( lookupContext.getAttrsId().size() == 0 ) )
         {
             return entry;

Modified: directory/clients/ldap/trunk/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/LdapConnection.java
URL: http://svn.apache.org/viewvc/directory/clients/ldap/trunk/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/LdapConnection.java?rev=993103&r1=993102&r2=993103&view=diff
==============================================================================
--- directory/clients/ldap/trunk/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/LdapConnection.java (original)
+++ directory/clients/ldap/trunk/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/LdapConnection.java Mon Sep  6 17:28:19 2010
@@ -573,6 +573,30 @@ public interface LdapConnection
 
 
     /**
+     * Tells if an Entry exists in the server
+     * 
+     * @param dn The DN for the entry we want to check the existence
+     * @return <code>true</code> if the entry exists, <code>false</code> otherwise. 
+     * Note that if the entry exists but if the users does not have the permission to
+     * read it, <code>false</code> will also be returned 
+     * @throws LdapException if some error occurred
+     */
+    public abstract boolean exists( String dn ) throws LdapException;
+
+
+    /**
+     * Tells if an Entry exists in the server
+     * 
+     * @param dn The DN for the entry we want to check the existence
+     * @return <code>true</code> if the entry exists, <code>false</code> otherwise. 
+     * Note that if the entry exists but if the users does not have the permission to
+     * read it, <code>false</code> will also be returned 
+     * @throws LdapException if some error occurred
+     */
+    public abstract boolean exists( DN dn ) throws LdapException;
+
+
+    /**
      * @see #lookup(DN, String...)
      * @throws LdapException if some error occurred
      */

Modified: directory/clients/ldap/trunk/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/LdapNetworkConnection.java
URL: http://svn.apache.org/viewvc/directory/clients/ldap/trunk/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/LdapNetworkConnection.java?rev=993103&r1=993102&r2=993103&view=diff
==============================================================================
--- directory/clients/ldap/trunk/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/LdapNetworkConnection.java (original)
+++ directory/clients/ldap/trunk/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/LdapNetworkConnection.java Mon Sep  6 17:28:19 2010
@@ -66,6 +66,7 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.entry.Value;
 import org.apache.directory.shared.ldap.exception.LdapException;
 import org.apache.directory.shared.ldap.exception.LdapInvalidDnException;
+import org.apache.directory.shared.ldap.exception.LdapNoPermissionException;
 import org.apache.directory.shared.ldap.filter.SearchScope;
 import org.apache.directory.shared.ldap.message.AbandonRequest;
 import org.apache.directory.shared.ldap.message.AbandonRequestImpl;
@@ -954,90 +955,6 @@ public class LdapNetworkConnection exten
 
 
     /**
-     * Create a SearchRequestCodec ready to be sent.
-     *
-    private SearchRequestCodec createSearchMessage( SearchRequest searchRequest ) throws LdapException
-    {
-        // Create a new codec SearchRequest object
-        SearchRequestCodec request = new SearchRequestCodec();
-
-        // Creates the messageID and stores it into the
-        // initial message and the transmitted message.
-        int newId = messageId.incrementAndGet();
-        searchRequest.setMessageId( newId );
-        request.setMessageId( newId );
-
-        // Set the name
-        try
-        {
-            DN dn = new DN( searchRequest.getBaseDn() );
-            request.setBaseObject( dn );
-        }
-        catch ( LdapInvalidDnException ine )
-        {
-            String msg = "The given dn '" + searchRequest.getBaseDn() + "' is not valid";
-            LOG.error( msg );
-            LdapException ldapException = new LdapException( msg );
-            ldapException.initCause( ine );
-
-            throw ldapException;
-        }
-
-        // Set the scope
-        request.setScope( searchRequest.getScope() );
-
-        // Set the typesOnly flag
-        request.setDerefAliases( searchRequest.getDerefAliases().getValue() );
-
-        // Set the timeLimit
-        request.setTimeLimit( searchRequest.getTimeLimit() );
-
-        // Set the sizeLimit
-        request.setSizeLimit( searchRequest.getSizeLimit() );
-
-        // Set the typesOnly flag
-        request.setTypesOnly( searchRequest.getTypesOnly() );
-
-        // Set the filter
-        Filter filter = null;
-
-        try
-        {
-            ExprNode filterNode = FilterParser.parse( schemaManager, searchRequest.getFilter() );
-
-            filter = LdapTransformer.transformFilter( schemaManager, filterNode );
-        }
-        catch ( ParseException pe )
-        {
-            String msg = "The given filter '" + searchRequest.getFilter() + "' is not valid";
-            LOG.error( msg );
-            LdapException ldapException = new LdapException( msg );
-            ldapException.initCause( pe );
-
-            throw ldapException;
-        }
-
-        request.setFilter( filter );
-
-        // Set the attributes
-        Set<String> attributes = searchRequest.getAttributes();
-
-        if ( attributes != null )
-        {
-            for ( String attribute : attributes )
-            {
-                request.addAttribute( attribute );
-            }
-        }
-
-        // Add the controls
-        setControls( searchRequest.getControls(), request );
-
-        return request;
-    }
-
-
-    /**
      * Create a Simple BindRequest ready to be sent.
      */
     private BindRequest createBindRequest( String name, byte[] credentials ) throws LdapException
@@ -2944,6 +2861,38 @@ public class LdapNetworkConnection exten
     /**
      * {@inheritDoc}
      */
+    public boolean exists( String dn ) throws LdapException
+    {
+        return exists( new DN( dn ) );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean exists( DN dn ) throws LdapException
+    {
+        try
+        {
+            Entry entry = lookup( dn, SchemaConstants.NO_ATTRIBUTE_ARRAY );
+
+            return entry != null;
+        }
+        catch ( LdapNoPermissionException lnpe )
+        {
+            // Special case to deal with insufficient permissions 
+            return false;
+        }
+        catch ( LdapException le )
+        {
+            throw le;
+        }
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
     public Entry lookup( DN dn ) throws LdapException
     {
         return lookup( dn, SchemaConstants.ALL_USER_ATTRIBUTES_ARRAY );
@@ -3050,7 +2999,7 @@ public class LdapNetworkConnection exten
 
             schemaManager = new DefaultSchemaManager( jarSchemaLoader );
 
-            // we enale all the schemas so that need not check with server for enabled schemas
+            // we enable all the schemas so that need not check with server for enabled schemas
             Collection<Schema> schemas = schemaManager.getLoader().getAllSchemas();
             for ( Schema s : schemas )
             {