directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ersi...@apache.org
Subject svn commit: r494680 - in /directory/trunks/apacheds: core-unit/src/test/java/org/apache/directory/server/core/collective/ core/src/main/java/org/apache/directory/server/core/collective/ server-unit/src/test/java/org/apache/directory/server/
Date Wed, 10 Jan 2007 01:29:58 GMT
Author: ersiner
Date: Tue Jan  9 17:29:57 2007
New Revision: 494680

URL: http://svn.apache.org/viewvc?view=rev&rev=494680
Log:
> Fixed DIRSERVER-816.
> Fixed 2-3 bugs more related to Collective Attribute Service.
> Enabled seelman's test cases which were commented out.
> Stuff added with this commit, may be improved for performance.
> A review of the Collective Attribute Service Interceptor might be a useful. I think it
can be better organized.

Modified:
    directory/trunks/apacheds/core-unit/src/test/java/org/apache/directory/server/core/collective/CollectiveAttributeServiceITest.java
    directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/collective/CollectiveAttributeService.java
    directory/trunks/apacheds/server-unit/src/test/java/org/apache/directory/server/SearchTest.java

Modified: directory/trunks/apacheds/core-unit/src/test/java/org/apache/directory/server/core/collective/CollectiveAttributeServiceITest.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/core-unit/src/test/java/org/apache/directory/server/core/collective/CollectiveAttributeServiceITest.java?view=diff&rev=494680&r1=494679&r2=494680
==============================================================================
--- directory/trunks/apacheds/core-unit/src/test/java/org/apache/directory/server/core/collective/CollectiveAttributeServiceITest.java
(original)
+++ directory/trunks/apacheds/core-unit/src/test/java/org/apache/directory/server/core/collective/CollectiveAttributeServiceITest.java
Tue Jan  9 17:29:57 2007
@@ -147,22 +147,21 @@
     }
     
     
-//  Testcase for DIRSERVER-816
-//    public Map getAllEntriesCollectiveAttributesOnly() throws NamingException
-//    {
-//        Map resultMap = new HashMap();
-//        SearchControls controls = new SearchControls();
-//        controls.setSearchScope( SearchControls.SUBTREE_SCOPE );
-//        controls.setReturningAttributes( new String[]
-//                                                    { "c-ou", "c-st" } );
-//        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 getAllEntriesCollectiveAttributesOnly() throws NamingException
+    {
+        Map resultMap = new HashMap();
+        SearchControls controls = new SearchControls();
+        controls.setSearchScope( SearchControls.SUBTREE_SCOPE );
+        controls.setReturningAttributes( new String[]
+                                                    { "c-ou", "c-st" } );
+        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
@@ -291,17 +290,16 @@
         assertEquals( "configuration", c_ou.get() );
 
         
-//      Testcase for DIRSERVER-816
-//        // ------------------------------------------------------------------
-//        // test an entry that should show the collective attribute c-ou, 
-//        // but restrict returned attributes to c-ou and c-st
-//        // ------------------------------------------------------------------
-//        
-//        entries = getAllEntriesCollectiveAttributesOnly();
-//        attributes = ( Attributes ) entries.get( "ou=services,ou=configuration,ou=system"
);
-//        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 show the collective attribute c-ou, 
+        // but restrict returned attributes to c-ou and c-st
+        // ------------------------------------------------------------------
+        
+        entries = getAllEntriesCollectiveAttributesOnly();
+        attributes = ( Attributes ) entries.get( "ou=services,ou=configuration,ou=system"
);
+        c_ou = attributes.get( "c-ou" );
+        assertNotNull( "a collective c-ou attribute should be present", c_ou );
+        assertEquals( "configuration", c_ou.get() );   
         
         
         // -------------------------------------------------------------------

Modified: directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/collective/CollectiveAttributeService.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/collective/CollectiveAttributeService.java?view=diff&rev=494680&r1=494679&r2=494680
==============================================================================
--- directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/collective/CollectiveAttributeService.java
(original)
+++ directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/collective/CollectiveAttributeService.java
Tue Jan  9 17:29:57 2007
@@ -20,6 +20,19 @@
 package org.apache.directory.server.core.collective;
 
 
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import javax.naming.Name;
+import javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
+import javax.naming.directory.Attribute;
+import javax.naming.directory.Attributes;
+import javax.naming.directory.SearchControls;
+import javax.naming.directory.SearchResult;
+
 import org.apache.directory.server.core.DirectoryServiceConfiguration;
 import org.apache.directory.server.core.configuration.InterceptorConfiguration;
 import org.apache.directory.server.core.enumeration.SearchResultFilter;
@@ -36,18 +49,6 @@
 import org.apache.directory.shared.ldap.name.LdapDN;
 import org.apache.directory.shared.ldap.schema.AttributeType;
 
