directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r375337 - in /directory/trunks/apacheds: core-unit/src/test/java/org/apache/ldap/server/core/ core-unit/src/test/java/org/apache/ldap/server/core/schema/ core-unit/src/test/java/org/apache/ldap/server/jndi/ core-unit/src/test/resources/org/...
Date Mon, 06 Feb 2006 19:15:25 GMT
Author: akarasulu
Date: Mon Feb  6 11:15:22 2006
New Revision: 375337

URL: http://svn.apache.org/viewcvs?rev=375337&view=rev
Log:
merging back changes in rc1refactor branch ...

 o fix for DIREVE-276
 o clean up tests
 o add tests for DIREVE-276
 o cleaned up test entry handling in DiectoryService
 o cleaned up some system.outs


Added:
    directory/trunks/apacheds/core-unit/src/test/java/org/apache/ldap/server/core/
      - copied from r375336, directory/sandbox/akarasulu/rc1refactor/apacheds/core-unit/src/test/java/org/apache/ldap/server/core/
    directory/trunks/apacheds/core-unit/src/test/java/org/apache/ldap/server/core/schema/
      - copied from r375336, directory/sandbox/akarasulu/rc1refactor/apacheds/core-unit/src/test/java/org/apache/ldap/server/core/schema/
    directory/trunks/apacheds/core-unit/src/test/java/org/apache/ldap/server/core/schema/SchemaServiceTest.java
  (props changed)
      - copied unchanged from r375336, directory/sandbox/akarasulu/rc1refactor/apacheds/core-unit/src/test/java/org/apache/ldap/server/core/schema/SchemaServiceTest.java
    directory/trunks/apacheds/core-unit/src/test/resources/org/
      - copied from r375336, directory/sandbox/akarasulu/rc1refactor/apacheds/core-unit/src/test/resources/org/
    directory/trunks/apacheds/core-unit/src/test/resources/org/apache/
      - copied from r375336, directory/sandbox/akarasulu/rc1refactor/apacheds/core-unit/src/test/resources/org/apache/
    directory/trunks/apacheds/core-unit/src/test/resources/org/apache/ldap/
      - copied from r375336, directory/sandbox/akarasulu/rc1refactor/apacheds/core-unit/src/test/resources/org/apache/ldap/
    directory/trunks/apacheds/core-unit/src/test/resources/org/apache/ldap/server/
      - copied from r375336, directory/sandbox/akarasulu/rc1refactor/apacheds/core-unit/src/test/resources/org/apache/ldap/server/
    directory/trunks/apacheds/core-unit/src/test/resources/org/apache/ldap/server/core/
      - copied from r375336, directory/sandbox/akarasulu/rc1refactor/apacheds/core-unit/src/test/resources/org/apache/ldap/server/core/
    directory/trunks/apacheds/core-unit/src/test/resources/org/apache/ldap/server/core/schema/
      - copied from r375336, directory/sandbox/akarasulu/rc1refactor/apacheds/core-unit/src/test/resources/org/apache/ldap/server/core/schema/
    directory/trunks/apacheds/core-unit/src/test/resources/org/apache/ldap/server/core/schema/nonspecific.ldif
  (props changed)
      - copied unchanged from r375336, directory/sandbox/akarasulu/rc1refactor/apacheds/core-unit/src/test/resources/org/apache/ldap/server/core/schema/nonspecific.ldif
    directory/trunks/apacheds/core/src/test/java/org/apache/ldap/server/schema/SchemaServiceTest.java
  (props changed)
      - copied unchanged from r375336, directory/sandbox/akarasulu/rc1refactor/apacheds/core/src/test/java/org/apache/ldap/server/schema/SchemaServiceTest.java
Modified:
    directory/trunks/apacheds/core-unit/src/test/java/org/apache/ldap/server/jndi/ReferralTest.java
    directory/trunks/apacheds/core/src/main/java/org/apache/ldap/server/DefaultDirectoryService.java
    directory/trunks/apacheds/core/src/main/java/org/apache/ldap/server/jndi/AbstractContextFactory.java
    directory/trunks/apacheds/core/src/main/java/org/apache/ldap/server/jndi/LdapJndiProperties.java
    directory/trunks/apacheds/core/src/main/java/org/apache/ldap/server/schema/SchemaService.java
    directory/trunks/apacheds/core/src/test/java/org/apache/ldap/server/jndi/LdapJndiPropertiesTest.java
    directory/trunks/apacheds/simple/jndi/src/main/java/org/apache/ldap/server/jndi/ServerContextFactory.java
    directory/trunks/apacheds/simple/unit/src/main/java/org/apache/ldap/server/AbstractServerTest.java
    directory/trunks/apacheds/simple/unit/src/test/java/org/apache/ldap/server/ReferralTest.java

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

