directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ersi...@apache.org
Subject svn commit: r507250 - in /directory/apacheds/branches/1.0: core-unit/src/test/java/org/apache/directory/server/core/subtree/SubentryServiceObjectClassChangeHandlingITest.java core/src/main/java/org/apache/directory/server/core/subtree/SubentryService.java
Date Tue, 13 Feb 2007 21:55:40 GMT
Author: ersiner
Date: Tue Feb 13 13:55:39 2007
New Revision: 507250

URL: http://svn.apache.org/viewvc?view=rev&rev=507250
Log:
Fixed DIRSERVER-784.
Ported the fix from 1.5 fix and had serious pbs. But all are OK now.
Also added test cases for the fix.

Added:
    directory/apacheds/branches/1.0/core-unit/src/test/java/org/apache/directory/server/core/subtree/SubentryServiceObjectClassChangeHandlingITest.java
Modified:
    directory/apacheds/branches/1.0/core/src/main/java/org/apache/directory/server/core/subtree/SubentryService.java

Added: directory/apacheds/branches/1.0/core-unit/src/test/java/org/apache/directory/server/core/subtree/SubentryServiceObjectClassChangeHandlingITest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/1.0/core-unit/src/test/java/org/apache/directory/server/core/subtree/SubentryServiceObjectClassChangeHandlingITest.java?view=auto&rev=507250
==============================================================================
--- directory/apacheds/branches/1.0/core-unit/src/test/java/org/apache/directory/server/core/subtree/SubentryServiceObjectClassChangeHandlingITest.java
(added)
+++ directory/apacheds/branches/1.0/core-unit/src/test/java/org/apache/directory/server/core/subtree/SubentryServiceObjectClassChangeHandlingITest.java
Tue Feb 13 13:55:39 2007
@@ -0,0 +1,145 @@
+/*
+ *  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.subtree;
+
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
+import javax.naming.directory.Attribute;
+import javax.naming.directory.Attributes;
+import javax.naming.directory.BasicAttribute;
+import javax.naming.directory.BasicAttributes;
+import javax.naming.directory.DirContext;
+import javax.naming.directory.SearchControls;
+import javax.naming.directory.SearchResult;
+
+import org.apache.directory.server.core.unit.AbstractAdminTestCase;
+import org.apache.directory.shared.ldap.message.ModificationItemImpl;
+
+
+/**
+ * Testcases for the SubentryService. Investigation on handling Subtree Refinement
+ * Selection Membership upon objectClass attribute value changes.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class SubentryServiceObjectClassChangeHandlingITest extends AbstractAdminTestCase
+{
+    public Attributes getTestEntry( String cn )
+    {
+        Attributes entry = new BasicAttributes( true );
+        Attribute objectClass = new BasicAttribute( "objectClass" );
+        objectClass.add( "top" );
+        objectClass.add( "person" );
+        entry.put( objectClass );
+        entry.put( "cn", cn );
+        entry.put( "sn", cn );
+        return entry;
+    }
+
+
+    public Attributes getModsForIntroducingNewOC() throws NamingException
+    {
+        Attributes changes = new BasicAttributes( true );
+        Attribute objectClass = new BasicAttribute( "objectClass" );
+        objectClass.add( "organizationalPerson" );
+        changes.put( objectClass );
+        changes.put( "ou", "Test Organizational Unit" );
+        return changes;
+    }
+
+
+    public Attributes getCollectiveAttributeTestSubentry( String cn )
+    {
+        Attributes subentry = new BasicAttributes( true );
+        Attribute objectClass = new BasicAttribute( "objectClass" );
+        objectClass.add( "top" );
+        objectClass.add( "subentry" );
+        objectClass.add( "collectiveAttributeSubentry" );
+        subentry.put( objectClass );
+        subentry.put( "subtreeSpecification", "{ specificationFilter item:organizationalPerson
}" );
+        subentry.put( "c-o", "Test Org" );
+        subentry.put( "cn", cn );
+        return subentry;
+    }
+
+
+    public void addAdministrativeRoles() throws NamingException
+    {
+        Attribute attribute = new BasicAttribute( "administrativeRole" );
+        attribute.add( "autonomousArea" );
+        attribute.add( "collectiveAttributeSpecificArea" );
+        ModificationItemImpl item = new ModificationItemImpl( DirContext.ADD_ATTRIBUTE, attribute
);
+        super.sysRoot.modifyAttributes( "", new ModificationItemImpl[]
+            { 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 void testTrackingOfOCChangesInSubentryServiceModifyRoutine() throws Exception
+    {
+        addAdministrativeRoles();
+        super.sysRoot.createSubcontext( "cn=collectiveAttributeTestSubentry",
+            getCollectiveAttributeTestSubentry( "collectiveAttributeTestSubentry" ) );
+        super.sysRoot.createSubcontext( "cn=testEntry", getTestEntry( "testEntry" ) );
+
+        //----------------------------------------------------------------------
+
+        Map results = getAllEntries();
+        Attributes testEntry = ( Attributes ) results.get( "cn=testEntry,ou=system" );
+
+        Attribute collectiveAttributeSubentries = testEntry.get( "collectiveAttributeSubentries"
);
+        
+        assertNull( collectiveAttributeSubentries );
+
+        //----------------------------------------------------------------------
+
+        super.sysRoot.modifyAttributes( "cn=testEntry", DirContext.ADD_ATTRIBUTE, getModsForIntroducingNewOC()
);
+
+        results = getAllEntries();
+        testEntry = ( Attributes ) results.get( "cn=testEntry,ou=system" );
+
+        collectiveAttributeSubentries = testEntry.get( "collectiveAttributeSubentries" );
+
+        assertNotNull( collectiveAttributeSubentries );
+    }
+
+}

Modified: directory/apacheds/branches/1.0/core/src/main/java/org/apache/directory/server/core/subtree/SubentryService.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/1.0/core/src/main/java/org/apache/directory/server/core/subtree/SubentryService.java?view=diff&rev=507250&r1=507249&r2=507250
==============================================================================
--- directory/apacheds/branches/1.0/core/src/main/java/org/apache/directory/server/core/subtree/SubentryService.java
(original)
+++ directory/apacheds/branches/1.0/core/src/main/java/org/apache/directory/server/core/subtree/SubentryService.java
Tue Feb 13 13:55:39 2007
@@ -57,6 +57,8 @@
 
 import javax.naming.directory.Attribute;
 import javax.naming.directory.Attributes;
+import javax.naming.directory.BasicAttribute;
+import javax.naming.directory.BasicAttributes;
 import javax.naming.directory.DirContext;
 import javax.naming.directory.SearchControls;
 import javax.naming.directory.SearchResult;
@@ -934,6 +936,7 @@
     public void modify( NextInterceptor next, LdapDN name, int modOp, Attributes mods ) throws
NamingException
     {
         Attributes entry = nexus.lookup( name );
+        Attributes oldEntry = (Attributes) AttributeUtils.toAttributesImpl( entry ).clone();
         Attribute objectClasses = ServerUtils.getAttribute( objectClassType, entry );
 
         if ( AttributeUtils.containsValueCaseIgnore( objectClasses, "subentry" ) &&
mods.get( "subtreeSpecification" ) != null )
@@ -1001,6 +1004,17 @@
         else
         {
             next.modify( name, modOp, mods );
+            
+            if ( !AttributeUtils.containsValueCaseIgnore( objectClasses, "subentry" ) )
+            {
+                Attributes newEntry = nexus.lookup( name );
+                
+                ModificationItemImpl[] subentriesOpAttrMods =  getModsOnEntryModification(name,
oldEntry, newEntry);
+                if ( subentriesOpAttrMods.length > 0)
+                {
+                    nexus.modify(name, subentriesOpAttrMods);
+                }
+            }
         }
     }
 
@@ -1008,6 +1022,7 @@
     public void modify( NextInterceptor next, LdapDN name, ModificationItemImpl[] mods )
throws NamingException
     {
         Attributes entry = nexus.lookup( name );
+        Attributes oldEntry = (Attributes) AttributeUtils.toAttributesImpl( entry ).clone();
         Attribute objectClasses = ServerUtils.getAttribute( objectClassType, entry );
         boolean isSubtreeSpecificationModification = false;
         ModificationItemImpl subtreeMod = null;
@@ -1086,6 +1101,17 @@
         else
         {
             next.modify( name, mods );
+            
+            if ( !AttributeUtils.containsValueCaseIgnore( objectClasses, "subentry" ) )
+            {
+                Attributes newEntry = nexus.lookup( name );
+                
+                ModificationItemImpl[] subentriesOpAttrMods =  getModsOnEntryModification(name,
oldEntry, newEntry);
+                if ( subentriesOpAttrMods.length > 0)
+                {
+                    nexus.modify(name, subentriesOpAttrMods);
+                }
+            }
         }
     }
 
@@ -1411,5 +1437,65 @@
             name.addAll( rest );
             return subentryCache.hasSubentry( name.toNormName() );
         }
+    }
+    
+    
+    private ModificationItemImpl[] getModsOnEntryModification( LdapDN name, Attributes oldEntry,
Attributes newEntry )
+    throws NamingException
+    {
+        List modList = new ArrayList();
+    
+        Iterator subentries = subentryCache.nameIterator();
+        while ( subentries.hasNext() )
+        {
+            String subentryDn = ( String ) subentries.next();
+            Name apDn = new LdapDN( subentryDn );
+            apDn.remove( apDn.size() - 1 );
+            SubtreeSpecification ss = subentryCache.getSubentry( subentryDn ).getSubtreeSpecification();
+            boolean isOldEntrySelected = evaluator.evaluate( ss, apDn, name, oldEntry.get(
"objectClass" ) );
+            boolean isNewEntrySelected = evaluator.evaluate( ss, apDn, name, newEntry.get(
"objectClass" ) );
+    
+            if ( isOldEntrySelected == isNewEntrySelected )
+            {
+                continue;
+            }
+    
+            // need to remove references to the subentry
+            if ( isOldEntrySelected && !isNewEntrySelected )
+            {
+                for ( int ii = 0; ii < SUBENTRY_OPATTRS.length; ii++ )
+                {
+                    int op = DirContext.REPLACE_ATTRIBUTE;
+                    Attribute opAttr = oldEntry.get( SUBENTRY_OPATTRS[ii] );
+                    if ( opAttr != null )
+                    {
+                        opAttr = ( Attribute ) opAttr.clone();
+                        opAttr.remove( subentryDn );
+    
+                        if ( opAttr.size() < 1 )
+                        {
+                            op = DirContext.REMOVE_ATTRIBUTE;
+                        }
+    
+                        modList.add( new ModificationItemImpl( op, opAttr ) );
+                    }
+                }
+            }
+            // need to add references to the subentry
+            else if ( isNewEntrySelected && !isOldEntrySelected )
+            {
+                for ( int ii = 0; ii < SUBENTRY_OPATTRS.length; ii++ )
+                {
+                    int op = DirContext.ADD_ATTRIBUTE;
+                    Attribute opAttr = new BasicAttribute( SUBENTRY_OPATTRS[ii] );
+                    opAttr.add( subentryDn );
+                    modList.add( new ModificationItemImpl( op, opAttr ) );
+                }
+            }
+        }
+    
+        ModificationItemImpl[] mods = new ModificationItemImpl[modList.size()];
+        mods = (ModificationItemImpl[]) modList.toArray( mods );
+        return mods;
     }
 }



Mime
View raw message