-import javax.naming.NamingException;
-import javax.naming.NamingEnumeration;
-import javax.naming.Name;
-import javax.naming.directory.Attributes;
-import javax.naming.directory.SearchControls;
-import javax.naming.directory.Attribute;
-import javax.naming.directory.SearchResult;
-import java.util.Map;
-import java.util.Set;
-import java.util.HashSet;
-import java.util.Collections;
-
 
 /**
  * An interceptor based service dealing with collective attribute
@@ -69,7 +70,10 @@
         public boolean accept( Invocation invocation, SearchResult result, SearchControls
controls )
             throws NamingException
         {
-            return filter( result.getAttributes() );
+            LdapDN name = new LdapDN(result.getName());
+            filter( name, result.getAttributes() );
+            searchFilter( name, result.getAttributes(), controls.getReturningAttributes()
);
+            return true;
         }
     };
 
@@ -90,18 +94,22 @@
      * by the entry.  All collective attributes that are not exclused are added
      * to the entry from all subentries.
      *
+     * @param name name of the entry being processed
      * @param entry the entry to have the collective attributes injected
      * @throws NamingException if there are problems accessing subentries
      */
-    private void addCollectiveAttributes( Attributes entry ) throws NamingException
+    private void addCollectiveAttributes( Name name, Attributes entry ) throws NamingException
     {
-        Attribute subentries = entry.get( SubentryService.COLLECTIVE_ATTRIBUTE_SUBENTRIES
);
+        LdapDN normName = LdapDN.normalize( ( LdapDN ) name, registry.getNormalizerMapping()
);
+        Attributes entryWithCAS = nexus.lookup( normName, new String[] { "collectiveAttributeSubentries"
} );
+        Attribute subentries = entryWithCAS.get( SubentryService.COLLECTIVE_ATTRIBUTE_SUBENTRIES
);
 
         if ( subentries == null )
         {
             return;
         }
-
+        
+        
         /*
          * Before we proceed we need to lookup the exclusions within the
          * entry and build a set of exclusions for rapid lookup.  We use
@@ -186,20 +194,19 @@
     /**
      * Filter that injects collective attributes into the entry.
      *
+     * @param name name of the entry being filtered
      * @param attributes the resultant attributes with added collective attributes
      * @return true always
      */
-    private boolean filter( Attributes attributes ) throws NamingException
+    private boolean filter( Name name, Attributes attributes ) throws NamingException
     {
-        addCollectiveAttributes( attributes );
+        addCollectiveAttributes( name, attributes );
         return true;
     }
 
 
     private void filter( Name dn, Attributes entry, String[] ids ) throws NamingException
     {
-        filter( entry );
-
         // still need to return collective attrs when ids is null
         if ( ids == null )
         {
@@ -233,6 +240,49 @@
         // attributes to include - backends will automatically populate
         // with right set of attributes using ids array
     }
+    
+    private void searchFilter( Name dn, Attributes entry, String[] ids ) throws NamingException
+    {
+        // still need to return collective attrs when ids is null
+        if ( ids == null )
+        {
+            return;
+        }
+        
+        HashSet idsSet = new HashSet( ids.length );
+
+        for ( int ii = 0; ii < ids.length; ii++ )
+        {
+            idsSet.add( ids[ii].toLowerCase() );
+        }
+        
+        if ( idsSet.contains( "*" ) )
+        {
+            return;
+        }
+
+        NamingEnumeration list = entry.getIDs();
+
+        while ( list.hasMore() )
+        {
+            String attrId = ( ( String ) list.nextElement() ).toLowerCase();
+            
+            AttributeType attrType = registry.lookup( attrId );
+            if ( !attrType.isCollective() )
+            {
+                continue;
+            }
+
+            if ( !idsSet.contains( attrId ) )
+            {
+                entry.remove( attrId );
+            }
+        }
+
+        // do nothing past here since this explicity specifies which
+        // attributes to include - backends will automatically populate
+        // with right set of attributes using ids array
+    }
 
 
     // ------------------------------------------------------------------------
@@ -246,7 +296,7 @@
         {
             return null;
         }
-        filter( result );
+        filter( name, result );
         return result;
     }
     
@@ -258,7 +308,7 @@
         {
             return null;
         }
-
+        filter( name, result );
         filter( name, result, attrIds );
         return result;
     }

Modified: directory/trunks/apacheds/server-unit/src/test/java/org/apache/directory/server/SearchTest.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/server-unit/src/test/java/org/apache/directory/server/SearchTest.java?view=diff&rev=494680&r1=494679&r2=494680
==============================================================================
--- directory/trunks/apacheds/server-unit/src/test/java/org/apache/directory/server/SearchTest.java
(original)
+++ directory/trunks/apacheds/server-unit/src/test/java/org/apache/directory/server/SearchTest.java
Tue Jan  9 17:29:57 2007
@@ -21,7 +21,6 @@
 
 
 import java.util.Arrays;
-import java.util.Enumeration;
 import java.util.HashSet;
 import java.util.Hashtable;
 import java.util.Set;