Modified: directory/trunks/apacheds/core-unit/src/test/java/org/apache/ldap/server/jndi/ReferralTest.java
URL: http://svn.apache.org/viewcvs/directory/trunks/apacheds/core-unit/src/test/java/org/apache/ldap/server/jndi/ReferralTest.java?rev=375337&r1=375336&r2=375337&view=diff
==============================================================================
--- directory/trunks/apacheds/core-unit/src/test/java/org/apache/ldap/server/jndi/ReferralTest.java
(original)
+++ directory/trunks/apacheds/core-unit/src/test/java/org/apache/ldap/server/jndi/ReferralTest.java
Mon Feb  6 11:15:22 2006
@@ -898,7 +898,6 @@
         while ( list.hasMore() )
         {
             SearchResult result = ( SearchResult) list.next();
-            System.out.println( "name = " + result.getName() + " results .. " + result );
             results.put ( result.getName(), result );
         }
         
@@ -917,7 +916,6 @@
             while ( list.hasMore() )
             {
                 SearchResult result = ( SearchResult ) list.next();
-                System.out.println( "name = " + result.getName() + " results .. " + result
);
                 results.put ( result.getName(), result );
             }
         }
@@ -944,7 +942,6 @@
             while ( list.hasMore() )
             {
                 SearchResult result = ( SearchResult ) list.next();
-                System.out.println( "name = " + result.getName() + " results .. " + result
);
                 results.put ( result.getName(), result );
             }
         }

Propchange: directory/trunks/apacheds/core-unit/src/test/resources/org/apache/ldap/server/core/schema/nonspecific.ldif
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: directory/trunks/apacheds/core/src/main/java/org/apache/ldap/server/DefaultDirectoryService.java
URL: http://svn.apache.org/viewcvs/directory/trunks/apacheds/core/src/main/java/org/apache/ldap/server/DefaultDirectoryService.java?rev=375337&r1=375336&r2=375337&view=diff
==============================================================================
--- directory/trunks/apacheds/core/src/main/java/org/apache/ldap/server/DefaultDirectoryService.java
(original)
+++ directory/trunks/apacheds/core/src/main/java/org/apache/ldap/server/DefaultDirectoryService.java
Mon Feb  6 11:15:22 2006
@@ -37,9 +37,7 @@
 import org.apache.ldap.common.message.LockableAttributesImpl;
 import org.apache.ldap.common.message.ResultCodeEnum;
 import org.apache.ldap.common.name.DnOidContainer;
-import org.apache.ldap.common.name.DnParser;
 import org.apache.ldap.common.name.LdapName;
-import org.apache.ldap.common.name.NameComponentNormalizer;
 import org.apache.ldap.common.util.DateUtils;
 import org.apache.ldap.common.util.StringTools;
 import org.apache.ldap.common.schema.AttributeType;
@@ -50,15 +48,16 @@
 import org.apache.ldap.server.configuration.ConfigurationException;
 import org.apache.ldap.server.configuration.StartupConfiguration;
 import org.apache.ldap.server.interceptor.InterceptorChain;
+import org.apache.ldap.server.jndi.AbstractContextFactory;
 import org.apache.ldap.server.jndi.DeadContext;
 import org.apache.ldap.server.jndi.ServerLdapContext;
 import org.apache.ldap.server.partition.DefaultDirectoryPartitionNexus;
 import org.apache.ldap.server.partition.DirectoryPartitionNexus;
 import org.apache.ldap.server.schema.AttributeTypeRegistry;
-import org.apache.ldap.server.schema.ConcreteNameComponentNormalizer;
 import org.apache.ldap.server.schema.GlobalRegistries;
 import org.apache.ldap.server.schema.bootstrap.BootstrapRegistries;
 import org.apache.ldap.server.schema.bootstrap.BootstrapSchemaLoader;
+
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -223,9 +222,12 @@
         initialize();
         firstStart = createBootstrapEntries();
         showSecurityWarnings();
-        createTestEntries();
         this.serviceListener = listener;
         started = true;
