directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r157047 - in incubator/directory/apacheds/trunk/core/src: main/java/org/apache/ldap/server/jndi/CoreContextFactory.java main/java/org/apache/ldap/server/jndi/JndiProvider.java main/java/org/apache/ldap/server/jndi/ServerContextFactory.java test/org/apache/ldap/server/jndi/ServiceRegistryPassthruTest.java
Date Fri, 11 Mar 2005 04:58:20 GMT
Author: akarasulu
Date: Thu Mar 10 20:58:17 2005
New Revision: 157047

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

 o added new base class for the initial context factory which does not
     o start the server listener sockets
     o apply initial ldif import
   this factory is ideal for use in a container environment where other
   aspects are handled by services outside of the ICF
 o fixed a couple tests that broke - changes made by trustin
 o made change to provider to use the base ICF so both can be used

Right now if you delegate the creation of the server socket to another class,
service, what have you you can use the CoreContextFactory.  The 
ServerContextFactory will create the server socket listeners via mina and 
will load an initial LDIF.  


Added:
    incubator/directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/jndi/CoreContextFactory.java
Modified:
    incubator/directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/jndi/JndiProvider.java
    incubator/directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/jndi/ServerContextFactory.java
    incubator/directory/apacheds/trunk/core/src/test/org/apache/ldap/server/jndi/ServiceRegistryPassthruTest.java

