directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r374956 - in /directory/sandbox/akarasulu/rc1refactor/apacheds/core/src: main/java/org/apache/ldap/server/jndi/ main/java/org/apache/ldap/server/schema/ test/java/org/apache/ldap/server/jndi/ test/java/org/apache/ldap/server/schema/
Date Sun, 05 Feb 2006 01:19:52 GMT
Author: akarasulu
Date: Sat Feb  4 17:19:47 2006
New Revision: 374956

URL: http://svn.apache.org/viewcvs?rev=374956&view=rev
Log:
DIREVE-276 work partially completed: need to test

Added:
    directory/sandbox/akarasulu/rc1refactor/apacheds/core/src/test/java/org/apache/ldap/server/schema/SchemaServiceTest.java
  (with props)
Modified:
    directory/sandbox/akarasulu/rc1refactor/apacheds/core/src/main/java/org/apache/ldap/server/jndi/LdapJndiProperties.java
    directory/sandbox/akarasulu/rc1refactor/apacheds/core/src/main/java/org/apache/ldap/server/schema/SchemaService.java
    directory/sandbox/akarasulu/rc1refactor/apacheds/core/src/test/java/org/apache/ldap/server/jndi/LdapJndiPropertiesTest.java

Modified: directory/sandbox/akarasulu/rc1refactor/apacheds/core/src/main/java/org/apache/ldap/server/jndi/LdapJndiProperties.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/akarasulu/rc1refactor/apacheds/core/src/main/java/org/apache/ldap/server/jndi/LdapJndiProperties.java?rev=374956&r1=374955&r2=374956&view=diff
==============================================================================
--- directory/sandbox/akarasulu/rc1refactor/apacheds/core/src/main/java/org/apache/ldap/server/jndi/LdapJndiProperties.java
(original)
+++ directory/sandbox/akarasulu/rc1refactor/apacheds/core/src/main/java/org/apache/ldap/server/jndi/LdapJndiProperties.java
Sat Feb  4 17:19:47 2006
@@ -1,3 +1,19 @@
+/*
+ *   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.jndi;
 
 
@@ -18,6 +34,9 @@
 /**
  * A wrapper around a JNDI environment which checks for correct LDAP specific 
  * environment settings.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev: 374647 $
  */
 public class LdapJndiProperties
 {

Modified: directory/sandbox/akarasulu/rc1refactor/apacheds/core/src/main/java/org/apache/ldap/server/schema/SchemaService.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/akarasulu/rc1refactor/apacheds/core/src/main/java/org/apache/ldap/server/schema/SchemaService.java?rev=374956&r1=374955&r2=374956&view=diff
==============================================================================
--- directory/sandbox/akarasulu/rc1refactor/apacheds/core/src/main/java/org/apache/ldap/server/schema/SchemaService.java
(original)
+++ directory/sandbox/akarasulu/rc1refactor/apacheds/core/src/main/java/org/apache/ldap/server/schema/SchemaService.java
Sat Feb  4 17:19:47 2006
@@ -48,6 +48,7 @@
 import org.apache.ldap.common.util.AttributeUtils;
 import org.apache.ldap.common.util.StringTools;
 import org.apache.ldap.common.exception.LdapAttributeInUseException;
+import org.apache.ldap.common.exception.LdapNamingException;
 import org.apache.ldap.common.exception.LdapSchemaViolationException;
 import org.apache.ldap.common.exception.LdapInvalidAttributeIdentifierException;
 import org.apache.ldap.common.exception.LdapNoSuchAttributeException;
@@ -506,6 +507,57 @@
                 throw new InternalError( "" );
         }
     }
