directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r280053 - in /directory/apacheds/trunk/core/src: main/java/org/apache/ldap/server/collective/ main/java/org/apache/ldap/server/configuration/ test/org/apache/ldap/server/collective/
Date Sun, 11 Sep 2005 01:05:48 GMT
Author: akarasulu
Date: Sat Sep 10 18:05:41 2005
New Revision: 280053

URL: http://svn.apache.org/viewcvs?rev=280053&view=rev
Log:
changes ...

 o added test case to test the collective attribute functionality
 o test case exposed several bugs which we fixed 
 o found that interceptor was not even running due to a bug in startup config


Added:
    directory/apacheds/trunk/core/src/test/org/apache/ldap/server/collective/
    directory/apacheds/trunk/core/src/test/org/apache/ldap/server/collective/CollectiveAttributeServiceTest.java
  (with props)
Modified:
    directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/collective/CollectiveAttributeService.java
    directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/configuration/StartupConfiguration.java

Modified: directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/collective/CollectiveAttributeService.java
URL: http://svn.apache.org/viewcvs/directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/collective/CollectiveAttributeService.java?rev=280053&r1=280052&r2=280053&view=diff
==============================================================================
--- directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/collective/CollectiveAttributeService.java
(original)
+++ directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/collective/CollectiveAttributeService.java
Sat Sep 10 18:05:41 2005
@@ -43,6 +43,7 @@
 import java.util.Map;
 import java.util.Set;
 import java.util.HashSet;