Added: incubator/directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/jndi/CoreContextFactory.java
URL: http://svn.apache.org/viewcvs/incubator/directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/jndi/CoreContextFactory.java?view=auto&rev=157047
==============================================================================
--- incubator/directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/jndi/CoreContextFactory.java (added)
+++ incubator/directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/jndi/CoreContextFactory.java Thu Mar 10 20:58:17 2005
@@ -0,0 +1,749 @@
+/*
+ *   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;
+
+
+import java.io.File;
+import java.lang.reflect.Constructor;
+import java.util.ArrayList;
+import java.util.Hashtable;
+import java.util.List;
+
+import javax.naming.Context;
+import javax.naming.Name;
+import javax.naming.NamingException;
+import javax.naming.directory.Attributes;
+import javax.naming.spi.InitialContextFactory;
+
+import org.apache.ldap.common.exception.LdapAuthenticationNotSupportedException;
+import org.apache.ldap.common.exception.LdapConfigurationException;
+import org.apache.ldap.common.exception.LdapNoPermissionException;
+import org.apache.ldap.common.message.LockableAttributesImpl;
+import org.apache.ldap.common.message.ResultCodeEnum;
+import org.apache.ldap.common.name.LdapName;
+import org.apache.ldap.common.schema.AttributeType;
+import org.apache.ldap.common.schema.Normalizer;
+import org.apache.ldap.common.util.DateUtils;
+import org.apache.ldap.common.util.StringTools;
+import org.apache.ldap.server.ApplicationPartition;
+import org.apache.ldap.server.ContextPartition;
+import org.apache.ldap.server.ContextPartitionConfig;
+import org.apache.ldap.server.RootNexus;
+import org.apache.ldap.server.SystemPartition;
+import org.apache.ldap.server.db.Database;
+import org.apache.ldap.server.db.DefaultSearchEngine;
+import org.apache.ldap.server.db.ExpressionEnumerator;
+import org.apache.ldap.server.db.ExpressionEvaluator;
+import org.apache.ldap.server.db.SearchEngine;
+import org.apache.ldap.server.db.jdbm.JdbmDatabase;
+import org.apache.ldap.server.jndi.ibs.AuthorizationService;
+import org.apache.ldap.server.jndi.ibs.FilterService;
+import org.apache.ldap.server.jndi.ibs.FilterServiceImpl;
+import org.apache.ldap.server.jndi.ibs.OperationalAttributeService;
+import org.apache.ldap.server.jndi.ibs.SchemaService;
+import org.apache.ldap.server.jndi.ibs.ServerExceptionService;
+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.MatchingRuleRegistry;
+import org.apache.ldap.server.schema.OidRegistry;
+import org.apache.ldap.server.schema.bootstrap.BootstrapRegistries;
+import org.apache.ldap.server.schema.bootstrap.BootstrapSchemaLoader;
+
+
+/**
+ * A server-side provider implementation of a InitialContextFactory.  Can be
+ * utilized via JNDI API in the standard fashion:
+ *
+ * <code>
+ * Hashtable env = new Hashtable();
+ * env.put( Context.PROVIDER_URL, "ou=system" );
+ * env.put(
+ * Context.INITIAL_CONTEXT_FACTORY, "org.apache.ldap.server.jndi.ServerContextFactory" );
+ * InitialContext initialContext = new InitialContext( env );
+ * </code>
+ *
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ * @see javax.naming.spi.InitialContextFactory
+ */
+public class CoreContextFactory implements InitialContextFactory
+{
+    /*
+     * @todo this class needs to be better broken down - its in disarray; too much
+     * fuctionality in one place which can be better organized
+     */
+
+    /** shorthand reference to the authentication type property */
+    private static final String TYPE = Context.SECURITY_AUTHENTICATION;
+
+    /** shorthand reference to the authentication credentials property */
+    private static final String CREDS = Context.SECURITY_CREDENTIALS;
+
+    /** shorthand reference to the authentication principal property */
+    protected static final String PRINCIPAL = Context.SECURITY_PRINCIPAL;
+
+    /** shorthand reference to the admin principal name */
+    protected static final String ADMIN = SystemPartition.ADMIN_PRINCIPAL;
+
+    /** shorthand reference to the admin principal distinguished name */
+    protected static final Name ADMIN_NAME = SystemPartition.getAdminDn();
+
+    /** default path to working directory if WKDIR_ENV property is not set */
+    public static final String DEFAULT_WKDIR = "server-work";
+
+    /** default schema classes for the SCHEMAS_ENV property if not set */
+    protected static final String[] DEFAULT_SCHEMAS = new String[]
+    {
+        "org.apache.ldap.server.schema.bootstrap.CoreSchema",
+        "org.apache.ldap.server.schema.bootstrap.CosineSchema",
+        "org.apache.ldap.server.schema.bootstrap.ApacheSchema",
+        "org.apache.ldap.server.schema.bootstrap.InetorgpersonSchema",
+        "org.apache.ldap.server.schema.bootstrap.JavaSchema",
+        "org.apache.ldap.server.schema.bootstrap.SystemSchema"
+    };
+
+    // ------------------------------------------------------------------------
+    // Members
+    // ------------------------------------------------------------------------
+
+    /** The singleton JndiProvider instance */
+    protected JndiProvider provider = null;
+
+    /** the initial context environment that fired up the backend subsystem */
+    protected Hashtable initialEnv;
+
+    /** the system partition used by the context factory */
+    protected SystemPartition system;
+
+    /** the registries for system schema objects */
+    protected GlobalRegistries globalRegistries;
+
+    /** the root nexus */
+    protected RootNexus nexus;
+
+    /** whether or not server is started for the first time */
+    protected boolean createMode;
+
+
+    /**
+     * Default constructor that sets the provider of this ServerContextFactory.
+     */
+    public CoreContextFactory()
+    {
+        JndiProvider.setProviderOn( this );
+    }
+
+
+    /**
+     * Enables this ServerContextFactory with a handle to the JndiProvider singleton.
+     *
+     * @param provider the system's singleton BackendSubsystem service.
+     */
+    void setProvider( JndiProvider provider )
+    {
+        this.provider = provider;
+    }
+
+
+    public Context getInitialContext( Hashtable env ) throws NamingException
+    {
+        env = ( Hashtable ) env.clone();
+
+        Context ctx = null;
+
+        if ( env.containsKey( EnvKeys.SHUTDOWN ) )
+        {
+            if ( this.provider == null )
+            {
+                return new DeadContext();
+            }
+
+            try
+            {
+                this.provider.shutdown();
+            }
+            catch ( Throwable t )
+            {
+                t.printStackTrace();
+            }
+            finally
+            {
+                ctx = new DeadContext();
+
+                provider = null;
+
+                initialEnv = null;
+            }
+
+            return ctx;
+        }
+
+        if ( env.containsKey( EnvKeys.SYNC ) )
+        {
+            provider.sync();
+
+            return provider.getLdapContext( env );
+        }
+
+        checkSecuritySettings( env );
+
+        if ( isAnonymous( env ) )
+        {
+            env.put( PRINCIPAL, "" );
+        }
+
+        // fire up the backend subsystem if we need to
+        if ( null == provider )
+        {
+            // we need to check this here instead of in AuthenticationService
+            // because otherwise we are going to start up the system incorrectly
+            if ( isAnonymous( env ) && env.containsKey( EnvKeys.DISABLE_ANONYMOUS ) )
+            {
+                throw new LdapNoPermissionException( "cannot bind as anonymous "
+                        + "on startup while disabling anonymous binds w/ property: "
+                        + EnvKeys.DISABLE_ANONYMOUS );
+            }
+
+            this.initialEnv = env;
+
+            initialize();
+
+            createMode = createAdminAccount();
+        }
+
+        ctx = ( ServerContext ) provider.getLdapContext( env );
+
+        return ctx;
+    }
+
+
+    /**
+     * Checks to make sure security environment parameters are set correctly.
+     *
+     * @throws javax.naming.NamingException if the security settings are not correctly configured.
+     */
+    protected void checkSecuritySettings( Hashtable env ) throws NamingException
+    {
+        if ( env.containsKey( TYPE ) && env.get( TYPE ) != null )
+        {
+            /*
+             * If bind is simple make sure we have the credentials and the
+             * principal name set within the environment, otherwise complain
+             */
+            if ( env.get( TYPE ).equals( "simple" ) )
+            {
+                if ( !env.containsKey( CREDS ) )
+                {
+                    throw new LdapConfigurationException( "missing required "
+                            + CREDS + " property for simple authentication" );
+                }
+
+                if ( !env.containsKey( PRINCIPAL ) )
+                {
+                    throw new LdapConfigurationException( "missing required "
+                            + PRINCIPAL + " property for simple authentication" );
+                }
+            }
+            /*
+             * If bind is none make sure credentials and the principal
+             * name are NOT set within the environment, otherwise complain
+             */
+            else if ( env.get( TYPE ).equals( "none" ) )
+            {
+                if ( env.containsKey( CREDS ) )
+                {
+                    throw new LdapConfigurationException( "ambiguous bind "
+                            + "settings encountered where bind is anonymous yet "
+                            + CREDS + " property is set" );
+                }
+                if ( env.containsKey( PRINCIPAL ) )
+                {
+                    throw new LdapConfigurationException( "ambiguous bind "
+                            + "settings encountered where bind is anonymous yet "
+                            + PRINCIPAL + " property is set" );
+                }
+            }
+            /*
+             * If bind is anything other than simple or none we need to
+             * complain because SASL is not a supported auth method yet
+             */
+            else
+            {
+                throw new LdapAuthenticationNotSupportedException( ResultCodeEnum.AUTHMETHODNOTSUPPORTED );
+            }
+        }
+        else if ( env.containsKey( CREDS ) )
+        {
+            if ( !env.containsKey( PRINCIPAL ) )
+            {
+                throw new LdapConfigurationException( "credentials provided "
+                        + "without principal name property: " + PRINCIPAL );
+            }
+        }
+    }
+
+
+    /**
+     * Checks to see if an anonymous bind is being attempted.
+     *
+     * @return true if bind is anonymous, false otherwise
+     */
+    protected boolean isAnonymous( Hashtable env )
+    {
+
+        if ( env.containsKey( TYPE ) && env.get( TYPE ) != null )
+        {
+            if ( env.get( TYPE ).equals( "none" ) )
+            {
+                return true;
+            }
+
+            return false;
+        }
+
+        if ( env.containsKey( CREDS ) )
+        {
+            return false;
+        }
+
+        return true;
+    }
+
+
+    /**
+     * Returns true if we had to create the admin account since this is the first time we started the server.  Otherwise
+     * if the account exists then we are not starting for the first time.
+     *
+     * @throws javax.naming.NamingException
+     */
+    protected boolean createAdminAccount() throws NamingException
+    {
+        /*
+         * If the admin entry is there, then the database was already created
+         * before so we just need to lookup the userPassword field to see if
+         * the password matches.
+         */
+        if ( nexus.hasEntry( ADMIN_NAME ) )
+        {
+            return false;
+        }
+
+        Attributes attributes = new LockableAttributesImpl();
+
+        attributes.put( "objectClass", "top" );
+
+        attributes.put( "objectClass", "person" );
+
+        attributes.put( "objectClass", "organizationalPerson" );
+
+        attributes.put( "objectClass", "inetOrgPerson" );
+
+        attributes.put( "uid", SystemPartition.ADMIN_UID );
+
+        attributes.put( "userPassword", SystemPartition.ADMIN_PW );
+
+        attributes.put( "displayName", "Directory Superuser" );
+
+        attributes.put( "creatorsName", ADMIN );
+
+        attributes.put( "createTimestamp", DateUtils.getGeneralizedTime() );
+
+        attributes.put( "displayName", "Directory Superuser" );
+
+        nexus.add( ADMIN, ADMIN_NAME, attributes );
+
+        return true;
+    }
+
+
+    /**
+     * Kicks off the initialization of the entire system.
+     *
+     * @throws javax.naming.NamingException if there are problems along the way
+     */
+    protected void initialize() throws NamingException
+    {
+        // --------------------------------------------------------------------
+        // Load the schema here and check that it is ok!
+        // --------------------------------------------------------------------
+
+        BootstrapRegistries bootstrapRegistries = new BootstrapRegistries();
+
+        BootstrapSchemaLoader loader = new BootstrapSchemaLoader();
+
+        String[] schemas = DEFAULT_SCHEMAS;
+
+        if ( initialEnv.containsKey( EnvKeys.SCHEMAS ) )
+        {
+            String schemaList = ( String ) initialEnv.get( EnvKeys.SCHEMAS );
+
+            schemaList = StringTools.deepTrim( schemaList );
+
+            schemas = schemaList.split( " " );
+
+            for ( int ii = 0; ii < schemas.length; ii++ )
+            {
+                schemas[ii] = schemas[ii].trim();
+            }
+        }
+
+        loader.load( schemas, bootstrapRegistries );
+
+        List errors = bootstrapRegistries.checkRefInteg();
+
+        if ( !errors.isEmpty() )
+        {
+            NamingException e = new NamingException();
+
+            e.setRootCause( ( Throwable ) errors.get( 0 ) );
+
+            throw e;
+        }
+
+        // --------------------------------------------------------------------
+        // Fire up the system partition
+        // --------------------------------------------------------------------
+
+        String wkdir = DEFAULT_WKDIR;
+
+        if ( initialEnv.containsKey( EnvKeys.WKDIR ) )
+        {
+            wkdir = ( ( String ) initialEnv.get( EnvKeys.WKDIR ) ).trim();
+        }
+
+        File wkdirFile = new File( wkdir );
+
+        if ( wkdirFile.isAbsolute() )
+        {
+            if ( !wkdirFile.exists() )
+            {
+                throw new NamingException( "working directory " + wkdir + " does not exist" );
+            }
+        }
+        else
+        {
+            File current = new File( "." );
+
+            mkdirs( current.getAbsolutePath(), wkdir );
+        }
+
+        LdapName suffix = new LdapName();
+
+        suffix.add( SystemPartition.SUFFIX );
+
+        Database db = new JdbmDatabase( suffix, suffix, wkdir );
+
+        AttributeTypeRegistry attributeTypeRegistry;
+
+        attributeTypeRegistry = bootstrapRegistries .getAttributeTypeRegistry();
+
+        OidRegistry oidRegistry;
+
+        oidRegistry = bootstrapRegistries.getOidRegistry();
+
+        ExpressionEvaluator evaluator;
+
+        evaluator = new ExpressionEvaluator( db, oidRegistry, attributeTypeRegistry );
+
+        ExpressionEnumerator enumerator;
+
+        enumerator = new ExpressionEnumerator( db, attributeTypeRegistry, evaluator );
+
+        SearchEngine eng = new DefaultSearchEngine( db, evaluator, enumerator );
+
+        AttributeType[] attributes = new AttributeType[]
+        {
+            attributeTypeRegistry.lookup( SystemPartition.ALIAS_OID ),
+
+            attributeTypeRegistry.lookup( SystemPartition.EXISTANCE_OID ),
+
+            attributeTypeRegistry.lookup( SystemPartition.HIERARCHY_OID ),
+
+            attributeTypeRegistry.lookup( SystemPartition.NDN_OID ),
+
+            attributeTypeRegistry.lookup( SystemPartition.ONEALIAS_OID ),
+
+            attributeTypeRegistry.lookup( SystemPartition.SUBALIAS_OID ),
+
+            attributeTypeRegistry.lookup( SystemPartition.UPDN_OID )
+        };
+
+        system = new SystemPartition( db, eng, attributes );
+
+        globalRegistries = new GlobalRegistries( system, bootstrapRegistries );
+
+        nexus = new RootNexus( system, new LockableAttributesImpl() );
+
+        provider = new JndiProvider( nexus );
+
+        // --------------------------------------------------------------------
+        // Adding interceptors
+        // --------------------------------------------------------------------
+
+        /*
+         * Create and add the Authentication service interceptor to before
+         * interceptor chain.
+         */
+        InvocationStateEnum[] state = new InvocationStateEnum[]{InvocationStateEnum.PREINVOCATION};
+
+        boolean allowAnonymous = !initialEnv.containsKey( EnvKeys.DISABLE_ANONYMOUS );
+
+        Interceptor interceptor = new AuthenticationService( nexus, allowAnonymous );
+
+        provider.addInterceptor( interceptor, state );
+
+        /*
+         * Create and add the Eve Exception service interceptor to both the
+         * before and onError interceptor chains.
+         */
+        state = new InvocationStateEnum[]{InvocationStateEnum.POSTINVOCATION};
+
+        FilterService filterService = new FilterServiceImpl();
+
+        interceptor = ( Interceptor ) filterService;
+
+        provider.addInterceptor( interceptor, state );
+
+        /*
+         * Create and add the Authorization service interceptor to before
+         * interceptor chain.
+         */
+        state = new InvocationStateEnum[]{InvocationStateEnum.PREINVOCATION};
+
+        ConcreteNameComponentNormalizer normalizer;
+
+        AttributeTypeRegistry atr = globalRegistries.getAttributeTypeRegistry();
+
+        normalizer = new ConcreteNameComponentNormalizer( atr );
+
+        interceptor = new AuthorizationService( normalizer, filterService );
+
+        provider.addInterceptor( interceptor, state );
+
+        /*
+         * Create and add the Eve Exception service interceptor to both the
+         * before and onError interceptor chains.
+         */
+        state = new InvocationStateEnum[]{
+            InvocationStateEnum.PREINVOCATION, InvocationStateEnum.FAILUREHANDLING};
+
+        interceptor = new ServerExceptionService( nexus );
+
+        provider.addInterceptor( interceptor, state );
+
+        /*
+         * Create and add the Eve schema service interceptor to before chain.
+         */
+        state = new InvocationStateEnum[]{InvocationStateEnum.PREINVOCATION};
+
+        interceptor = new SchemaService( nexus, globalRegistries, filterService );
+
+        provider.addInterceptor( interceptor, state );
+
+        /*
+         * Create and add the Eve operational attribute managment service
+         * interceptor to both the before and after interceptor chains.
+         */
+        state = new InvocationStateEnum[]{
+            InvocationStateEnum.PREINVOCATION,
+            InvocationStateEnum.POSTINVOCATION};
+
+        interceptor = new OperationalAttributeService( nexus, globalRegistries, filterService );
+
+        provider.addInterceptor( interceptor, state );
+
+        // fire up the app partitions now!
+        if ( initialEnv.get( EnvKeys.PARTITIONS ) != null )
+        {
+            startUpAppPartitions( wkdir );
+        }
+    }
+
+
+    /**
+     * Starts up all the application partitions that will be attached to naming contexts in the system.  Partition
+     * database files are created within a subdirectory immediately under the Eve working directory base.
+     *
+     * @param eveWkdir the base Eve working directory
+     * @throws javax.naming.NamingException if there are problems creating and starting these new application
+     *                                      partitions
+     */
+    protected void startUpAppPartitions( String eveWkdir ) throws NamingException
+    {
+        OidRegistry oidRegistry = globalRegistries.getOidRegistry();
+
+        AttributeTypeRegistry attributeTypeRegistry;
+
+        attributeTypeRegistry = globalRegistries.getAttributeTypeRegistry();
+
+        MatchingRuleRegistry reg = globalRegistries.getMatchingRuleRegistry();
+
+        // start getting all the parameters from the initial environment
+        ContextPartitionConfig[] configs = null;
+
+        configs = PartitionConfigBuilder.getContextPartitionConfigs( initialEnv );
+
+        for ( int ii = 0; ii < configs.length; ii++ )
+        {
+            // ----------------------------------------------------------------
+            // create working directory under eve directory for app partition
+            // ----------------------------------------------------------------
+
+            String wkdir = eveWkdir + File.separator + configs[ii].getId();
+
+            mkdirs( eveWkdir, configs[ii].getId() );
+
+            // ----------------------------------------------------------------
+            // create the database/store
+            // ----------------------------------------------------------------
+
+            Name upSuffix = new LdapName( configs[ii].getSuffix() );
+
+            Normalizer dnNorm = reg.lookup( "distinguishedNameMatch" ) .getNormalizer();
+
+            Name normSuffix = new LdapName( ( String ) dnNorm.normalize( configs[ii].getSuffix() ) );
+
+            Database db = new JdbmDatabase( upSuffix, normSuffix, wkdir );
+
+            // ----------------------------------------------------------------
+            // create the search engine using db, enumerators and evaluators
+            // ----------------------------------------------------------------
+
+            ExpressionEvaluator evaluator;
+
+            evaluator = new ExpressionEvaluator( db, oidRegistry, attributeTypeRegistry );
+
+            ExpressionEnumerator enumerator;
+
+            enumerator = new ExpressionEnumerator( db, attributeTypeRegistry, evaluator );
+
+            SearchEngine eng = new DefaultSearchEngine( db, evaluator, enumerator );
+
+            // ----------------------------------------------------------------
+            // fill up a list with the AttributeTypes for the system indices
+            // ----------------------------------------------------------------
+
+            ArrayList attributeTypeList = new ArrayList();
+
+            attributeTypeList.add( attributeTypeRegistry.lookup( SystemPartition.ALIAS_OID ) );
+
+            attributeTypeList.add( attributeTypeRegistry.lookup( SystemPartition.EXISTANCE_OID ) );
+
+            attributeTypeList.add( attributeTypeRegistry.lookup( SystemPartition.HIERARCHY_OID ) );
+
+            attributeTypeList.add( attributeTypeRegistry.lookup( SystemPartition.NDN_OID ) );
+
+            attributeTypeList.add( attributeTypeRegistry.lookup( SystemPartition.ONEALIAS_OID ) );
+
+            attributeTypeList.add( attributeTypeRegistry.lookup( SystemPartition.SUBALIAS_OID ) );
+
+            attributeTypeList.add( attributeTypeRegistry.lookup( SystemPartition.UPDN_OID ) );
+
+            // ----------------------------------------------------------------
+            // if user indices are specified add those attribute types as well
+            // ----------------------------------------------------------------
+
+            for ( int jj = 0; jj < configs[ii].getIndices().length; jj++ )
+            {
+                attributeTypeList.add( attributeTypeRegistry
+                        .lookup( configs[ii].getIndices()[jj] ) );
+            }
+
+            // ----------------------------------------------------------------
+            // fire up the appPartition & register it with the nexus
+            // ----------------------------------------------------------------
+
+            AttributeType[] indexTypes = ( AttributeType[] ) attributeTypeList
+                    .toArray( new AttributeType[attributeTypeList.size()] );
+
+            String partitionClass = configs[ii].getPartitionClass();
+
+            String properties = configs[ii].getProperties();
+
+            ContextPartition partition = null;
+
+            if ( partitionClass == null )
+            {
+                // If custom partition is not defined, use the ApplicationPartion.
+                partition = new ApplicationPartition( upSuffix, normSuffix, db, eng, indexTypes );
+
+            }
+            else
+            {
+                // If custom partition is defined, instantiate it.
+                try
+                {
+                    Class clazz = Class.forName( partitionClass );
+
+                    Constructor constructor = clazz.getConstructor(
+                            new Class[] { Name.class, Name.class, String.class } );
+
+                    partition = ( ContextPartition ) constructor.newInstance(
+                            new Object[] { upSuffix, normSuffix, properties } );
+                }
+                catch ( Exception e )
+                {
+                    e.printStackTrace();
+                }
+            }
+
+            if ( partition != null ) 
+            { 
+                nexus.register( partition );
+            }
+
+            // ----------------------------------------------------------------
+            // add the nexus context entry
+            // ----------------------------------------------------------------
+
+            partition.add( configs[ii].getSuffix(), normSuffix, configs[ii].getAttributes() );
+        }
+    }
+
+
+    /**
+     * Recursively creates a bunch of directories from a base down to a path.
+     *
+     * @param base the base directory to start at
+     * @param path the path to recursively create if we have to
+     * @return true if the target directory has been created or exists, false if we fail along the way somewhere
+     */
+    protected boolean mkdirs( String base, String path )
+    {
+        String[] comps = path.split( "/" );
+
+        File file = new File( base );
+
+        if ( !file.exists() )
+        {
+            file.mkdirs();
+        }
+
+        for ( int ii = 0; ii < comps.length; ii++ )
+        {
+            file = new File( file, comps[ii] );
+
+            if ( !file.exists() )
+            {
+                file.mkdirs();
+            }
+        }
+
+        return file.exists();
+    }
+}