+    
+    
+    /**
+     * Given the objectClasses for an entry, this method adds missing ancestors 
+     * in the hierarchy except for top which it removes.  This is used for this
+     * solution to DIREVE-276.  More information about this solution can be found
+     * <a href="http://docs.safehaus.org:8080/x/kBE">here</a>.
+     * 
+     * @param objectClassAttr the objectClass attribute to modify
+     * @throws NamingException if there are problems 
+     */
+    public static void alterObjectClasses( Attribute objectClassAttr, ObjectClassRegistry
registry ) throws NamingException
+    {
+        if ( ! objectClassAttr.getID().equalsIgnoreCase( "objectClass" ) )
+        {
+            throw new LdapNamingException( "Expecting an objectClass attribute but got "
+ objectClassAttr.getID(), 
+                ResultCodeEnum.OPERATIONSERROR );
+        }
+        
+        Set objectClasses = new HashSet();
+        for ( int ii = 0; ii < objectClassAttr.size(); ii++ )
+        {
+            String val = ( String ) objectClassAttr.get( ii );
+            if ( ! val.equalsIgnoreCase( "top" ) )
+            {
+                objectClasses.add( val.toLowerCase() );
+            }
+        }
+        
+        for ( int ii = 0; ii < objectClassAttr.size(); ii++ )
+        {
+            String val = ( String ) objectClassAttr.get( ii );
+            if ( val.equalsIgnoreCase( "top" ) )
+            {
+                objectClassAttr.remove( val );
+            }
+            
+            ObjectClass objectClass = registry.lookup( val );
+            
+            // cannot use Collections.addAll(Collection, Object[]) since it's 1.5
+            ObjectClass top = registry.lookup( "top" );
+            ObjectClass[] superiors = objectClass.getSuperClasses();
+            for ( int jj = 0; jj < superiors.length; jj++ )
+            {
+                if ( superiors[jj] != top && ! objectClasses.contains( superiors[jj].getName().toLowerCase()
) )
+                {
+                    objectClassAttr.add( superiors[jj].getName() );
+                }
+            }
+        }
+    }
 
 
     public void modify( NextInterceptor next, Name name, int modOp, Attributes mods ) throws
NamingException
@@ -553,6 +605,54 @@
             SchemaChecker.preventStructuralClassRemovalOnModifyReplace( ocRegistry, name,
modOp, mods );
         }
 
+        // let's figure out if we need to add or take away from mods to maintain 
+        // the objectClass attribute with it's hierarchy of ancestors 
+        if ( mods.get( "objectClass" ) != null )
+        {
+            Attribute alteredObjectClass = ( Attribute ) objectClass.clone();
+            alterObjectClasses( alteredObjectClass, ocRegistry );
+            
+            if ( ! alteredObjectClass.equals( objectClass ) )
+            {
+                Attribute ocMods = mods.get( "objectClass" );
+                switch( modOp )
+                {
+                    case( DirContext.ADD_ATTRIBUTE ):
+                        if ( ocMods.contains( "top" ) )
+                        {
+                            ocMods.remove( "top" );
+                        }
+                        for ( int ii = 0; ii < alteredObjectClass.size(); ii++ )
+                        {
+                            if ( ! objectClass.contains( alteredObjectClass.get( ii ) ) )
+                            {
+                                ocMods.add( alteredObjectClass.get( ii ) );
+                            }
+                        }
+                        break;
+                    case( DirContext.REMOVE_ATTRIBUTE ):
+                        for ( int ii = 0; ii < alteredObjectClass.size(); ii++ )
+                        {
+                            if ( ! objectClass.contains( alteredObjectClass.get( ii ) ) )
+                            {
+                                ocMods.remove( alteredObjectClass.get( ii ) );
+                            }
+                        }
+                        break;
+                    case( DirContext.REPLACE_ATTRIBUTE ):
+                        for ( int ii = 0; ii < alteredObjectClass.size(); ii++ )
+                        {
+                            if ( ! objectClass.contains( alteredObjectClass.get( ii ) ) )
+                            {
+                                ocMods.add( alteredObjectClass.get( ii ) );
+                            }
+                        }
+                        break;
+                    default:
+                }
+            }
+        }
+        
         next.modify( name, modOp, mods );
     }
 
@@ -632,31 +732,87 @@
             }
         }
 