+        if ( ! startupConfiguration.getTestEntries().isEmpty() )
+        {
+            createTestEntries( env );
+        }
         listener.afterStartup( this );
     }
 
@@ -640,28 +642,28 @@
         }
     }
     
-    private void createTestEntries() throws NamingException
+    private void createTestEntries( Hashtable env ) throws NamingException
     {
-        /*
-         * Unfortunately to test non-root user startup of the core and make sure
-         * all the appropriate functionality is there we need to load more user
-         * entries at startup due to a chicken and egg like problem.  The value
-         * of this property is a list of attributes to be added.
-         */
+        String principal = AbstractContextFactory.getPrincipal( env );
+        byte[] credential = AbstractContextFactory.getCredential( env );
+        String authentication = AbstractContextFactory.getAuthentication( env );
+        ServerLdapContext ctx = ( ServerLdapContext ) getJndiContext( principal, credential,

+            authentication, "" );
+        
         Iterator i = startupConfiguration.getTestEntries().iterator();
         while( i.hasNext() )
         {
-            Attributes entry = ( Attributes ) i.next();
-            entry.put( "creatorsName", DirectoryPartitionNexus.ADMIN_PRINCIPAL );
-            entry.put( "createTimestamp", DateUtils.getGeneralizedTime() );
+            Attributes entry = ( Attributes ) ( ( Attributes ) i.next() ).clone();
+            String dn = ( String ) entry.remove( "dn" ).get();
             
-            Attribute dn = ( Attribute ) entry.get( "dn" ).clone();
-            AttributeTypeRegistry registry = globalRegistries.getAttributeTypeRegistry();
-            NameComponentNormalizer ncn = new ConcreteNameComponentNormalizer( registry );
-            DnParser parser = new DnParser( ncn );
-            Name ndn = parser.parse( ( String ) dn.get() );
-            
-            partitionNexus.add( ( String ) dn.get(), ndn, entry );
+            try
+            {
+                ctx.createSubcontext( dn, entry );
+            }
+            catch ( Exception e )
+            {
+                log.warn( dn + " test entry already exists.", e );
+            }
         }
     }
 

Modified: directory/trunks/apacheds/core/src/main/java/org/apache/ldap/server/jndi/AbstractContextFactory.java
URL: http://svn.apache.org/viewcvs/directory/trunks/apacheds/core/src/main/java/org/apache/ldap/server/jndi/AbstractContextFactory.java?rev=375337&r1=375336&r2=375337&view=diff
==============================================================================
--- directory/trunks/apacheds/core/src/main/java/org/apache/ldap/server/jndi/AbstractContextFactory.java
(original)
+++ directory/trunks/apacheds/core/src/main/java/org/apache/ldap/server/jndi/AbstractContextFactory.java
Mon Feb  6 11:15:22 2006
@@ -121,7 +121,7 @@
         return service.getJndiContext( principal, credential, authentication, providerUrl
);
     }
 
-    private String getProviderUrl( Hashtable env )
+    public static String getProviderUrl( Hashtable env )
     {
         String providerUrl;
         Object value;
@@ -137,7 +137,7 @@
         return providerUrl;
     }
 
-    private String getAuthentication( Hashtable env )
+    public static String getAuthentication( Hashtable env )
     {
         String authentication;
         Object value = env.get( Context.SECURITY_AUTHENTICATION );
@@ -155,7 +155,7 @@
         return authentication;
     }
 
-    private byte[] getCredential( Hashtable env ) throws ConfigurationException
+    public static byte[] getCredential( Hashtable env ) throws ConfigurationException
     {
         byte[] credential;
         Object value = env.get( Context.SECURITY_CREDENTIALS );
@@ -184,7 +184,7 @@
         return credential;
     }
 