Modified: incubator/directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/jndi/JndiProvider.java
URL: http://svn.apache.org/viewcvs/incubator/directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/jndi/JndiProvider.java?view=diff&r1=157046&r2=157047
==============================================================================
--- incubator/directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/jndi/JndiProvider.java (original)
+++ incubator/directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/jndi/JndiProvider.java Thu Mar 10 20:58:17 2005
@@ -99,7 +99,7 @@
      *
      * @param factory the ServerContextFactory to enable
      */
-    static void setProviderOn( ServerContextFactory factory )
+    static void setProviderOn( CoreContextFactory factory )
     {
         factory.setProvider( s_singleton );
     }

Modified: incubator/directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/jndi/ServerContextFactory.java
URL: http://svn.apache.org/viewcvs/incubator/directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/jndi/ServerContextFactory.java?view=diff&r1=157046&r2=157047
==============================================================================
--- incubator/directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/jndi/ServerContextFactory.java (original)
+++ incubator/directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/jndi/ServerContextFactory.java Thu Mar 10 20:58:17 2005
@@ -17,60 +17,24 @@
 package org.apache.ldap.server.jndi;
 
 
-import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
-import java.lang.reflect.Constructor;
-import java.util.ArrayList;
 import java.util.Hashtable;