@@ -834,56 +833,55 @@
     }
     
     
-//  Testcase for DIRSERVER-816
-//    public void testSearchAttrC_L() throws NamingException
-//    {
-//        // create administrative area
-//        Attributes aaAttrs = new AttributesImpl();
-//        Attribute aaObjectClass = new AttributeImpl( "objectClass" );
-//        aaObjectClass.add( "top" );
-//        aaObjectClass.add( "organizationalUnit" );
-//        aaObjectClass.add( "extensibleObject" );
-//        aaAttrs.put( aaObjectClass );
-//        aaAttrs.put( "ou", "Collective Test" );
-//        aaAttrs.put( "administrativeRole", "collectiveAttributeSpecificArea" );
-//        DirContext aaCtx = ctx.createSubcontext( "ou=Collective Area", aaAttrs );
-//        
-//        // create subentry
-//        Attributes subentry = new AttributesImpl();
-//        Attribute objectClass = new AttributeImpl( "objectClass" );
-//        objectClass.add( "top" );
-//        objectClass.add( "subentry" );
-//        objectClass.add( "collectiveAttributeSubentry" );
-//        subentry.put( objectClass );
-//        subentry.put( "c-l", "Munich" );
-//        subentry.put( "cn", "Collective Subentry" );
-//        subentry.put( "subtreeSpecification", "{ }" );
-//        aaCtx.createSubcontext( "cn=Collective Subentry", subentry );
-//        
-//        // create real enty
-//        Attributes attributes = this.getPersonAttributes( "Bush", "Kate Bush" );
-//        aaCtx.createSubcontext( "cn=Kate Bush", attributes );
-//        
-//        // search
-//        SearchControls controls = new SearchControls();
-//        controls.setSearchScope( SearchControls.ONELEVEL_SCOPE );
-//        controls.setReturningAttributes( new String[]{"c-l"} );
-//        
-//        NamingEnumeration res = aaCtx.search( "", "(cn=Kate Bush)", controls );
-//        
-//        assertTrue( res.hasMore() );
-//        
-//        SearchResult result = ( SearchResult ) res.next();
-//        
-//        // ensure that result is not null
-//        assertNotNull( result );
-//        
-//        Attributes attrs = result.getAttributes();
-//        
-//        // ensure the one and only attribute is "c-l"
-//        assertEquals( 1, attrs.size() );
-//        assertNotNull( attrs.get("c-l") );
-//        assertEquals( 1, attrs.get("c-l").size() );
-//        assertEquals( "Munich", (String)attrs.get("c-l").get() );
-//    }
+    public void testSearchAttrC_L() throws NamingException
+    {
+        // create administrative area
+        Attributes aaAttrs = new AttributesImpl();
+        Attribute aaObjectClass = new AttributeImpl( "objectClass" );
+        aaObjectClass.add( "top" );
+        aaObjectClass.add( "organizationalUnit" );
+        aaObjectClass.add( "extensibleObject" );
+        aaAttrs.put( aaObjectClass );
+        aaAttrs.put( "ou", "Collective Area" );
+        aaAttrs.put( "administrativeRole", "collectiveAttributeSpecificArea" );
+        DirContext aaCtx = ctx.createSubcontext( "ou=Collective Area", aaAttrs );
+        
+        // create subentry
+        Attributes subentry = new AttributesImpl();
+        Attribute objectClass = new AttributeImpl( "objectClass" );
+        objectClass.add( "top" );
+        objectClass.add( "subentry" );
+        objectClass.add( "collectiveAttributeSubentry" );
+        subentry.put( objectClass );
+        subentry.put( "c-l", "Munich" );
+        subentry.put( "cn", "Collective Subentry" );
+        subentry.put( "subtreeSpecification", "{ }" );
+        aaCtx.createSubcontext( "cn=Collective Subentry", subentry );
+        
+        // create real enty
+        Attributes attributes = this.getPersonAttributes( "Bush", "Kate Bush" );
+        aaCtx.createSubcontext( "cn=Kate Bush", attributes );
+        
+        // search
+        SearchControls controls = new SearchControls();
+        controls.setSearchScope( SearchControls.ONELEVEL_SCOPE );
+        controls.setReturningAttributes( new String[]{"c-l" } );
+        
+        NamingEnumeration res = aaCtx.search( "", "(cn=Kate Bush)", controls );
+        
+        assertTrue( res.hasMore() );
+        
+        SearchResult result = ( SearchResult ) res.next();
+        
+        // ensure that result is not null
+        assertNotNull( result );
+        
+        Attributes attrs = result.getAttributes();
+        
+        // ensure the one and only attribute is "c-l"
+        assertEquals( 1, attrs.size() );
+        assertNotNull( attrs.get("c-l") );
+        assertEquals( 1, attrs.get("c-l").size() );
+        assertEquals( "Munich", (String)attrs.get("c-l").get() );
+    }
 }



Mime
View raw message