-    private String getPrincipal( Hashtable env )
+    public static String getPrincipal( Hashtable env )
     {
         String principal;
         Object value = env.get( Context.SECURITY_PRINCIPAL );

Modified: directory/trunks/apacheds/core/src/main/java/org/apache/ldap/server/jndi/LdapJndiProperties.java
URL: http://svn.apache.org/viewcvs/directory/trunks/apacheds/core/src/main/java/org/apache/ldap/server/jndi/LdapJndiProperties.java?rev=375337&r1=375336&r2=375337&view=diff
==============================================================================
--- directory/trunks/apacheds/core/src/main/java/org/apache/ldap/server/jndi/LdapJndiProperties.java
(original)
+++ directory/trunks/apacheds/core/src/main/java/org/apache/ldap/server/jndi/LdapJndiProperties.java
Mon Feb  6 11:15:22 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/trunks/apacheds/core/src/main/java/org/apache/ldap/server/schema/SchemaService.java
URL: http://svn.apache.org/viewcvs/directory/trunks/apacheds/core/src/main/java/org/apache/ldap/server/schema/SchemaService.java?rev=375337&r1=375336&r2=375337&view=diff
==============================================================================
--- directory/trunks/apacheds/core/src/main/java/org/apache/ldap/server/schema/SchemaService.java
(original)
+++ directory/trunks/apacheds/core/src/main/java/org/apache/ldap/server/schema/SchemaService.java
Mon Feb  6 11:15:22 2006
@@ -17,8 +17,10 @@
 package org.apache.ldap.server.schema;
 
 
+import java.util.ArrayList;
 import java.util.HashSet;
 import java.util.Iterator;
+import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
@@ -48,6 +50,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;
@@ -88,6 +91,10 @@
      * a binary attribute tranforming filter: String -> byte[]
      */
     private BinaryAttributeFilter binaryAttributeFilter;
+    
+    private TopFilter topFilter;
+    
+    private List filters = new ArrayList();
 
     /**
      * the global schema object registries
@@ -99,7 +106,7 @@
     /**
      * subschemaSubentry attribute's value from Root DSE
      */
-    private String subentryDn;
+    private String subschemaSubentryDn;
 
     /**
      * The time when the server started up.
@@ -120,11 +127,14 @@
         this.nexus = factoryCfg.getPartitionNexus();
         this.globalRegistries = factoryCfg.getGlobalRegistries();
         binaryAttributeFilter = new BinaryAttributeFilter();
+        topFilter = new TopFilter();
+        filters.add( binaryAttributeFilter );
+        filters.add( topFilter );
         binaries = ( Set ) factoryCfg.getEnvironment().get( BINARY_KEY );
 
         // stuff for dealing with subentries (garbage for now)
         String subschemaSubentry = ( String ) nexus.getRootDSE().get( "subschemaSubentry"
).get();
-        subentryDn = new LdapName( subschemaSubentry ).toString().toLowerCase();
+        subschemaSubentryDn = new LdapName( subschemaSubentry ).toString().toLowerCase();
     }
 
 
@@ -155,9 +165,16 @@
                                      SearchControls searchCtls ) throws NamingException
     {
         // check to make sure the DN searched for is a subentry
-        if ( !subentryDn.equals( base.toString() ) )
+        if ( !subschemaSubentryDn.equals( base.toString() ) )
         {
-            return nextInterceptor.search( base, env, filter, searchCtls );
+            NamingEnumeration e = nextInterceptor.search( base, env, filter, searchCtls );
+            if ( searchCtls.getReturningAttributes() != null )
+            {
+                return e;
+            }
+
+            Invocation invocation = InvocationStack.getInstance().peek();
+            return new SearchResultFilteringEnumeration( e, searchCtls, invocation, filters
);
         }
 
         if ( searchCtls.getSearchScope() == SearchControls.OBJECT_SCOPE &&
@@ -177,7 +194,7 @@
             }
         }
         else if ( searchCtls.getSearchScope() == SearchControls.OBJECT_SCOPE &&
-                filter instanceof PresenceNode )
+                    filter instanceof PresenceNode )
         {
             PresenceNode node = ( PresenceNode ) filter;
 
@@ -191,14 +208,13 @@
         }
 
         NamingEnumeration e = nextInterceptor.search( base, env, filter, searchCtls );
-
         if ( searchCtls.getReturningAttributes() != null )
         {
             return e;
         }
 
         Invocation invocation = InvocationStack.getInstance().peek();
-        return new SearchResultFilteringEnumeration( e, searchCtls, invocation, binaryAttributeFilter
);
+        return new SearchResultFilteringEnumeration( e, searchCtls, invocation, filters );
     }
 
 
@@ -386,7 +402,8 @@
     public Attributes lookup( NextInterceptor nextInterceptor, Name name ) throws NamingException
     {
         Attributes result = nextInterceptor.lookup( name );
-        doFilter( result );
+        filterBinaryAttributes( result );
+        filterTop( result );
         return result;
     }
 
@@ -399,7 +416,8 @@
             return null;
         }
 
-        doFilter( result );
+        filterBinaryAttributes( result );
+        filterTop( result );
         return result;
     }
 
@@ -506,6 +524,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 +622,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,16 +749,79 @@
             }
         }
 
+        // 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 filterTop( Attributes entry ) throws NamingException
+    {
+        // add top if objectClass is included and missing top
+        Attribute oc = entry.get( "objectClass" );
+        if ( oc != null )
+        {
+            if ( ! oc.contains( "top" ) )
+            {
+                oc.add( "top" );
+            }
+        }
+    }
 
-    private void doFilter( Attributes entry ) throws NamingException
+
+    private void filterBinaryAttributes( Attributes entry ) throws NamingException
     {
-        long t0 = System.currentTimeMillis();
+        long t0 = -1;
         
         if ( log.isDebugEnabled() )
         {
+            t0 = System.currentTimeMillis();
             log.debug( "Filtering entry " + AttributeUtils.toString( entry ) );  
         }
         
@@ -650,13 +830,10 @@
          * 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 +844,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 +865,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,14 +887,21 @@
      */
     private class BinaryAttributeFilter implements SearchResultFilter
     {
-        public BinaryAttributeFilter()
+        public boolean accept( Invocation invocation, SearchResult result, SearchControls
controls ) throws NamingException
         {
+            filterBinaryAttributes( result.getAttributes() );
+            return true;
         }
+    }
 
-
+    /**
+     * Filters objectClass attribute to inject top when not present.
+     */
+    private class TopFilter implements SearchResultFilter
+    {
         public boolean accept( Invocation invocation, SearchResult result, SearchControls
controls ) throws NamingException
         {
-            doFilter( result.getAttributes() );
+            filterTop( result.getAttributes() );
             return true;
         }
     }
@@ -734,19 +912,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();
+                throw new LdapInvalidAttributeIdentifierException( name + " not found in
attribute registry!" );
             }
         }