-import java.util.List;
 
 import javax.naming.Context;
-import javax.naming.Name;
 import javax.naming.NamingException;
+import javax.naming.Name;
 import javax.naming.directory.Attributes;
 import javax.naming.ldap.LdapContext;
-import javax.naming.spi.InitialContextFactory;
 
-import org.apache.ldap.common.exception.LdapAuthenticationNotSupportedException;
 import org.apache.ldap.common.exception.LdapConfigurationException;
-import org.apache.ldap.common.exception.LdapNoPermissionException;
-import org.apache.ldap.common.ldif.LdifIterator;
+import org.apache.ldap.common.util.PropertiesUtils;
 import org.apache.ldap.common.ldif.LdifParser;
 import org.apache.ldap.common.ldif.LdifParserImpl;
+import org.apache.ldap.common.ldif.LdifIterator;
 import org.apache.ldap.common.message.LockableAttributesImpl;
-import org.apache.ldap.common.message.ResultCodeEnum;
 import org.apache.ldap.common.name.LdapName;
-import org.apache.ldap.common.schema.AttributeType;
-import org.apache.ldap.common.schema.Normalizer;
-import org.apache.ldap.common.util.DateUtils;
-import org.apache.ldap.common.util.PropertiesUtils;
-import org.apache.ldap.common.util.StringTools;
-import org.apache.ldap.server.ApplicationPartition;
-import org.apache.ldap.server.ContextPartition;
-import org.apache.ldap.server.ContextPartitionConfig;
-import org.apache.ldap.server.RootNexus;
-import org.apache.ldap.server.SystemPartition;
-import org.apache.ldap.server.db.Database;
-import org.apache.ldap.server.db.DefaultSearchEngine;
-import org.apache.ldap.server.db.ExpressionEnumerator;
-import org.apache.ldap.server.db.ExpressionEvaluator;
-import org.apache.ldap.server.db.SearchEngine;
-import org.apache.ldap.server.db.jdbm.JdbmDatabase;
-import org.apache.ldap.server.jndi.ibs.AuthorizationService;
-import org.apache.ldap.server.jndi.ibs.FilterService;
-import org.apache.ldap.server.jndi.ibs.FilterServiceImpl;
-import org.apache.ldap.server.jndi.ibs.OperationalAttributeService;
-import org.apache.ldap.server.jndi.ibs.SchemaService;
-import org.apache.ldap.server.jndi.ibs.ServerExceptionService;
 import org.apache.ldap.server.protocol.LdapProtocolProvider;