+        // let's figure out if we need to add or take away from mods to maintain 
+        // the objectClass attribute with it's hierarchy of ancestors 
+        if ( objectClassMod != null )
+        {
+            Attribute alteredObjectClass = ( Attribute ) objectClass.clone();
+            alterObjectClasses( alteredObjectClass, ocRegistry );
+            
+            if ( ! alteredObjectClass.equals( objectClass ) )
+            {
+                Attribute ocMods = objectClassMod.getAttribute();
+                switch( objectClassMod.getModificationOp() )
+                {
+                    case( DirContext.ADD_ATTRIBUTE ):
+                        if ( ocMods.contains( "top" ) )
+                        {
+                            ocMods.remove( "top" );
+                        }
+                        for ( int ii = 0; ii < alteredObjectClass.size(); ii++ )
+                        {
+                            if ( ! objectClass.contains( alteredObjectClass.get( ii ) ) )
+                            {
+                                ocMods.add( alteredObjectClass.get( ii ) );
+                            }
+                        }
+                        break;
+                    case( DirContext.REMOVE_ATTRIBUTE ):
+                        for ( int ii = 0; ii < alteredObjectClass.size(); ii++ )
+                        {
+                            if ( ! objectClass.contains( alteredObjectClass.get( ii ) ) )
+                            {
+                                ocMods.remove( alteredObjectClass.get( ii ) );
+                            }
+                        }
+                        break;
+                    case( DirContext.REPLACE_ATTRIBUTE ):
+                        for ( int ii = 0; ii < alteredObjectClass.size(); ii++ )
+                        {
+                            if ( ! objectClass.contains( alteredObjectClass.get( ii ) ) )
+                            {
+                                ocMods.add( alteredObjectClass.get( ii ) );
+                            }
+                        }
+                        break;
+                    default:
+                }
+            }
+        }
+
         next.modify( name, mods );
     }
 
 
     private void doFilter( Attributes entry ) throws NamingException
     {
-        long t0 = System.currentTimeMillis();
+        long t0 = -1;
         
         if ( log.isDebugEnabled() )
         {
+            t0 = System.currentTimeMillis();
             log.debug( "Filtering entry " + AttributeUtils.toString( entry ) );  
         }
         
+        // add top if objectClass is included and missing top
+        Attribute oc = entry.get( "objectClass" );
+        if ( oc != null )
+        {
+            if ( ! oc.contains( "top" ) )
+            {
+                oc.add( "top" );
+            }
+        }
+        
         /*
          * start converting values of attributes to byte[]s which are not
          * human readable and those that are in the binaries set
          */
         NamingEnumeration list = entry.getIDs();
-
         while ( list.hasMore() )
         {
             String id = ( String ) list.next();
-
             AttributeType type = null;
-
             boolean asBinary = false;
 
             if ( globalRegistries.getAttributeTypeRegistry().hasAttributeType( id ) )
@@ -667,20 +823,16 @@
             if ( type != null )
             {
                 asBinary = !type.getSyntax().isHumanReadible();
-
                 asBinary = asBinary || binaries.contains( type );
             }
 
             if ( asBinary )
             {
                 Attribute attribute = entry.get( id );
-
                 Attribute binary = new LockableAttributeImpl( id );
-
                 for ( int i = 0; i < attribute.size(); i++ )
                 {
                     Object value = attribute.get( i );
-
                     if ( value instanceof String )
                     {
                         binary.add( i, StringTools.getBytesUtf8( ( String ) value ) );
@@ -692,16 +844,14 @@
                 }
 
                 entry.remove( id );
-
                 entry.put( binary );
             }
         }
         
-        long t1 = System.currentTimeMillis();
-        
         if ( log.isDebugEnabled() )
         {
-            log.debug( "Time to filter entry = " + (t1 - t0) + "ns" );
+            long t1 = System.currentTimeMillis();
+            log.debug( "Time to filter entry = " + (t1 - t0) + " ms" );
         }
     }
 
@@ -716,11 +866,6 @@
      */
     private class BinaryAttributeFilter implements SearchResultFilter
     {
-        public BinaryAttributeFilter()
-        {
-        }
-
-
         public boolean accept( Invocation invocation, SearchResult result, SearchControls
controls ) throws NamingException
         {
             doFilter( result.getAttributes() );
@@ -734,19 +879,17 @@
     public void add( NextInterceptor next, String upName, Name normName, Attributes attrs
) throws NamingException
     {
         AttributeTypeRegistry atRegistry = this.globalRegistries.getAttributeTypeRegistry();
-
         NamingEnumeration attrEnum = attrs.getIDs();
-        
-        while ( attrEnum.hasMoreElements())
+        while ( attrEnum.hasMoreElements() )
         {
             String name = (String)attrEnum.nextElement();
-
             if ( ! atRegistry.hasAttributeType( name ) )
             {
                 throw new LdapInvalidAttributeIdentifierException();
             }
         }
-
+        
+        alterObjectClasses( attrs.get( "objectClass" ), this.globalRegistries.getObjectClassRegistry()
);
         next.add( upName, normName, attrs );
     }
 }

Modified: directory/sandbox/akarasulu/rc1refactor/apacheds/core/src/test/java/org/apache/ldap/server/jndi/LdapJndiPropertiesTest.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/akarasulu/rc1refactor/apacheds/core/src/test/java/org/apache/ldap/server/jndi/LdapJndiPropertiesTest.java?rev=374956&r1=374955&r2=374956&view=diff
==============================================================================
--- directory/sandbox/akarasulu/rc1refactor/apacheds/core/src/test/java/org/apache/ldap/server/jndi/LdapJndiPropertiesTest.java
(original)
+++ directory/sandbox/akarasulu/rc1refactor/apacheds/core/src/test/java/org/apache/ldap/server/jndi/LdapJndiPropertiesTest.java
Sat Feb  4 17:19:47 2006
@@ -1,3 +1,19 @@
+/*
+ *   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.jndi;
  
 
@@ -13,6 +29,12 @@
 import junit.framework.TestCase;
 
 
+/**
+ * Tests the LdapJndiProperties.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev: 374647 $
+ */
 public class LdapJndiPropertiesTest extends TestCase
 {
     public void testEmptyEnv() throws Exception

Added: directory/sandbox/akarasulu/rc1refactor/apacheds/core/src/test/java/org/apache/ldap/server/schema/SchemaServiceTest.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/akarasulu/rc1refactor/apacheds/core/src/test/java/org/apache/ldap/server/schema/SchemaServiceTest.java?rev=374956&view=auto
==============================================================================
--- directory/sandbox/akarasulu/rc1refactor/apacheds/core/src/test/java/org/apache/ldap/server/schema/SchemaServiceTest.java
(added)
+++ directory/sandbox/akarasulu/rc1refactor/apacheds/core/src/test/java/org/apache/ldap/server/schema/SchemaServiceTest.java
Sat Feb  4 17:19:47 2006
@@ -0,0 +1,137 @@
+/*
+ *   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.schema;
+
+import javax.naming.NamingException;
+import javax.naming.directory.Attribute;
+import javax.naming.directory.BasicAttribute;
+
+import org.apache.ldap.common.exception.LdapNamingException;
+import org.apache.ldap.common.message.ResultCodeEnum;
+import org.apache.ldap.server.schema.bootstrap.ApacheSchema;
+import org.apache.ldap.server.schema.bootstrap.BootstrapRegistries;
+import org.apache.ldap.server.schema.bootstrap.BootstrapSchemaLoader;
+import org.apache.ldap.server.schema.bootstrap.CoreSchema;
+import org.apache.ldap.server.schema.bootstrap.CosineSchema;
+import org.apache.ldap.server.schema.bootstrap.InetorgpersonSchema;
+import org.apache.ldap.server.schema.bootstrap.SystemSchema;
+
+import junit.framework.TestCase;
+
+
+/**
+ * Tests methods in SchemaService.
+ * 
+ */
+public class SchemaServiceTest extends TestCase
+{
+    ObjectClassRegistry registry = null;
+    
+    
+    public void setUp() throws Exception
+    {
+        if ( registry != null )
+        {
+            return;
+        }
+        
+        BootstrapRegistries registries = new BootstrapRegistries();
+        BootstrapSchemaLoader loader = new BootstrapSchemaLoader();
+        loader.load( new ApacheSchema(), registries );
+        loader.load( new CoreSchema(), registries );
+        loader.load( new CosineSchema(), registries );
+        loader.load( new InetorgpersonSchema(), registries );
+        loader.load( new SystemSchema(), registries );
+        registry = registries.getObjectClassRegistry();
+    }
+    
+    
+    public void testAlterObjectClassesBogusAttr() throws NamingException 
+    {
+        Attribute attr = new BasicAttribute( "blah", "blah" );
+        
+        try
+        {
+            SchemaService.alterObjectClasses( attr, registry );
+            fail( "should not get here" );
+        }
+        catch ( LdapNamingException e )
+        {
+            assertEquals( ResultCodeEnum.OPERATIONSERROR, e.getResultCode() );
+        }
+
+        attr = new BasicAttribute( "objectClass" );
+        SchemaService.alterObjectClasses( attr, registry );
+        assertEquals( 0, attr.size() );
+    }
+    
+    
+    public void testAlterObjectClassesNoAttrValue() throws NamingException 
+    {
+        Attribute attr = new BasicAttribute( "objectClass" );
+        SchemaService.alterObjectClasses( attr, registry );
+        assertEquals( 0, attr.size() );
+    }
+    
+    
+    public void testAlterObjectClassesTopAttrValue() throws NamingException 
+    {
+        Attribute attr = new BasicAttribute( "objectClass", "top" );
+        SchemaService.alterObjectClasses( attr, registry );
+        assertEquals( 0, attr.size() );
+    }
+    
+    
+    public void testAlterObjectClassesInetOrgPersonAttrValue() throws NamingException 
+    {
+        Attribute attr = new BasicAttribute( "objectClass", "inetOrgPerson" );
+        SchemaService.alterObjectClasses( attr, registry );
+        assertEquals( 3, attr.size() );
+        assertTrue( attr.contains( "person" ) );
+        assertTrue( attr.contains( "organizationalPerson" ) );
+        assertTrue( attr.contains( "inetOrgPerson" ) );
+    }
+
+
+    public void testAlterObjectClassesOverlapping() throws NamingException 
+    {
+        Attribute attr = new BasicAttribute( "objectClass", "inetOrgPerson" );
+        attr.add( "residentialPerson" );
+        SchemaService.alterObjectClasses( attr, registry );
+        assertEquals( 4, attr.size() );
+        assertTrue( attr.contains( "person" ) );
+        assertTrue( attr.contains( "organizationalPerson" ) );
+        assertTrue( attr.contains( "inetOrgPerson" ) );
+        assertTrue( attr.contains( "residentialPerson" ) );
+    }
+
+
+    public void testAlterObjectClassesOverlappingAndDsa() throws NamingException 
+    {
+        Attribute attr = new BasicAttribute( "objectClass", "inetOrgPerson" );
+        attr.add( "residentialPerson" );
+        attr.add( "dSA" );
+        SchemaService.alterObjectClasses( attr, registry );
+        assertEquals( 6, attr.size() );
+        assertTrue( attr.contains( "person" ) );
+        assertTrue( attr.contains( "organizationalPerson" ) );
+        assertTrue( attr.contains( "inetOrgPerson" ) );
+        assertTrue( attr.contains( "residentialPerson" ) );
+        assertTrue( attr.contains( "dSA" ) );
+        assertTrue( attr.contains( "applicationEntity" ) );
+    }
+}

Propchange: directory/sandbox/akarasulu/rc1refactor/apacheds/core/src/test/java/org/apache/ldap/server/schema/SchemaServiceTest.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message