-
+        
+        alterObjectClasses( attrs.get( "objectClass" ), this.globalRegistries.getObjectClassRegistry()
);
         next.add( upName, normName, attrs );
     }
 }

Modified: directory/trunks/apacheds/core/src/test/java/org/apache/ldap/server/jndi/LdapJndiPropertiesTest.java
URL: http://svn.apache.org/viewcvs/directory/trunks/apacheds/core/src/test/java/org/apache/ldap/server/jndi/LdapJndiPropertiesTest.java?rev=375337&r1=375336&r2=375337&view=diff
==============================================================================
--- directory/trunks/apacheds/core/src/test/java/org/apache/ldap/server/jndi/LdapJndiPropertiesTest.java
(original)
+++ directory/trunks/apacheds/core/src/test/java/org/apache/ldap/server/jndi/LdapJndiPropertiesTest.java
Mon Feb  6 11:15:22 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

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

Modified: directory/trunks/apacheds/simple/jndi/src/main/java/org/apache/ldap/server/jndi/ServerContextFactory.java
URL: http://svn.apache.org/viewcvs/directory/trunks/apacheds/simple/jndi/src/main/java/org/apache/ldap/server/jndi/ServerContextFactory.java?rev=375337&r1=375336&r2=375337&view=diff
==============================================================================
--- directory/trunks/apacheds/simple/jndi/src/main/java/org/apache/ldap/server/jndi/ServerContextFactory.java
(original)
+++ directory/trunks/apacheds/simple/jndi/src/main/java/org/apache/ldap/server/jndi/ServerContextFactory.java
Mon Feb  6 11:15:22 2006
@@ -56,6 +56,7 @@
 import org.apache.mina.common.WriteFuture;
 import org.apache.mina.registry.Service;
 import org.apache.mina.registry.ServiceRegistry;
+import org.apache.mina.transport.socket.nio.SocketAcceptor;
 import org.apache.ntp.NtpConfiguration;
 import org.apache.ntp.NtpServer;
 import org.apache.protocol.common.LoadStrategy;