-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.MatchingRuleRegistry;
-import org.apache.ldap.server.schema.OidRegistry;
-import org.apache.ldap.server.schema.bootstrap.BootstrapRegistries;
-import org.apache.ldap.server.schema.bootstrap.BootstrapSchemaLoader;
 import org.apache.mina.common.TransportType;
 import org.apache.mina.registry.Service;
 import org.apache.mina.registry.ServiceRegistry;
@@ -78,70 +42,22 @@
 
 
 /**
- * An LDAPd server-side provider implementation of a InitialContextFactory. Can be utilized via JNDI API in the standard
- * fashion: <code> Hashtable env = new Hashtable(); env.put( Context.PROVIDER_URL, "ou=system" ); env.put(
- * Context.INITIAL_CONTEXT_FACTORY, "org.apache.ldap.server.jndi.ServerContextFactory" ); InitialContext initialContext
- * = new InitialContext( env ); </code>
+ * Adds additional bootstrapping for server socket listeners when firing
+ * up the server.
  *
  * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
  * @version $Rev$
  * @see javax.naming.spi.InitialContextFactory
  */
-public class ServerContextFactory implements InitialContextFactory
+public class ServerContextFactory extends CoreContextFactory
 {
-    private static final String TYPE = Context.SECURITY_AUTHENTICATION;
-
-    private static final String CREDS = Context.SECURITY_CREDENTIALS;
-
-    private static final String PRINCIPAL = Context.SECURITY_PRINCIPAL;
-
-    private static final String ADMIN = SystemPartition.ADMIN_PRINCIPAL;
-
-    private static final Name ADMIN_NAME = SystemPartition.getAdminDn();
-
-    /**
-     * the default LDAP port to use
-     */
+    /** the default LDAP port to use */
     private static final int LDAP_PORT = 389;
 
-    /**
-     * default path to working directory if WKDIR_ENV property is not set
-     */
-    public static final String DEFAULT_WKDIR = "server-work";
-
-    /**
-     * default schema classes for the SCHEMAS_ENV property if not set
-     */
-    private static final String[] DEFAULT_SCHEMAS = new String[]
-    {
-        "org.apache.ldap.server.schema.bootstrap.CoreSchema",
-        "org.apache.ldap.server.schema.bootstrap.CosineSchema",
-        "org.apache.ldap.server.schema.bootstrap.ApacheSchema",
-        "org.apache.ldap.server.schema.bootstrap.InetorgpersonSchema",
-        "org.apache.ldap.server.schema.bootstrap.JavaSchema",
-        "org.apache.ldap.server.schema.bootstrap.SystemSchema"
-    };
-
     // ------------------------------------------------------------------------
     // Members
     // ------------------------------------------------------------------------
 
-    /**
-     * The singleton JndiProvider instance
-     */
-    private JndiProvider provider = null;
-
-    /**
-     * the initial context environment that fired up the backend subsystem
-     */
-    private Hashtable initialEnv;
-
-    private SystemPartition system;
-
-    private GlobalRegistries globalRegistries;
-
-    private RootNexus nexus;
-
     private Service minaService;
 
     private ServiceRegistry minaRegistry;
@@ -152,34 +68,18 @@
      */
     public ServerContextFactory()
     {
-        JndiProvider.setProviderOn( this );
+        super();
     }
 
 
-    /**
-     * Enables this ServerContextFactory with a handle to the JndiProvider singleton.
-     *
-     * @param a_provider the system's singleton BackendSubsystem service.
-     */
-    void setProvider( JndiProvider a_provider )
-    {
-        provider = a_provider;
-    }
-
-
-    /**
-     * @see javax.naming.spi.InitialContextFactory#getInitialContext( java.util.Hashtable)
-     */
     public Context getInitialContext( Hashtable env ) throws NamingException
     {
-        env = ( Hashtable ) env.clone();
         Context ctx = null;
 
         if ( env.containsKey( EnvKeys.SHUTDOWN ) )
         {
             if ( this.provider == null )
             {
-                // monitor.shutDownCalledOnStoppedProvider()
                 return new DeadContext();
             }
 
@@ -199,372 +99,36 @@
             finally
             {
                 ctx = new DeadContext();
+
                 provider = null;
+
                 initialEnv = null;
             }
 
             return ctx;
         }
 
-        if ( env.containsKey( EnvKeys.SYNC ) )
-        {
-            provider.sync();
-            return provider.getLdapContext( env );
-        }
-
-        checkSecuritySettings( env );
+        ctx = super.getInitialContext( env );
 
-        if ( isAnonymous( env ) )
+        // fire up the front end if we have not explicitly disabled it
+        if ( initialEnv != null && ! initialEnv.containsKey( EnvKeys.DISABLE_PROTOCOL ) )
         {
-            env.put( PRINCIPAL, "" );
+            startUpWireProtocol();
         }
 
-        // fire up the backend subsystem if we need to
-        if ( null == provider )
+        if ( createMode )
         {
-            // we need to check this here instead of in AuthenticationService
-            // because otherwise we are going to start up the system incorrectly
-            if ( isAnonymous( env )
-                    && env.containsKey( EnvKeys.DISABLE_ANONYMOUS ) )
-            {
-                throw new LdapNoPermissionException( "cannot bind as anonymous "
-                        + "on startup while disabling anonymous binds w/ property: "
-                        + EnvKeys.DISABLE_ANONYMOUS );
-            }
-
-            this.initialEnv = env;
-
-            initialize();
-            boolean createMode = createAdminAccount();
-
-            if ( createMode )
-            {
-                importLdif();
-            }
-
-            // fire up the front end if we have not explicitly disabled it
-            if ( !initialEnv.containsKey( EnvKeys.DISABLE_PROTOCOL ) )
-            {
-                startUpWireProtocol();
-            }
+            importLdif();
         }
 
-        ctx = ( ServerContext ) provider.getLdapContext( env );
         return ctx;
     }
 
 
-    /**
-     * Checks to make sure security environment parameters are set correctly.
-     *
-     * @throws NamingException if the security settings are not correctly configured.
-     */
-    private void checkSecuritySettings( Hashtable env )
-            throws NamingException
-    {
-        if ( env.containsKey( TYPE ) && env.get( TYPE ) != null )
-        {
-            /*
-             * If bind is simple make sure we have the credentials and the
-             * principal name set within the environment, otherwise complain
-             */
-            if ( env.get( TYPE ).equals( "simple" ) )
-            {
-                if ( !env.containsKey( CREDS ) )
-                {
-                    throw new LdapConfigurationException( "missing required "
-                            + CREDS
-                            + " property for simple authentication" );
-                }
-
-                if ( !env.containsKey( PRINCIPAL ) )
-                {
-                    throw new LdapConfigurationException( "missing required "
-                            + PRINCIPAL
-                            + " property for simple authentication" );
-                }
-            }
-            /*
-             * If bind is none make sure credentials and the principal
-             * name are NOT set within the environment, otherwise complain
-             */
-            else if ( env.get( TYPE ).equals( "none" ) )
-            {
-                if ( env.containsKey( CREDS ) )
-                {
-                    throw new LdapConfigurationException( "ambiguous bind "
-                            + "settings encountered where bind is anonymous yet "
-                            + CREDS
-                            + " property is set" );
-                }
-                if ( env.containsKey( PRINCIPAL ) )
-                {
-                    throw new LdapConfigurationException( "ambiguous bind "
-                            + "settings encountered where bind is anonymous yet "
-                            + PRINCIPAL
-                            + " property is set" );
-                }
-            }
-            /*
-             * If bind is anything other than simple or none we need to
-             * complain because SASL is not a supported auth method yet
-             */
-            else
-            {
-                throw new LdapAuthenticationNotSupportedException( ResultCodeEnum.AUTHMETHODNOTSUPPORTED );
-            }
-        }
-        else if ( env.containsKey( CREDS ) )
-        {
-            if ( !env.containsKey( PRINCIPAL ) )
-            {
-                throw new LdapConfigurationException( "credentials provided "
-                        + "without principal name property: "
-                        + PRINCIPAL );
-            }
-        }
-    }
-
-
-    /**
-     * Checks to see if an anonymous bind is being attempted.
-     *
-     * @return true if bind is anonymous, false otherwise
-     */
-    private boolean isAnonymous( Hashtable env )
-    {
-
-        if ( env.containsKey( TYPE ) && env.get( TYPE ) != null )
-        {
-            if ( env.get( TYPE ).equals( "none" ) )
-            {
-                return true;
-            }
-
-            return false;
-        }
-
-        if ( env.containsKey( CREDS ) )
-        {
-            return false;
-        }
-
-        return true;
-    }
-
-
-    /**
-     * Returns true if we had to create the admin account since this is the first time we started the server.  Otherwise
-     * if the account exists then we are not starting for the first time.
-     *
-     * @throws NamingException
-     */
-    private boolean createAdminAccount() throws NamingException
-    {
-        /*
-         * If the admin entry is there, then the database was already created
-         * before so we just need to lookup the userPassword field to see if
-         * the password matches.
-         */
-        if ( nexus.hasEntry( ADMIN_NAME ) )
-        {
-            return false;
-        }
-
-        Attributes attributes = new LockableAttributesImpl();
-        attributes.put( "objectClass", "top" );
-        attributes.put( "objectClass", "person" );
-        attributes.put( "objectClass", "organizationalPerson" );
-        attributes.put( "objectClass", "inetOrgPerson" );
-        attributes.put( "uid", SystemPartition.ADMIN_UID );
-        attributes.put( "userPassword", SystemPartition.ADMIN_PW );
-        attributes.put( "displayName", "Directory Superuser" );
-        attributes.put( "creatorsName", ADMIN );
-        attributes.put( "createTimestamp", DateUtils.getGeneralizedTime() );
-        attributes.put( "displayName", "Directory Superuser" );
-
-        nexus.add( ADMIN, ADMIN_NAME, attributes );
-        return true;
-    }
-
-
-    /**
-     * Kicks off the initialization of the entire system.
-     *
-     * @throws NamingException if there are problems along the way
-     */
-    private void initialize() throws NamingException
-    {
-        // --------------------------------------------------------------------
-        // Load the schema here and check that it is ok!
-        // --------------------------------------------------------------------
-
-        BootstrapRegistries bootstrapRegistries = new BootstrapRegistries();
-        BootstrapSchemaLoader loader = new BootstrapSchemaLoader();
-
-        String[] schemas = DEFAULT_SCHEMAS;
-        if ( initialEnv.containsKey( EnvKeys.SCHEMAS ) )
-        {
-            String schemaList = ( String ) initialEnv.get( EnvKeys.SCHEMAS );
-            schemaList = StringTools.deepTrim( schemaList );
-            schemas = schemaList.split( " " );
-            for ( int ii = 0; ii < schemas.length; ii++ )
-            {
-                schemas[ii] = schemas[ii].trim();
-            }
-        }
-
-        loader.load( schemas, bootstrapRegistries );
-        List errors = bootstrapRegistries.checkRefInteg();
-        if ( !errors.isEmpty() )
-        {
-            NamingException e = new NamingException();
-            e.setRootCause( ( Throwable ) errors.get( 0 ) );
-            throw e;
-        }
-
-        // --------------------------------------------------------------------
-        // Fire up the system partition
-        // --------------------------------------------------------------------
-
-        String wkdir = DEFAULT_WKDIR;
-        if ( initialEnv.containsKey( EnvKeys.WKDIR ) )
-        {
-            wkdir = ( ( String ) initialEnv.get( EnvKeys.WKDIR ) ).trim();
-        }
-
-        File wkdirFile = new File( wkdir );
-        if ( wkdirFile.isAbsolute() )
-        {
-            if ( !wkdirFile.exists() )
-            {
-                throw new NamingException( "working directory " + wkdir
-                        + " does not exist" );
-            }
-        }
-        else
-        {
-            File current = new File( "." );
-            mkdirs( current.getAbsolutePath(), wkdir );
-        }
-
-        LdapName suffix = new LdapName();
-        suffix.add( SystemPartition.SUFFIX );
-        Database db = new JdbmDatabase( suffix, suffix, wkdir );
-
-        AttributeTypeRegistry attributeTypeRegistry;
-        attributeTypeRegistry = bootstrapRegistries
-                .getAttributeTypeRegistry();
-        OidRegistry oidRegistry;
-        oidRegistry = bootstrapRegistries.getOidRegistry();
-
-        ExpressionEvaluator evaluator;
-        evaluator = new ExpressionEvaluator( db, oidRegistry,
-                attributeTypeRegistry );
-
-        ExpressionEnumerator enumerator;
-        enumerator = new ExpressionEnumerator( db, attributeTypeRegistry,
-                evaluator );
-
-        SearchEngine eng = new DefaultSearchEngine( db, evaluator, enumerator );
-
-        AttributeType[] attributes = new AttributeType[]{
-            attributeTypeRegistry
-                .lookup( SystemPartition.ALIAS_OID ),
-            attributeTypeRegistry
-                .lookup( SystemPartition.EXISTANCE_OID ),
-            attributeTypeRegistry
-                .lookup( SystemPartition.HIERARCHY_OID ),
-            attributeTypeRegistry
-                .lookup( SystemPartition.NDN_OID ),
-            attributeTypeRegistry
-                .lookup( SystemPartition.ONEALIAS_OID ),
-            attributeTypeRegistry
-                .lookup( SystemPartition.SUBALIAS_OID ),
-            attributeTypeRegistry
-                .lookup( SystemPartition.UPDN_OID )};
-
-        system = new SystemPartition( db, eng, attributes );
-        globalRegistries = new GlobalRegistries( system, bootstrapRegistries );
-        nexus = new RootNexus( system, new LockableAttributesImpl() );
-        provider = new JndiProvider( nexus );
-
-        // --------------------------------------------------------------------
-        // Adding interceptors
-        // --------------------------------------------------------------------
-
-        /*
-         * Create and add the Authentication service interceptor to before
-         * interceptor chain.
-         */
-        InvocationStateEnum[] state = new InvocationStateEnum[]{InvocationStateEnum.PREINVOCATION};
-        boolean allowAnonymous = !initialEnv
-                .containsKey( EnvKeys.DISABLE_ANONYMOUS );
-        Interceptor interceptor = new AuthenticationService( nexus,
-                allowAnonymous );
-        provider.addInterceptor( interceptor, state );
-
-        /*
-         * Create and add the Eve Exception service interceptor to both the
-         * before and onError interceptor chains.
-         */
-        state = new InvocationStateEnum[]{InvocationStateEnum.POSTINVOCATION};
-        FilterService filterService = new FilterServiceImpl();
-        interceptor = ( Interceptor ) filterService;
-        provider.addInterceptor( interceptor, state );
-
-        /*
-         * Create and add the Authorization service interceptor to before
-         * interceptor chain.
-         */
-        state = new InvocationStateEnum[]{InvocationStateEnum.PREINVOCATION};
-        ConcreteNameComponentNormalizer normalizer;
-        AttributeTypeRegistry atr = globalRegistries
-                .getAttributeTypeRegistry();
-        normalizer = new ConcreteNameComponentNormalizer( atr );
-        interceptor = new AuthorizationService( normalizer, filterService );
-        provider.addInterceptor( interceptor, state );
-
-        /*
-         * Create and add the Eve Exception service interceptor to both the
-         * before and onError interceptor chains.
-         */
-        state = new InvocationStateEnum[]{
-            InvocationStateEnum.PREINVOCATION,
-            InvocationStateEnum.FAILUREHANDLING};
-        interceptor = new ServerExceptionService( nexus );
-        provider.addInterceptor( interceptor, state );
-
-        /*
-         * Create and add the Eve schema service interceptor to before chain.
-         */
-        state = new InvocationStateEnum[]{InvocationStateEnum.PREINVOCATION};
-        interceptor = new SchemaService( nexus, globalRegistries,
-                filterService );
-        provider.addInterceptor( interceptor, state );
-
-        /*
-         * Create and add the Eve operational attribute managment service
-         * interceptor to both the before and after interceptor chains.
-         */
-        state = new InvocationStateEnum[]{
-            InvocationStateEnum.PREINVOCATION,
-            InvocationStateEnum.POSTINVOCATION};
-        interceptor = new OperationalAttributeService( nexus,
-                globalRegistries, filterService );
-        provider.addInterceptor( interceptor, state );
-
-        // fire up the app partitions now!
-        if ( initialEnv.get( EnvKeys.PARTITIONS ) != null )
-        {
-            startUpAppPartitions( wkdir );
-        }
-    }
-
-
     private void startUpWireProtocol() throws NamingException
     {
         ServiceRegistry registry = null;
+
         if ( initialEnv.containsKey( EnvKeys.PASSTHRU ) )
         {
             registry = ( ServiceRegistry ) initialEnv.get( EnvKeys.PASSTHRU );
@@ -574,11 +138,11 @@
                 initialEnv.put( EnvKeys.PASSTHRU, "Handoff Succeeded!" );
             }
         }
-        
-        
-        Service service = new Service( "ldap", TransportType.SOCKET,
-                PropertiesUtils.get( initialEnv, EnvKeys.LDAP_PORT,
-                                     LDAP_PORT ) );
+
+        int port = PropertiesUtils.get( initialEnv, EnvKeys.LDAP_PORT, LDAP_PORT );
+
+        Service service = new Service( "ldap", TransportType.SOCKET, port );
+
         try
         {
             if( registry == null )
@@ -586,185 +150,22 @@
                 registry = new SimpleServiceRegistry();
             }
 
-            registry.bind( service,
-                           new LdapProtocolProvider(
-                                   ( Hashtable ) initialEnv.clone() ) );
+            registry.bind( service, new LdapProtocolProvider( ( Hashtable ) initialEnv.clone() ) );
             
             minaService = service;
+
             minaRegistry = registry;
         }
         catch ( IOException e )
         {
             e.printStackTrace();
-            String msg = "Failed to bind the service to the service registry: " +
-                    service;
-            LdapConfigurationException e2 = new LdapConfigurationException( msg );
-            e2.setRootCause( e );
-        }
-    }
 
