Return-Path: Delivered-To: apmail-incubator-directory-cvs-archive@www.apache.org Received: (qmail 17923 invoked from network); 11 Mar 2005 04:58:25 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 11 Mar 2005 04:58:25 -0000 Received: (qmail 59918 invoked by uid 500); 11 Mar 2005 04:58:24 -0000 Delivered-To: apmail-incubator-directory-cvs-archive@incubator.apache.org Received: (qmail 59871 invoked by uid 500); 11 Mar 2005 04:58:24 -0000 Mailing-List: contact directory-cvs-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: directory-dev@incubator.apache.org Delivered-To: mailing list directory-cvs@incubator.apache.org Received: (qmail 59853 invoked by uid 99); 11 Mar 2005 04:58:23 -0000 X-ASF-Spam-Status: No, hits=-9.8 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from minotaur.apache.org (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.28) with SMTP; Thu, 10 Mar 2005 20:58:22 -0800 Received: (qmail 17850 invoked by uid 65534); 11 Mar 2005 04:58:21 -0000 Message-ID: <20050311045821.17849.qmail@minotaur.apache.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Mailer: svnmailer-1.0.0-dev Date: Fri, 11 Mar 2005 04:58:20 -0000 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 To: directory-cvs@incubator.apache.org From: akarasulu@apache.org X-Virus-Checked: Checked X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N Author: akarasulu Date: Thu Mar 10 20:58:17 2005 New Revision: 157047 URL: http://svn.apache.org/viewcvs?view=3Drev&rev=3D157047 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 clas= s, service, what have you you can use the CoreContextFactory. The=20 ServerContextFactory will create the server socket listeners via mina and=20 will load an initial LDIF. =20 Added: incubator/directory/apacheds/trunk/core/src/main/java/org/apache/ldap/s= erver/jndi/CoreContextFactory.java Modified: incubator/directory/apacheds/trunk/core/src/main/java/org/apache/ldap/s= erver/jndi/JndiProvider.java incubator/directory/apacheds/trunk/core/src/main/java/org/apache/ldap/s= erver/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/lda= p/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=3Dau= to&rev=3D157047 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/directory/apacheds/trunk/core/src/main/java/org/apache/ldap/s= erver/jndi/CoreContextFactory.java (added) +++ incubator/directory/apacheds/trunk/core/src/main/java/org/apache/ldap/s= erver/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 impli= ed. + * 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.LdapAuthenticationNotSupportedExce= ption; +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: + * + * + * Hashtable env =3D new Hashtable(); + * env.put( Context.PROVIDER_URL, "ou=3Dsystem" ); + * env.put( + * Context.INITIAL_CONTEXT_FACTORY, "org.apache.ldap.server.jndi.ServerCon= textFactory" ); + * InitialContext initialContext =3D new InitialContext( env ); + * + * + * @author Apache Di= rectory Project + * @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 =3D Context.SECURITY_AUTHENTICATION; + + /** shorthand reference to the authentication credentials property */ + private static final String CREDS =3D Context.SECURITY_CREDENTIALS; + + /** shorthand reference to the authentication principal property */ + protected static final String PRINCIPAL =3D Context.SECURITY_PRINCIPAL; + + /** shorthand reference to the admin principal name */ + protected static final String ADMIN =3D SystemPartition.ADMIN_PRINCIPA= L; + + /** shorthand reference to the admin principal distinguished name */ + protected static final Name ADMIN_NAME =3D SystemPartition.getAdminDn(= ); + + /** default path to working directory if WKDIR_ENV property is not set= */ + public static final String DEFAULT_WKDIR =3D "server-work"; + + /** default schema classes for the SCHEMAS_ENV property if not set */ + protected static final String[] DEFAULT_SCHEMAS =3D 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 =3D null; + + /** the initial context environment that fired up the backend subsyste= m */ + 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 ServerContextFac= tory. + */ + 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 =3D provider; + } + + + public Context getInitialContext( Hashtable env ) throws NamingExcepti= on + { + env =3D ( Hashtable ) env.clone(); + + Context ctx =3D null; + + if ( env.containsKey( EnvKeys.SHUTDOWN ) ) + { + if ( this.provider =3D=3D null ) + { + return new DeadContext(); + } + + try + { + this.provider.shutdown(); + } + catch ( Throwable t ) + { + t.printStackTrace(); + } + finally + { + ctx =3D new DeadContext(); + + provider =3D null; + + initialEnv =3D 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 =3D=3D provider ) + { + // we need to check this here instead of in AuthenticationServ= ice + // because otherwise we are going to start up the system incor= rectly + if ( isAnonymous( env ) && env.containsKey( EnvKeys.DISABLE_AN= ONYMOUS ) ) + { + throw new LdapNoPermissionException( "cannot bind as anony= mous " + + "on startup while disabling anonymous binds w/ p= roperty: " + + EnvKeys.DISABLE_ANONYMOUS ); + } + + this.initialEnv =3D env; + + initialize(); + + createMode =3D createAdminAccount(); + } + + ctx =3D ( ServerContext ) provider.getLdapContext( env ); + + return ctx; + } + + + /** + * Checks to make sure security environment parameters are set correct= ly. + * + * @throws javax.naming.NamingException if the security settings are n= ot correctly configured. + */ + protected void checkSecuritySettings( Hashtable env ) throws NamingExc= eption + { + if ( env.containsKey( TYPE ) && env.get( TYPE ) !=3D null ) + { + /* + * If bind is simple make sure we have the credentials and the + * principal name set within the environment, otherwise compla= in + */ + if ( env.get( TYPE ).equals( "simple" ) ) + { + if ( !env.containsKey( CREDS ) ) + { + throw new LdapConfigurationException( "missing require= d " + + CREDS + " property for simple authentication= " ); + } + + if ( !env.containsKey( PRINCIPAL ) ) + { + throw new LdapConfigurationException( "missing require= d " + + PRINCIPAL + " property for simple authentica= tion" ); + } + } + /* + * 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 anonymou= s yet " + + CREDS + " property is set" ); + } + if ( env.containsKey( PRINCIPAL ) ) + { + throw new LdapConfigurationException( "ambiguous bind " + + "settings encountered where bind is anonymou= s 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( ResultC= odeEnum.AUTHMETHODNOTSUPPORTED ); + } + } + else if ( env.containsKey( CREDS ) ) + { + if ( !env.containsKey( PRINCIPAL ) ) + { + throw new LdapConfigurationException( "credentials provide= d " + + "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 ) !=3D 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 th= e 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 crea= ted + * 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 =3D 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 th= e way + */ + protected void initialize() throws NamingException + { + // ---------------------------------------------------------------= ----- + // Load the schema here and check that it is ok! + // ---------------------------------------------------------------= ----- + + BootstrapRegistries bootstrapRegistries =3D new BootstrapRegistrie= s(); + + BootstrapSchemaLoader loader =3D new BootstrapSchemaLoader(); + + String[] schemas =3D DEFAULT_SCHEMAS; + + if ( initialEnv.containsKey( EnvKeys.SCHEMAS ) ) + { + String schemaList =3D ( String ) initialEnv.get( EnvKeys.SCHEM= AS ); + + schemaList =3D StringTools.deepTrim( schemaList ); + + schemas =3D schemaList.split( " " ); + + for ( int ii =3D 0; ii < schemas.length; ii++ ) + { + schemas[ii] =3D schemas[ii].trim(); + } + } + + loader.load( schemas, bootstrapRegistries ); + + List errors =3D bootstrapRegistries.checkRefInteg(); + + if ( !errors.isEmpty() ) + { + NamingException e =3D new NamingException(); + + e.setRootCause( ( Throwable ) errors.get( 0 ) ); + + throw e; + } + + // ---------------------------------------------------------------= ----- + // Fire up the system partition + // ---------------------------------------------------------------= ----- + + String wkdir =3D DEFAULT_WKDIR; + + if ( initialEnv.containsKey( EnvKeys.WKDIR ) ) + { + wkdir =3D ( ( String ) initialEnv.get( EnvKeys.WKDIR ) ).trim(= ); + } + + File wkdirFile =3D new File( wkdir ); + + if ( wkdirFile.isAbsolute() ) + { + if ( !wkdirFile.exists() ) + { + throw new NamingException( "working directory " + wkdir + = " does not exist" ); + } + } + else + { + File current =3D new File( "." ); + + mkdirs( current.getAbsolutePath(), wkdir ); + } + + LdapName suffix =3D new LdapName(); + + suffix.add( SystemPartition.SUFFIX ); + + Database db =3D new JdbmDatabase( suffix, suffix, wkdir ); + + AttributeTypeRegistry attributeTypeRegistry; + + attributeTypeRegistry =3D bootstrapRegistries .getAttributeTypeReg= istry(); + + OidRegistry oidRegistry; + + oidRegistry =3D bootstrapRegistries.getOidRegistry(); + + ExpressionEvaluator evaluator; + + evaluator =3D new ExpressionEvaluator( db, oidRegistry, attributeT= ypeRegistry ); + + ExpressionEnumerator enumerator; + + enumerator =3D new ExpressionEnumerator( db, attributeTypeRegistry= , evaluator ); + + SearchEngine eng =3D new DefaultSearchEngine( db, evaluator, enume= rator ); + + AttributeType[] attributes =3D 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 =3D new SystemPartition( db, eng, attributes ); + + globalRegistries =3D new GlobalRegistries( system, bootstrapRegist= ries ); + + nexus =3D new RootNexus( system, new LockableAttributesImpl() ); + + provider =3D new JndiProvider( nexus ); + + // ---------------------------------------------------------------= ----- + // Adding interceptors + // ---------------------------------------------------------------= ----- + + /* + * Create and add the Authentication service interceptor to before + * interceptor chain. + */ + InvocationStateEnum[] state =3D new InvocationStateEnum[]{Invocati= onStateEnum.PREINVOCATION}; + + boolean allowAnonymous =3D !initialEnv.containsKey( EnvKeys.DISABL= E_ANONYMOUS ); + + Interceptor interceptor =3D new AuthenticationService( nexus, allo= wAnonymous ); + + provider.addInterceptor( interceptor, state ); + + /* + * Create and add the Eve Exception service interceptor to both the + * before and onError interceptor chains. + */ + state =3D new InvocationStateEnum[]{InvocationStateEnum.POSTINVOCA= TION}; + + FilterService filterService =3D new FilterServiceImpl(); + + interceptor =3D ( Interceptor ) filterService; + + provider.addInterceptor( interceptor, state ); + + /* + * Create and add the Authorization service interceptor to before + * interceptor chain. + */ + state =3D new InvocationStateEnum[]{InvocationStateEnum.PREINVOCAT= ION}; + + ConcreteNameComponentNormalizer normalizer; + + AttributeTypeRegistry atr =3D globalRegistries.getAttributeTypeReg= istry(); + + normalizer =3D new ConcreteNameComponentNormalizer( atr ); + + interceptor =3D new AuthorizationService( normalizer, filterServic= e ); + + provider.addInterceptor( interceptor, state ); + + /* + * Create and add the Eve Exception service interceptor to both the + * before and onError interceptor chains. + */ + state =3D new InvocationStateEnum[]{ + InvocationStateEnum.PREINVOCATION, InvocationStateEnum.FAILURE= HANDLING}; + + interceptor =3D new ServerExceptionService( nexus ); + + provider.addInterceptor( interceptor, state ); + + /* + * Create and add the Eve schema service interceptor to before cha= in. + */ + state =3D new InvocationStateEnum[]{InvocationStateEnum.PREINVOCAT= ION}; + + interceptor =3D new SchemaService( nexus, globalRegistries, filter= Service ); + + provider.addInterceptor( interceptor, state ); + + /* + * Create and add the Eve operational attribute managment service + * interceptor to both the before and after interceptor chains. + */ + state =3D new InvocationStateEnum[]{ + InvocationStateEnum.PREINVOCATION, + InvocationStateEnum.POSTINVOCATION}; + + interceptor =3D new OperationalAttributeService( nexus, globalRegi= stries, filterService ); + + provider.addInterceptor( interceptor, state ); + + // fire up the app partitions now! + if ( initialEnv.get( EnvKeys.PARTITIONS ) !=3D null ) + { + startUpAppPartitions( wkdir ); + } + } + + + /** + * Starts up all the application partitions that will be attached to n= aming 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 NamingEx= ception + { + OidRegistry oidRegistry =3D globalRegistries.getOidRegistry(); + + AttributeTypeRegistry attributeTypeRegistry; + + attributeTypeRegistry =3D globalRegistries.getAttributeTypeRegistr= y(); + + MatchingRuleRegistry reg =3D globalRegistries.getMatchingRuleRegis= try(); + + // start getting all the parameters from the initial environment + ContextPartitionConfig[] configs =3D null; + + configs =3D PartitionConfigBuilder.getContextPartitionConfigs( ini= tialEnv ); + + for ( int ii =3D 0; ii < configs.length; ii++ ) + { + // -----------------------------------------------------------= ----- + // create working directory under eve directory for app partit= ion + // -----------------------------------------------------------= ----- + + String wkdir =3D eveWkdir + File.separator + configs[ii].getId= (); + + mkdirs( eveWkdir, configs[ii].getId() ); + + // -----------------------------------------------------------= ----- + // create the database/store + // -----------------------------------------------------------= ----- + + Name upSuffix =3D new LdapName( configs[ii].getSuffix() ); + + Normalizer dnNorm =3D reg.lookup( "distinguishedNameMatch" ) .= getNormalizer(); + + Name normSuffix =3D new LdapName( ( String ) dnNorm.normalize(= configs[ii].getSuffix() ) ); + + Database db =3D new JdbmDatabase( upSuffix, normSuffix, wkdir = ); + + // -----------------------------------------------------------= ----- + // create the search engine using db, enumerators and evaluato= rs + // -----------------------------------------------------------= ----- + + ExpressionEvaluator evaluator; + + evaluator =3D new ExpressionEvaluator( db, oidRegistry, attrib= uteTypeRegistry ); + + ExpressionEnumerator enumerator; + + enumerator =3D new ExpressionEnumerator( db, attributeTypeRegi= stry, evaluator ); + + SearchEngine eng =3D new DefaultSearchEngine( db, evaluator, e= numerator ); + + // -----------------------------------------------------------= ----- + // fill up a list with the AttributeTypes for the system indic= es + // -----------------------------------------------------------= ----- + + ArrayList attributeTypeList =3D new ArrayList(); + + attributeTypeList.add( attributeTypeRegistry.lookup( SystemPar= tition.ALIAS_OID ) ); + + attributeTypeList.add( attributeTypeRegistry.lookup( SystemPar= tition.EXISTANCE_OID ) ); + + attributeTypeList.add( attributeTypeRegistry.lookup( SystemPar= tition.HIERARCHY_OID ) ); + + attributeTypeList.add( attributeTypeRegistry.lookup( SystemPar= tition.NDN_OID ) ); + + attributeTypeList.add( attributeTypeRegistry.lookup( SystemPar= tition.ONEALIAS_OID ) ); + + attributeTypeList.add( attributeTypeRegistry.lookup( SystemPar= tition.SUBALIAS_OID ) ); + + attributeTypeList.add( attributeTypeRegistry.lookup( SystemPar= tition.UPDN_OID ) ); + + // -----------------------------------------------------------= ----- + // if user indices are specified add those attribute types as = well + // -----------------------------------------------------------= ----- + + for ( int jj =3D 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 =3D ( AttributeType[] ) attributeTy= peList + .toArray( new AttributeType[attributeTypeList.size()] = ); + + String partitionClass =3D configs[ii].getPartitionClass(); + + String properties =3D configs[ii].getProperties(); + + ContextPartition partition =3D null; + + if ( partitionClass =3D=3D null ) + { + // If custom partition is not defined, use the Application= Partion. + partition =3D new ApplicationPartition( upSuffix, normSuff= ix, db, eng, indexTypes ); + + } + else + { + // If custom partition is defined, instantiate it. + try + { + Class clazz =3D Class.forName( partitionClass ); + + Constructor constructor =3D clazz.getConstructor( + new Class[] { Name.class, Name.class, String.c= lass } ); + + partition =3D ( ContextPartition ) constructor.newInst= ance( + new Object[] { upSuffix, normSuffix, propertie= s } ); + } + catch ( Exception e ) + { + e.printStackTrace(); + } + } + + if ( partition !=3D null )=20 + {=20 + nexus.register( partition ); + } + + // -----------------------------------------------------------= ----- + // add the nexus context entry + // -----------------------------------------------------------= ----- + + partition.add( configs[ii].getSuffix(), normSuffix, configs[ii= ]=2EgetAttributes() ); + } + } + + + /** + * Recursively creates a bunch of directories from a base down to a pa= th. + * + * @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, fa= lse if we fail along the way somewhere + */ + protected boolean mkdirs( String base, String path ) + { + String[] comps =3D path.split( "/" ); + + File file =3D new File( base ); + + if ( !file.exists() ) + { + file.mkdirs(); + } + + for ( int ii =3D 0; ii < comps.length; ii++ ) + { + file =3D 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=3Ddiff&r1= =3D157046&r2=3D157047 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/directory/apacheds/trunk/core/src/main/java/org/apache/ldap/s= erver/jndi/JndiProvider.java (original) +++ incubator/directory/apacheds/trunk/core/src/main/java/org/apache/ldap/s= erver/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=3D= diff&r1=3D157046&r2=3D157047 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/directory/apacheds/trunk/core/src/main/java/org/apache/ldap/s= erver/jndi/ServerContextFactory.java (original) +++ incubator/directory/apacheds/trunk/core/src/main/java/org/apache/ldap/s= erver/jndi/ServerContextFactory.java Thu Mar 10 20:58:17 2005 @@ -17,60 +17,24 @@ package org.apache.ldap.server.jndi; =20 =20 -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; =20 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; =20 -import org.apache.ldap.common.exception.LdapAuthenticationNotSupportedExce= ption; 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 @@ =20 =20 /** - * An LDAPd server-side provider implementation of a InitialContextFactory= . Can be utilized via JNDI API in the standard - * fashion: Hashtable env =3D new Hashtable(); env.put( Context.PRO= VIDER_URL, "ou=3Dsystem" ); env.put( - * Context.INITIAL_CONTEXT_FACTORY, "org.apache.ldap.server.jndi.ServerCon= textFactory" ); InitialContext initialContext - * =3D new InitialContext( env ); + * Adds additional bootstrapping for server socket listeners when firing + * up the server. * * @author Apache Di= rectory Project * @version $Rev$ * @see javax.naming.spi.InitialContextFactory */ -public class ServerContextFactory implements InitialContextFactory +public class ServerContextFactory extends CoreContextFactory { - private static final String TYPE =3D Context.SECURITY_AUTHENTICATION; - - private static final String CREDS =3D Context.SECURITY_CREDENTIALS; - - private static final String PRINCIPAL =3D Context.SECURITY_PRINCIPAL; - - private static final String ADMIN =3D SystemPartition.ADMIN_PRINCIPAL; - - private static final Name ADMIN_NAME =3D SystemPartition.getAdminDn(); - - /** - * the default LDAP port to use - */ + /** the default LDAP port to use */ private static final int LDAP_PORT =3D 389; =20 - /** - * default path to working directory if WKDIR_ENV property is not set - */ - public static final String DEFAULT_WKDIR =3D "server-work"; - - /** - * default schema classes for the SCHEMAS_ENV property if not set - */ - private static final String[] DEFAULT_SCHEMAS =3D 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 // -------------------------------------------------------------------= ----- =20 - /** - * The singleton JndiProvider instance - */ - private JndiProvider provider =3D 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; =20 private ServiceRegistry minaRegistry; @@ -152,34 +68,18 @@ */ public ServerContextFactory() { - JndiProvider.setProviderOn( this ); + super(); } =20 =20 - /** - * 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 =3D a_provider; - } - - - /** - * @see javax.naming.spi.InitialContextFactory#getInitialContext( java= .util.Hashtable) - */ public Context getInitialContext( Hashtable env ) throws NamingExcepti= on { - env =3D ( Hashtable ) env.clone(); Context ctx =3D null; =20 if ( env.containsKey( EnvKeys.SHUTDOWN ) ) { if ( this.provider =3D=3D null ) { - // monitor.shutDownCalledOnStoppedProvider() return new DeadContext(); } =20 @@ -199,372 +99,36 @@ finally { ctx =3D new DeadContext(); + provider =3D null; + initialEnv =3D null; } =20 return ctx; } =20 - if ( env.containsKey( EnvKeys.SYNC ) ) - { - provider.sync(); - return provider.getLdapContext( env ); - } - - checkSecuritySettings( env ); + ctx =3D super.getInitialContext( env ); =20 - if ( isAnonymous( env ) ) + // fire up the front end if we have not explicitly disabled it + if ( initialEnv !=3D null && ! initialEnv.containsKey( EnvKeys.DIS= ABLE_PROTOCOL ) ) { - env.put( PRINCIPAL, "" ); + startUpWireProtocol(); } =20 - // fire up the backend subsystem if we need to - if ( null =3D=3D provider ) + if ( createMode ) { - // we need to check this here instead of in AuthenticationServ= ice - // because otherwise we are going to start up the system incor= rectly - if ( isAnonymous( env ) - && env.containsKey( EnvKeys.DISABLE_ANONYMOUS ) ) - { - throw new LdapNoPermissionException( "cannot bind as anony= mous " - + "on startup while disabling anonymous binds w/ p= roperty: " - + EnvKeys.DISABLE_ANONYMOUS ); - } - - this.initialEnv =3D env; - - initialize(); - boolean createMode =3D createAdminAccount(); - - if ( createMode ) - { - importLdif(); - } - - // fire up the front end if we have not explicitly disabled it - if ( !initialEnv.containsKey( EnvKeys.DISABLE_PROTOCOL ) ) - { - startUpWireProtocol(); - } + importLdif(); } =20 - ctx =3D ( ServerContext ) provider.getLdapContext( env ); return ctx; } =20 =20 - /** - * Checks to make sure security environment parameters are set correct= ly. - * - * @throws NamingException if the security settings are not correctly = configured. - */ - private void checkSecuritySettings( Hashtable env ) - throws NamingException - { - if ( env.containsKey( TYPE ) && env.get( TYPE ) !=3D null ) - { - /* - * If bind is simple make sure we have the credentials and the - * principal name set within the environment, otherwise compla= in - */ - if ( env.get( TYPE ).equals( "simple" ) ) - { - if ( !env.containsKey( CREDS ) ) - { - throw new LdapConfigurationException( "missing require= d " - + CREDS - + " property for simple authentication" ); - } - - if ( !env.containsKey( PRINCIPAL ) ) - { - throw new LdapConfigurationException( "missing require= d " - + 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 anonymou= s yet " - + CREDS - + " property is set" ); - } - if ( env.containsKey( PRINCIPAL ) ) - { - throw new LdapConfigurationException( "ambiguous bind " - + "settings encountered where bind is anonymou= s 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( ResultC= odeEnum.AUTHMETHODNOTSUPPORTED ); - } - } - else if ( env.containsKey( CREDS ) ) - { - if ( !env.containsKey( PRINCIPAL ) ) - { - throw new LdapConfigurationException( "credentials provide= d " - + "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 ) !=3D 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 th= e 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 crea= ted - * 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 =3D 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 =3D new BootstrapRegistrie= s(); - BootstrapSchemaLoader loader =3D new BootstrapSchemaLoader(); - - String[] schemas =3D DEFAULT_SCHEMAS; - if ( initialEnv.containsKey( EnvKeys.SCHEMAS ) ) - { - String schemaList =3D ( String ) initialEnv.get( EnvKeys.SCHEM= AS ); - schemaList =3D StringTools.deepTrim( schemaList ); - schemas =3D schemaList.split( " " ); - for ( int ii =3D 0; ii < schemas.length; ii++ ) - { - schemas[ii] =3D schemas[ii].trim(); - } - } - - loader.load( schemas, bootstrapRegistries ); - List errors =3D bootstrapRegistries.checkRefInteg(); - if ( !errors.isEmpty() ) - { - NamingException e =3D new NamingException(); - e.setRootCause( ( Throwable ) errors.get( 0 ) ); - throw e; - } - - // ---------------------------------------------------------------= ----- - // Fire up the system partition - // ---------------------------------------------------------------= ----- - - String wkdir =3D DEFAULT_WKDIR; - if ( initialEnv.containsKey( EnvKeys.WKDIR ) ) - { - wkdir =3D ( ( String ) initialEnv.get( EnvKeys.WKDIR ) ).trim(= ); - } - - File wkdirFile =3D new File( wkdir ); - if ( wkdirFile.isAbsolute() ) - { - if ( !wkdirFile.exists() ) - { - throw new NamingException( "working directory " + wkdir - + " does not exist" ); - } - } - else - { - File current =3D new File( "." ); - mkdirs( current.getAbsolutePath(), wkdir ); - } - - LdapName suffix =3D new LdapName(); - suffix.add( SystemPartition.SUFFIX ); - Database db =3D new JdbmDatabase( suffix, suffix, wkdir ); - - AttributeTypeRegistry attributeTypeRegistry; - attributeTypeRegistry =3D bootstrapRegistries - .getAttributeTypeRegistry(); - OidRegistry oidRegistry; - oidRegistry =3D bootstrapRegistries.getOidRegistry(); - - ExpressionEvaluator evaluator; - evaluator =3D new ExpressionEvaluator( db, oidRegistry, - attributeTypeRegistry ); - - ExpressionEnumerator enumerator; - enumerator =3D new ExpressionEnumerator( db, attributeTypeRegistry, - evaluator ); - - SearchEngine eng =3D new DefaultSearchEngine( db, evaluator, enume= rator ); - - AttributeType[] attributes =3D 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 =3D new SystemPartition( db, eng, attributes ); - globalRegistries =3D new GlobalRegistries( system, bootstrapRegist= ries ); - nexus =3D new RootNexus( system, new LockableAttributesImpl() ); - provider =3D new JndiProvider( nexus ); - - // ---------------------------------------------------------------= ----- - // Adding interceptors - // ---------------------------------------------------------------= ----- - - /* - * Create and add the Authentication service interceptor to before - * interceptor chain. - */ - InvocationStateEnum[] state =3D new InvocationStateEnum[]{Invocati= onStateEnum.PREINVOCATION}; - boolean allowAnonymous =3D !initialEnv - .containsKey( EnvKeys.DISABLE_ANONYMOUS ); - Interceptor interceptor =3D 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 =3D new InvocationStateEnum[]{InvocationStateEnum.POSTINVOCA= TION}; - FilterService filterService =3D new FilterServiceImpl(); - interceptor =3D ( Interceptor ) filterService; - provider.addInterceptor( interceptor, state ); - - /* - * Create and add the Authorization service interceptor to before - * interceptor chain. - */ - state =3D new InvocationStateEnum[]{InvocationStateEnum.PREINVOCAT= ION}; - ConcreteNameComponentNormalizer normalizer; - AttributeTypeRegistry atr =3D globalRegistries - .getAttributeTypeRegistry(); - normalizer =3D new ConcreteNameComponentNormalizer( atr ); - interceptor =3D new AuthorizationService( normalizer, filterServic= e ); - provider.addInterceptor( interceptor, state ); - - /* - * Create and add the Eve Exception service interceptor to both the - * before and onError interceptor chains. - */ - state =3D new InvocationStateEnum[]{ - InvocationStateEnum.PREINVOCATION, - InvocationStateEnum.FAILUREHANDLING}; - interceptor =3D new ServerExceptionService( nexus ); - provider.addInterceptor( interceptor, state ); - - /* - * Create and add the Eve schema service interceptor to before cha= in. - */ - state =3D new InvocationStateEnum[]{InvocationStateEnum.PREINVOCAT= ION}; - interceptor =3D 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 =3D new InvocationStateEnum[]{ - InvocationStateEnum.PREINVOCATION, - InvocationStateEnum.POSTINVOCATION}; - interceptor =3D new OperationalAttributeService( nexus, - globalRegistries, filterService ); - provider.addInterceptor( interceptor, state ); - - // fire up the app partitions now! - if ( initialEnv.get( EnvKeys.PARTITIONS ) !=3D null ) - { - startUpAppPartitions( wkdir ); - } - } - - private void startUpWireProtocol() throws NamingException { ServiceRegistry registry =3D null; + if ( initialEnv.containsKey( EnvKeys.PASSTHRU ) ) { registry =3D ( ServiceRegistry ) initialEnv.get( EnvKeys.PASST= HRU ); @@ -574,11 +138,11 @@ initialEnv.put( EnvKeys.PASSTHRU, "Handoff Succeeded!" ); } } - =20 - =20 - Service service =3D new Service( "ldap", TransportType.SOCKET, - PropertiesUtils.get( initialEnv, EnvKeys.LDAP_PORT, - LDAP_PORT ) ); + + int port =3D PropertiesUtils.get( initialEnv, EnvKeys.LDAP_PORT, L= DAP_PORT ); + + Service service =3D new Service( "ldap", TransportType.SOCKET, por= t ); + try { if( registry =3D=3D null ) @@ -586,185 +150,22 @@ registry =3D new SimpleServiceRegistry(); } =20 - registry.bind( service, - new LdapProtocolProvider( - ( Hashtable ) initialEnv.clone() ) ); + registry.bind( service, new LdapProtocolProvider( ( Hashtable = ) initialEnv.clone() ) ); =20 minaService =3D service; + minaRegistry =3D registry; } catch ( IOException e ) { e.printStackTrace(); - String msg =3D "Failed to bind the service to the service regi= stry: " + - service; - LdapConfigurationException e2 =3D new LdapConfigurationExcepti= on( msg ); - e2.setRootCause( e ); - } - } =20 + String msg =3D "Failed to bind the service to the service regi= stry: " + service; =20 - /** - * Starts up all the application partitions that will be attached to n= aming 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 =3D globalRegistries.getOidRegistry(); - AttributeTypeRegistry attributeTypeRegistry; - attributeTypeRegistry =3D globalRegistries.getAttributeTypeRegistr= y(); - MatchingRuleRegistry reg =3D globalRegistries.getMatchingRuleRegis= try(); - - // start getting all the parameters from the initial environment - ContextPartitionConfig[] configs =3D null; - configs =3D PartitionConfigBuilder - .getContextPartitionConfigs( initialEnv ); - - for ( int ii =3D 0; ii < configs.length; ii++ ) - { - // -----------------------------------------------------------= ----- - // create working directory under eve directory for app partit= ion - // -----------------------------------------------------------= ----- - - String wkdir =3D eveWkdir + File.separator + configs[ii].getId= (); - mkdirs( eveWkdir, configs[ii].getId() ); - - // -----------------------------------------------------------= ----- - // create the database/store - // -----------------------------------------------------------= ----- - - Name upSuffix =3D new LdapName( configs[ii].getSuffix() ); - Normalizer dnNorm =3D reg.lookup( "distinguishedNameMatch" ) - .getNormalizer(); - Name normSuffix =3D new LdapName( ( String ) dnNorm - .normalize( configs[ii].getSuffix() ) ); - Database db =3D new JdbmDatabase( upSuffix, normSuffix, wkdir = ); - - // -----------------------------------------------------------= ----- - // create the search engine using db, enumerators and evaluato= rs - // -----------------------------------------------------------= ----- - - ExpressionEvaluator evaluator; - evaluator =3D new ExpressionEvaluator( db, oidRegistry, - attributeTypeRegistry ); - ExpressionEnumerator enumerator; - enumerator =3D new ExpressionEnumerator( db, attributeTypeRegi= stry, - evaluator ); - SearchEngine eng =3D new DefaultSearchEngine( db, evaluator, - enumerator ); - - // -----------------------------------------------------------= ----- - // fill up a list with the AttributeTypes for the system indic= es - // -----------------------------------------------------------= ----- - - ArrayList attributeTypeList =3D 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 =3D 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 =3D ( AttributeType[] ) attributeTy= peList - .toArray( new AttributeType[attributeTypeList.size()] = ); - - String partitionClass =3D configs[ii].getPartitionClass(); - String properties =3D configs[ii].getProperties(); - ContextPartition partition =3D null; - - if ( partitionClass =3D=3D null ) - { - // If custom partition is not defined, use the Application= Partion. - partition =3D new ApplicationPartition( upSuffix, - normSuffix, db, eng, indexTypes ); - - } - else - { - // If custom partition is defined, instantiate it. - try - { - Class clazz =3D Class.forName( partitionClass ); - Constructor constructor =3D clazz.getConstructor( - new Class[] { Name.class, Name.class, String.c= lass } ); - partition =3D ( ContextPartition ) constructor.newInst= ance( - new Object[] { upSuffix, normSuffix, propertie= s } ); - } - catch ( Exception e ) - { - e.printStackTrace(); - } - } - - if ( partition !=3D null )=20 - {=20 - 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 pa= th. - * - * @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, fa= lse if we fail along the way somewhere - */ - protected boolean mkdirs( String base, String path ) - { - String[] comps =3D path.split( "/" ); - File file =3D new File( base ); - - if ( !file.exists() ) - { - file.mkdirs(); - } + LdapConfigurationException e2 =3D new LdapConfigurationExcepti= on( msg ); =20 - for ( int ii =3D 0; ii < comps.length; ii++ ) - { - file =3D new File( file, comps[ii] ); - if ( !file.exists() ) - { - file.mkdirs(); - } + e2.setRootCause( e ); } - - return file.exists(); } =20 =20 @@ -773,38 +174,50 @@ * it up for operation. Note that only ou=3Dsystem entries will be ad= ded - 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 =3D new Hashtable(); + env.putAll( initialEnv ); + env.put( Context.PROVIDER_URL, "ou=3Dsystem" ); + LdapContext ctx =3D provider.getLdapContext( env ); + InputStream in =3D getClass().getResourceAsStream( "system.ldif" ); + LdifParser parser =3D new LdifParserImpl(); =20 try { LdifIterator iterator =3D new LdifIterator( in ); + while ( iterator.hasNext() ) { Attributes attributes =3D new LockableAttributesImpl(); + String ldif =3D ( String ) iterator.next(); + parser.parse( attributes, ldif ); - Name dn =3D new LdapName( ( String ) attributes.remove( "d= n" ) - .get() ); + + Name dn =3D new LdapName( ( String ) attributes.remove( "d= n" ).get() ); =20 dn.remove( 0 ); + ctx.createSubcontext( dn, attributes ); } } catch ( Exception e ) { String msg =3D "failed while trying to parse system ldif file"; + NamingException ne =3D 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= =3Ddiff&r1=3D157046&r2=3D157047 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- 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 ) ); } =20 =20