@@ -423,7 +424,9 @@
         try
         {
             // Disable the disconnection of the clients on unbind
-            minaRegistry.getAcceptor( service.getTransportType() ).setDisconnectClientsOnUnbind(
false );
+            IoAcceptor acceptor = minaRegistry.getAcceptor( service.getTransportType() );
+            acceptor.setDisconnectClientsOnUnbind( false );
+            ( ( SocketAcceptor ) acceptor ).setReuseAddress( true );
             
             minaRegistry.bind( service, protocolProvider.getHandler(), chainBuilder );
             ldapService = service;

Modified: directory/trunks/apacheds/simple/unit/src/main/java/org/apache/ldap/server/AbstractServerTest.java
URL: http://svn.apache.org/viewcvs/directory/trunks/apacheds/simple/unit/src/main/java/org/apache/ldap/server/AbstractServerTest.java?rev=375337&r1=375336&r2=375337&view=diff
==============================================================================
--- directory/trunks/apacheds/simple/unit/src/main/java/org/apache/ldap/server/AbstractServerTest.java
(original)
+++ directory/trunks/apacheds/simple/unit/src/main/java/org/apache/ldap/server/AbstractServerTest.java
Mon Feb  6 11:15:22 2006
@@ -77,7 +77,6 @@
         port = AvailablePortFinder.getNextAvailable( 1024 );
         configuration.setLdapPort( port );
         configuration.setShutdownHookEnabled( false );
-
         setSysRoot( "uid=admin,ou=system", "secret" );
     }
 
@@ -114,11 +113,9 @@
     protected LdapContext setSysRoot( String user, String passwd ) throws NamingException
     {
         Hashtable env = new Hashtable( configuration.toJndiEnvironment() );
-
         env.put( Context.SECURITY_PRINCIPAL, user );
         env.put( Context.SECURITY_CREDENTIALS, passwd );
         env.put( Context.SECURITY_AUTHENTICATION, "simple" );
-
         return setSysRoot( env );
     }
 
@@ -137,7 +134,6 @@
         Hashtable envFinal = new Hashtable( env );
         envFinal.put( Context.PROVIDER_URL, "ou=system" );
         envFinal.put( Context.INITIAL_CONTEXT_FACTORY, ServerContextFactory.class.getName()
);
-
         return sysRoot = new InitialLdapContext( envFinal, null );
     }
 
@@ -150,19 +146,12 @@
     protected void tearDown() throws Exception
     {
         super.tearDown();
-
         Hashtable env = new Hashtable();
-
         env.put( Context.PROVIDER_URL, "ou=system" );
-
         env.put( Context.INITIAL_CONTEXT_FACTORY, "org.apache.ldap.server.jndi.ServerContextFactory"
);
-
         env.putAll( new ShutdownConfiguration().toJndiEnvironment() );
-
         env.put( Context.SECURITY_PRINCIPAL, "uid=admin,ou=system" );
-
         env.put( Context.SECURITY_CREDENTIALS, "secret" );
-
         try { new InitialContext( env ); } catch( Exception e ) {}
 
         sysRoot = null;
@@ -183,40 +172,28 @@
     protected void importLdif( InputStream in ) throws NamingException
     {
         Hashtable env = new Hashtable();
-
         env.putAll( sysRoot.getEnvironment() );
-
         LdapContext ctx = new InitialLdapContext( env, null );
-
         LdifParser parser = new LdifParserImpl();
 
         try
         {
             LdifIterator iterator = new LdifIterator( in );
-
             while ( iterator.hasNext() )
             {
                 Attributes attributes = new LockableAttributesImpl();
-
                 String ldif = ( String ) iterator.next();
-
                 parser.parse( attributes, ldif );
-
                 Name dn = new LdapName( ( String ) attributes.remove( "dn" ).get() );
-
                 dn.remove( 0 );
-
                 ctx.createSubcontext( dn, attributes );
             }
         }
         catch ( Exception e )
         {
             String msg = "failed while trying to parse system ldif file";
-
             NamingException ne = new LdapConfigurationException( msg );
-
             ne.setRootCause( e );
-
             throw ne;
         }
     }

Modified: directory/trunks/apacheds/simple/unit/src/test/java/org/apache/ldap/server/ReferralTest.java
URL: http://svn.apache.org/viewcvs/directory/trunks/apacheds/simple/unit/src/test/java/org/apache/ldap/server/ReferralTest.java?rev=375337&r1=375336&r2=375337&view=diff
==============================================================================
--- directory/trunks/apacheds/simple/unit/src/test/java/org/apache/ldap/server/ReferralTest.java
(original)
+++ directory/trunks/apacheds/simple/unit/src/test/java/org/apache/ldap/server/ReferralTest.java
Mon Feb  6 11:15:22 2006
@@ -82,6 +82,7 @@
         if ( td.refCtx != null )
         {
             td.refCtx.close();
+            td.rootCtx.close();
         }
         
         super.tearDown();



Mime
View raw message