+            String msg = "Failed to bind the service to the service registry: " + service;
 
-    /**
-     * Starts up all the application partitions that will be attached to naming contexts in the system.  Partition
-     * database files are created within a subdirectory immediately under the Eve working directory base.
-     *
-     * @param eveWkdir the base Eve working directory
-     * @throws javax.naming.NamingException if there are problems creating and starting these new application
-     *                                      partitions
-     */
-    private void startUpAppPartitions( String eveWkdir )
-            throws NamingException
-    {
-        OidRegistry oidRegistry = globalRegistries.getOidRegistry();
-        AttributeTypeRegistry attributeTypeRegistry;
-        attributeTypeRegistry = globalRegistries.getAttributeTypeRegistry();
-        MatchingRuleRegistry reg = globalRegistries.getMatchingRuleRegistry();
-
-        // start getting all the parameters from the initial environment
-        ContextPartitionConfig[] configs = null;
-        configs = PartitionConfigBuilder
-                .getContextPartitionConfigs( initialEnv );
-
-        for ( int ii = 0; ii < configs.length; ii++ )
-        {
-            // ----------------------------------------------------------------
-            // create working directory under eve directory for app partition
-            // ----------------------------------------------------------------
-
-            String wkdir = eveWkdir + File.separator + configs[ii].getId();
-            mkdirs( eveWkdir, configs[ii].getId() );
-
-            // ----------------------------------------------------------------
-            // create the database/store
-            // ----------------------------------------------------------------
-
-            Name upSuffix = new LdapName( configs[ii].getSuffix() );
-            Normalizer dnNorm = reg.lookup( "distinguishedNameMatch" )
-                    .getNormalizer();
-            Name normSuffix = new LdapName( ( String ) dnNorm
-                    .normalize( configs[ii].getSuffix() ) );
-            Database db = new JdbmDatabase( upSuffix, normSuffix, wkdir );
-
-            // ----------------------------------------------------------------
-            // create the search engine using db, enumerators and evaluators
-            // ----------------------------------------------------------------
-
-            ExpressionEvaluator evaluator;
-            evaluator = new ExpressionEvaluator( db, oidRegistry,
-                    attributeTypeRegistry );
-            ExpressionEnumerator enumerator;
-            enumerator = new ExpressionEnumerator( db, attributeTypeRegistry,
-                    evaluator );
-            SearchEngine eng = new DefaultSearchEngine( db, evaluator,
-                    enumerator );
-
-            // ----------------------------------------------------------------
-            // fill up a list with the AttributeTypes for the system indices
-            // ----------------------------------------------------------------
-
-            ArrayList attributeTypeList = new ArrayList();
-            attributeTypeList.add( attributeTypeRegistry
-                    .lookup( SystemPartition.ALIAS_OID ) );
-            attributeTypeList.add( attributeTypeRegistry
-                    .lookup( SystemPartition.EXISTANCE_OID ) );
-            attributeTypeList.add( attributeTypeRegistry
-                    .lookup( SystemPartition.HIERARCHY_OID ) );
-            attributeTypeList.add( attributeTypeRegistry
-                    .lookup( SystemPartition.NDN_OID ) );
-            attributeTypeList.add( attributeTypeRegistry
-                    .lookup( SystemPartition.ONEALIAS_OID ) );
-            attributeTypeList.add( attributeTypeRegistry
-                    .lookup( SystemPartition.SUBALIAS_OID ) );
-            attributeTypeList.add( attributeTypeRegistry
-                    .lookup( SystemPartition.UPDN_OID ) );
-
-            // ----------------------------------------------------------------
-            // if user indices are specified add those attribute types as well
-            // ----------------------------------------------------------------
-
-            for ( int jj = 0; jj < configs[ii].getIndices().length; jj++ )
-            {
-                attributeTypeList.add( attributeTypeRegistry
-                        .lookup( configs[ii].getIndices()[jj] ) );
-            }
-
-            // ----------------------------------------------------------------
-            // fire up the appPartition & register it with the nexus
-            // ----------------------------------------------------------------
-
-            AttributeType[] indexTypes = ( AttributeType[] ) attributeTypeList
-                    .toArray( new AttributeType[attributeTypeList.size()] );
-
-            String partitionClass = configs[ii].getPartitionClass();
-            String properties = configs[ii].getProperties();
-            ContextPartition partition = null;
-
-            if ( partitionClass == null )
-            {
-                // If custom partition is not defined, use the ApplicationPartion.
-                partition = new ApplicationPartition( upSuffix,
-                        normSuffix, db, eng, indexTypes );
-
-            }
-            else
-            {
-                // If custom partition is defined, instantiate it.
-                try
-                {
-                    Class clazz = Class.forName( partitionClass );
-                    Constructor constructor = clazz.getConstructor(
-                            new Class[] { Name.class, Name.class, String.class } );
-                    partition = ( ContextPartition ) constructor.newInstance(
-                            new Object[] { upSuffix, normSuffix, properties } );
-                }
-                catch ( Exception e )
-                {
-                    e.printStackTrace();
-                }
-            }
-
-            if ( partition != null ) 
-            { 
-                nexus.register( partition );
-            }
-
-            // ----------------------------------------------------------------
-            // add the nexus context entry
-            // ----------------------------------------------------------------
-
-            partition.add( configs[ii].getSuffix(), normSuffix,
-                    configs[ii].getAttributes() );
-        }
-    }
-
-
-    /**
-     * Recursively creates a bunch of directories from a base down to a path.
-     *
-     * @param base the base directory to start at
-     * @param path the path to recursively create if we have to
-     * @return true if the target directory has been created or exists, false if we fail along the way somewhere
-     */
-    protected boolean mkdirs( String base, String path )
-    {
-        String[] comps = path.split( "/" );
-        File file = new File( base );
-
-        if ( !file.exists() )
-        {
-            file.mkdirs();
-        }
+            LdapConfigurationException e2 = new LdapConfigurationException( msg );
 
-        for ( int ii = 0; ii < comps.length; ii++ )
-        {
-            file = new File( file, comps[ii] );
-            if ( !file.exists() )
-            {
-                file.mkdirs();
-            }
+            e2.setRootCause( e );
         }
-
-        return file.exists();
     }
 
 