+import java.util.Collections;
 
 
 /**
@@ -65,12 +66,7 @@
         public boolean accept( LdapContext ctx, SearchResult result, SearchControls controls
)
                 throws NamingException
         {
-            if ( controls.getReturningAttributes() == null )
-            {
                 return filter( result.getAttributes() );
-            }
-
-            return true;
         }
     };
 
@@ -126,6 +122,10 @@
                 exclusions.add( attrType.getOid() );
             }
         }
+        else
+        {
+            exclusions = Collections.EMPTY_SET;
+        }
 
         /*
          * For each collective subentry referenced by the entry we lookup the
@@ -172,7 +172,7 @@
                     // add all the collective attribute values in the subentry to entry
                     for ( int jj = 0; jj < subentryColAttr.size(); jj++ )
                     {
-                        entryColAttr.add( subentryColAttr.get( ii ) );
+                        entryColAttr.add( subentryColAttr.get( jj ) );
                     }
                 }
             }
@@ -276,11 +276,6 @@
             SearchControls searchCtls ) throws NamingException
     {
         NamingEnumeration e = nextInterceptor.search( base, env, filter, searchCtls );
-        if ( searchCtls.getReturningAttributes() != null )
-        {
-            return e;
-        }
-
         LdapContext ctx =
             ( LdapContext ) InvocationStack.getInstance().peek().getCaller();
         return new SearchResultFilteringEnumeration( e, searchCtls, ctx, SEARCH_FILTER );

Modified: directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/configuration/StartupConfiguration.java
URL: http://svn.apache.org/viewcvs/directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/configuration/StartupConfiguration.java?rev=280053&r1=280052&r2=280053&view=diff
==============================================================================
--- directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/configuration/StartupConfiguration.java
(original)
+++ directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/configuration/StartupConfiguration.java
Sat Sep 10 18:05:41 2005
@@ -39,6 +39,7 @@
 import org.apache.ldap.server.schema.bootstrap.*;
 import org.apache.ldap.server.subtree.SubentryService;
 import org.apache.ldap.server.event.EventService;
+import org.apache.ldap.server.collective.CollectiveAttributeService;
 
 /**
  * A {@link Configuration} that starts up ApacheDS.
@@ -165,7 +166,7 @@
 
         interceptorCfg = new MutableInterceptorConfiguration();
         interceptorCfg.setName( "collectiveAttributeService" );
-        interceptorCfg.setInterceptor( new OperationalAttributeService() );
+        interceptorCfg.setInterceptor( new CollectiveAttributeService() );
         list.add( interceptorCfg );
 
         interceptorCfg = new MutableInterceptorConfiguration();

Added: directory/apacheds/trunk/core/src/test/org/apache/ldap/server/collective/CollectiveAttributeServiceTest.java
URL: http://svn.apache.org/viewcvs/directory/apacheds/trunk/core/src/test/org/apache/ldap/server/collective/CollectiveAttributeServiceTest.java?rev=280053&view=auto
==============================================================================
--- directory/apacheds/trunk/core/src/test/org/apache/ldap/server/collective/CollectiveAttributeServiceTest.java
(added)
+++ directory/apacheds/trunk/core/src/test/org/apache/ldap/server/collective/CollectiveAttributeServiceTest.java
Sat Sep 10 18:05:41 2005
@@ -0,0 +1,370 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed 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.ldap.server.collective;
+
+
+import org.apache.ldap.server.AbstractAdminTestCase;
+import org.apache.ldap.common.message.LockableAttributeImpl;
+import org.apache.ldap.common.message.LockableAttributesImpl;
+
+import javax.naming.NamingException;
+import javax.naming.NamingEnumeration;
+import javax.naming.directory.*;
+import java.util.Map;
+import java.util.HashMap;
+
+
+/**
+ * Test cases for the collective attribute service.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class CollectiveAttributeServiceTest extends AbstractAdminTestCase
+{
+    public Attributes getTestEntry( String cn )
+    {
+        Attributes subentry = new LockableAttributesImpl();
+        Attribute objectClass = new LockableAttributeImpl( "objectClass" );
+        objectClass.add( "top" );
+        objectClass.add( "person" );
+        subentry.put( objectClass );
+        subentry.put( "cn", cn );
+        subentry.put( "sn", "testentry" );
+        return subentry;
+    }
+
+
+    public Attributes getTestSubentry()
+    {
+        Attributes subentry = new LockableAttributesImpl();
+        Attribute objectClass = new LockableAttributeImpl( "objectClass" );
+        objectClass.add( "top" );
+        objectClass.add( "subentry" );
+        objectClass.add( "collectiveAttributeSubentry" );
+        subentry.put( objectClass );
+        subentry.put( "c-ou", "configuration" );
+        subentry.put( "subtreeSpecification", "{ base \"ou=configuration\" }" );
+        subentry.put( "cn", "testsubentry" );
+        return subentry;
+    }
+
+
+    public Attributes getTestSubentry2()
+    {
+        Attributes subentry = new LockableAttributesImpl();
+        Attribute objectClass = new LockableAttributeImpl( "objectClass" );
+        objectClass.add( "top" );
+        objectClass.add( "subentry" );
+        objectClass.add( "collectiveAttributeSubentry" );
+        subentry.put( objectClass );
+        subentry.put( "c-ou", "configuration2" );
+        subentry.put( "subtreeSpecification", "{ base \"ou=configuration\" }" );
+        subentry.put( "cn", "testsubentry2" );
+        return subentry;
+    }
+
+
+    public Attributes getTestSubentry3()
+    {
+        Attributes subentry = new LockableAttributesImpl();
+        Attribute objectClass = new LockableAttributeImpl( "objectClass" );
+        objectClass.add( "top" );
+        objectClass.add( "subentry" );
+        objectClass.add( "collectiveAttributeSubentry" );
+        subentry.put( objectClass );
+        subentry.put( "c-st", "FL" );
+        subentry.put( "subtreeSpecification", "{ base \"ou=configuration\" }" );
+        subentry.put( "cn", "testsubentry3" );
+        return subentry;
+    }
+
+
+    public void addAdministrativeRole( String role ) throws NamingException
+    {
+        Attribute attribute = new LockableAttributeImpl( "administrativeRole" );
+        attribute.add( role );
+        ModificationItem item = new ModificationItem( DirContext.ADD_ATTRIBUTE, attribute
);
+        super.sysRoot.modifyAttributes( "", new ModificationItem[] { item } );
+    }
+
+
+    public Map getAllEntries() throws NamingException
+    {
+        Map resultMap = new HashMap();
+        SearchControls controls = new SearchControls();
+        controls.setSearchScope( SearchControls.SUBTREE_SCOPE );
+        controls.setReturningAttributes( new String[] { "+", "*" } );
+        NamingEnumeration results = super.sysRoot.search( "", "(objectClass=*)", controls
);
+        while ( results.hasMore() )
+        {
+            SearchResult result = ( SearchResult ) results.next();
+            resultMap.put( result.getName(), result.getAttributes() );
+        }
+        return resultMap;
+    }
+
+
+    public Map getAllEntriesRestrictAttributes() throws NamingException
+    {
+        Map resultMap = new HashMap();
+        SearchControls controls = new SearchControls();
+        controls.setSearchScope( SearchControls.SUBTREE_SCOPE );
+        controls.setReturningAttributes( new String[] { "cn", "ou" } );
+        NamingEnumeration results = super.sysRoot.search( "", "(objectClass=*)", controls
);
+        while ( results.hasMore() )
+        {
+            SearchResult result = ( SearchResult ) results.next();
+            resultMap.put( result.getName(), result.getAttributes() );
+        }
+        return resultMap;
+    }
+
+
+    public void testLookup() throws Exception
+    {
+        // -------------------------------------------------------------------
+        // Setup the collective attribute specific administration point
+        // -------------------------------------------------------------------
+
+        addAdministrativeRole( "collectiveAttributeSpecificArea" );
+        super.sysRoot.createSubcontext( "cn=testsubentry", getTestSubentry() );
+
+        // -------------------------------------------------------------------
+        // test an entry that should show the collective attribute c-ou
+        // -------------------------------------------------------------------
+
+        Attributes attributes = super.sysRoot.getAttributes( "ou=services,ou=configuration"
);
+        Attribute c_ou = attributes.get( "c-ou" );
+        assertNotNull( "a collective c-ou attribute should be present", c_ou );
+        assertEquals( "configuration", c_ou.get() );
+
+        // -------------------------------------------------------------------
+        // test an entry that should not show the collective attribute
+        // -------------------------------------------------------------------
+
+        attributes = super.sysRoot.getAttributes( "ou=users" );
+        c_ou = attributes.get( "c-ou" );
+        assertNull( "the c-ou collective attribute should not be present", c_ou );
+
+        // -------------------------------------------------------------------
+        // now modify entries included by the subentry to have collectiveExclusions
+        // -------------------------------------------------------------------
+
+        ModificationItem[] items = new ModificationItem[] {
+            new ModificationItem( DirContext.ADD_ATTRIBUTE,
+                    new LockableAttributeImpl( "collectiveExclusions", "c-ou" ) ) };
+        super.sysRoot.modifyAttributes( "ou=services,ou=configuration", items );
+
+        // entry should not show the c-ou collective attribute anymore
+        attributes = super.sysRoot.getAttributes( "ou=services,ou=configuration" );
+        c_ou = attributes.get( "c-ou" );
+        if ( c_ou != null )
+        {
+            assertEquals( "the c-ou collective attribute should not be present", 0, c_ou.size()
);
+        }
+
+        // now add more collective subentries - the c-ou should still not show due to exclusions
+        super.sysRoot.createSubcontext( "cn=testsubentry2", getTestSubentry2() );
+
+        attributes = super.sysRoot.getAttributes( "ou=services,ou=configuration" );
+        c_ou = attributes.get( "c-ou" );
+        if ( c_ou != null )
+        {
+            assertEquals( "the c-ou collective attribute should not be present", 0, c_ou.size()
);
+        }
+
+        // entries without the collectiveExclusion should still show both values of c-ou
+        attributes = super.sysRoot.getAttributes( "ou=interceptors,ou=configuration" );
+        c_ou = attributes.get( "c-ou" );
+        assertNotNull( "a collective c-ou attribute should be present", c_ou );
+        assertTrue( c_ou.contains( "configuration" ) );
+        assertTrue( c_ou.contains( "configuration2" ) );
+
+        // -------------------------------------------------------------------
+        // now add the subentry for the c-st collective attribute
+        // -------------------------------------------------------------------
+
+        super.sysRoot.createSubcontext( "cn=testsubentry3", getTestSubentry3() );
+
+        // the new attribute c-st should appear in the node with the c-ou exclusion
+        attributes = super.sysRoot.getAttributes( "ou=services,ou=configuration" );
+        Attribute c_st = attributes.get( "c-st" );
+        assertNotNull( "a collective c-st attribute should be present", c_st );
+        assertTrue( c_st.contains( "FL" ) );
+
+        // in node without exclusions both values of c-ou should appear with c-st value
+        attributes = super.sysRoot.getAttributes( "ou=interceptors,ou=configuration" );
+        c_ou = attributes.get( "c-ou" );
+        assertNotNull( "a collective c-ou attribute should be present", c_ou );
+        assertTrue( c_ou.contains( "configuration" ) );
+        assertTrue( c_ou.contains( "configuration2" ) );
+        c_st = attributes.get( "c-st" );
+        assertNotNull( "a collective c-st attribute should be present", c_st );
+        assertTrue( c_st.contains( "FL" ) );
+
+        // -------------------------------------------------------------------
+        // now modify an entry to exclude all collective attributes
+        // -------------------------------------------------------------------
+
+        items = new ModificationItem[] {
+            new ModificationItem( DirContext.REPLACE_ATTRIBUTE,
+                    new LockableAttributeImpl( "collectiveExclusions", "excludeAllCollectiveAttributes"
) ) };
+        super.sysRoot.modifyAttributes( "ou=interceptors,ou=configuration", items );
+
+        // none of the attributes should appear any longer
+        attributes = super.sysRoot.getAttributes( "ou=interceptors,ou=configuration" );
+        c_ou = attributes.get( "c-ou" );
+        if ( c_ou != null )
+        {
+            assertEquals( "the c-ou collective attribute should not be present", 0, c_ou.size()
);
+        }
+        c_st = attributes.get( "c-st" );
+        if ( c_st != null )
+        {
+            assertEquals( "the c-st collective attribute should not be present", 0, c_st.size()
);
+        }
+    }
+
+
+    public void testSearch() throws Exception
+    {
+        // -------------------------------------------------------------------
+        // Setup the collective attribute specific administration point
+        // -------------------------------------------------------------------
+
+        addAdministrativeRole( "collectiveAttributeSpecificArea" );
+        super.sysRoot.createSubcontext( "cn=testsubentry", getTestSubentry() );
+
+        // -------------------------------------------------------------------
+        // test an entry that should show the collective attribute c-ou
+        // -------------------------------------------------------------------
+
+        Map entries = getAllEntries();
+        Attributes attributes = ( Attributes ) entries.get( "ou=services,ou=configuration,ou=system"
);
+        Attribute c_ou = attributes.get( "c-ou" );
+        assertNotNull( "a collective c-ou attribute should be present", c_ou );
+        assertEquals( "configuration", c_ou.get() );
+
+        // -------------------------------------------------------------------
+        // test an entry that should not show the collective attribute
+        // -------------------------------------------------------------------
+
+        attributes = ( Attributes ) entries.get( "ou=users,ou=system" );
+        c_ou = attributes.get( "c-ou" );
+        assertNull( "the c-ou collective attribute should not be present", c_ou );
+
+        // -------------------------------------------------------------------
+        // now modify entries included by the subentry to have collectiveExclusions
+        // -------------------------------------------------------------------
+
+        ModificationItem[] items = new ModificationItem[] {
+            new ModificationItem( DirContext.ADD_ATTRIBUTE,
+                    new LockableAttributeImpl( "collectiveExclusions", "c-ou" ) ) };
+        super.sysRoot.modifyAttributes( "ou=services,ou=configuration", items );
+        entries = getAllEntries();
+
+        // entry should not show the c-ou collective attribute anymore
+        attributes = ( Attributes ) entries.get( "ou=services,ou=configuration,ou=system"
);
+        c_ou = attributes.get( "c-ou" );
+        if ( c_ou != null )
+        {
+            assertEquals( "the c-ou collective attribute should not be present", 0, c_ou.size()
);
+        }
+
+        // now add more collective subentries - the c-ou should still not show due to exclusions
+        super.sysRoot.createSubcontext( "cn=testsubentry2", getTestSubentry2() );
+        entries = getAllEntries();
+
+        attributes = ( Attributes ) entries.get( "ou=services,ou=configuration,ou=system"
);
+        c_ou = attributes.get( "c-ou" );
+        if ( c_ou != null )
+        {
+            assertEquals( "the c-ou collective attribute should not be present", 0, c_ou.size()
);
+        }
+
+        // entries without the collectiveExclusion should still show both values of c-ou
+        attributes = ( Attributes ) entries.get( "ou=interceptors,ou=configuration,ou=system"
);
+        c_ou = attributes.get( "c-ou" );
+        assertNotNull( "a collective c-ou attribute should be present", c_ou );
+        assertTrue( c_ou.contains( "configuration" ) );
+        assertTrue( c_ou.contains( "configuration2" ) );
+
+        // -------------------------------------------------------------------
+        // now add the subentry for the c-st collective attribute
+        // -------------------------------------------------------------------
+
+        super.sysRoot.createSubcontext( "cn=testsubentry3", getTestSubentry3() );
+        entries = getAllEntries();
+
+        // the new attribute c-st should appear in the node with the c-ou exclusion
+        attributes = ( Attributes ) entries.get( "ou=services,ou=configuration,ou=system"
);
+        Attribute c_st = attributes.get( "c-st" );
+        assertNotNull( "a collective c-st attribute should be present", c_st );
+        assertTrue( c_st.contains( "FL" ) );
+
+        // in node without exclusions both values of c-ou should appear with c-st value
+        attributes = ( Attributes ) entries.get( "ou=interceptors,ou=configuration,ou=system"
);
+        c_ou = attributes.get( "c-ou" );
+        assertNotNull( "a collective c-ou attribute should be present", c_ou );
+        assertTrue( c_ou.contains( "configuration" ) );
+        assertTrue( c_ou.contains( "configuration2" ) );
+        c_st = attributes.get( "c-st" );
+        assertNotNull( "a collective c-st attribute should be present", c_st );
+        assertTrue( c_st.contains( "FL" ) );
+
+        // -------------------------------------------------------------------
+        // now modify an entry to exclude all collective attributes
+        // -------------------------------------------------------------------
+
+        items = new ModificationItem[] {
+            new ModificationItem( DirContext.REPLACE_ATTRIBUTE,
+                    new LockableAttributeImpl( "collectiveExclusions", "excludeAllCollectiveAttributes"
) ) };
+        super.sysRoot.modifyAttributes( "ou=interceptors,ou=configuration", items );
+        entries = getAllEntries();
+
+        // none of the attributes should appear any longer
+        attributes = ( Attributes ) entries.get( "ou=interceptors,ou=configuration,ou=system"
);
+        c_ou = attributes.get( "c-ou" );
+        if ( c_ou != null )
+        {
+            assertEquals( "the c-ou collective attribute should not be present", 0, c_ou.size()
);
+        }
+        c_st = attributes.get( "c-st" );
+        if ( c_st != null )
+        {
+            assertEquals( "the c-st collective attribute should not be present", 0, c_st.size()
);
+        }
+
+        // -------------------------------------------------------------------
+        // Now search attributes but restrict returned attributes to cn and ou
+        // -------------------------------------------------------------------
+
+        entries = getAllEntriesRestrictAttributes();
+
+        // we should no longer see collective attributes with restricted return attribs
+        attributes = ( Attributes ) entries.get( "ou=services,ou=configuration,ou=system"
);
+        c_st = attributes.get( "c-st" );
+        assertNull( "a collective c-st attribute should NOT be present", c_st );
+
+        attributes = ( Attributes ) entries.get( "ou=partitions,ou=configuration,ou=system"
);
+        c_ou = attributes.get( "c-ou" );
+        c_st = attributes.get( "c-st" );
+        assertNull( c_ou );
+        assertNull( c_st );
+    }
+}

Propchange: directory/apacheds/trunk/core/src/test/org/apache/ldap/server/collective/CollectiveAttributeServiceTest.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message