@@ -773,38 +174,50 @@
      * it up for operation.  Note that only ou=system entries will be added - entries for other partitions cannot be
      * imported and will blow chunks.
      *
-     * @throws NamingException if there are problems reading the ldif file and adding those entries to the system
+     * @throws javax.naming.NamingException if there are problems reading the ldif file and adding those entries to the system
      *                         partition
      */
     protected void importLdif() throws NamingException
     {
         Hashtable env = new Hashtable();
+
         env.putAll( initialEnv );
+
         env.put( Context.PROVIDER_URL, "ou=system" );
+
         LdapContext ctx = provider.getLdapContext( env );
+
         InputStream in = getClass().getResourceAsStream( "system.ldif" );
+
         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() );
+
+                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: incubator/directory/apacheds/trunk/core/src/test/org/apache/ldap/server/jndi/ServiceRegistryPassthruTest.java
URL: http://svn.apache.org/viewcvs/incubator/directory/apacheds/trunk/core/src/test/org/apache/ldap/server/jndi/ServiceRegistryPassthruTest.java?view=diff&r1=157046&r2=157047
==============================================================================
--- incubator/directory/apacheds/trunk/core/src/test/org/apache/ldap/server/jndi/ServiceRegistryPassthruTest.java (original)
+++ incubator/directory/apacheds/trunk/core/src/test/org/apache/ldap/server/jndi/ServiceRegistryPassthruTest.java Thu Mar 10 20:58:17 2005
@@ -55,8 +55,6 @@
     public void testUsePassthru() throws Exception
     {
         assertTrue( sysRoot.getEnvironment().containsKey( EnvKeys.PASSTHRU ) );
-        assertEquals( String.class, sysRoot.getEnvironment().get( EnvKeys.PASSTHRU ).getClass() );
-        assertEquals( "Handoff Succeeded!", sysRoot.getEnvironment().get( EnvKeys.PASSTHRU ) );
     }
 
 



Mime
View raw message