Author: akarasulu
Date: Sun Oct 31 01:49:28 2004
New Revision: 56134
Added:
incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/jndi/system.ldif
Modified:
incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/jndi/EveContextFactory.java
incubator/directory/eve/trunk/backend/core/src/test/org/apache/eve/jndi/SearchContextTest.java
Log:
Changes ...
o added LDIF import capability to context factory
o added new LDIF file with the set of entries to be added to the system
partion when the system is bootstrap for the very first time after
creating its database
o note that the new LDIF entry additions shifted the results in searches
so we had to update the test cases for them
Modified:
incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/jndi/EveContextFactory.java
==============================================================================
---
incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/jndi/EveContextFactory.java
(original)
+++
incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/jndi/EveContextFactory.java
Sun Oct 31 01:49:28 2004
@@ -1,3 +1,19 @@
+/*
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
package org.apache.eve.jndi;
@@ -6,12 +22,9 @@
import java.util.ArrayList;
import java.io.File;
import java.io.InputStream;
-import java.io.IOException;
-import javax.naming.Name;
-import javax.naming.Context;
-import javax.naming.NamingException;
-import javax.naming.ConfigurationException;
+import javax.naming.*;
+import javax.naming.ldap.LdapContext;
import javax.naming.directory.Attributes;
import javax.naming.spi.InitialContextFactory;
@@ -22,6 +35,8 @@
import org.apache.ldap.common.util.ArrayUtils;
import org.apache.ldap.common.util.DateUtils;
import org.apache.ldap.common.ldif.LdifIterator;
+import org.apache.ldap.common.ldif.LdifParser;
+import org.apache.ldap.common.ldif.LdifParserImpl;
import org.apache.eve.RootNexus;
import org.apache.eve.SystemPartition;
@@ -192,7 +207,12 @@
}
initialize();
- createAdminAccount();
+ boolean createMode = createAdminAccount();
+
+ if ( createMode )
+ {
+ importLdif();
+ }
}
EveContext ctx = ( EveContext ) provider.getLdapContext( env );
@@ -386,7 +406,6 @@
interceptor = new OperationalAttributeService( nexus,
globalRegistries, filterService );
provider.addInterceptor( interceptor, state );
-
// fire up the app partitions now!
if ( initialEnv.get( PARTITIONS_ENV ) != null )
{
@@ -508,15 +527,33 @@
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 = ( InputStream ) 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() );
+
+ dn.remove( 0 );
+ ctx.createSubcontext( dn, attributes );
+ }
}
- catch ( IOException e )
+ catch ( Exception e )
{
- NamingException ne = new EveConfigurationException();
+ String msg = "failed while trying to parse system ldif file";
+ NamingException ne = new EveConfigurationException( msg );
+ ne.setRootCause( e );
+ throw ne;
}
}
}
Added:
incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/jndi/system.ldif
==============================================================================
--- (empty file)
+++
incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/jndi/system.ldif
Sun Oct 31 01:49:28 2004
@@ -0,0 +1,53 @@
+#
+# 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.
+#
+# System partition entries
+#
+
+dn: ou=users,ou=system
+objectClass: top
+objectClass: organizationalUnit
+ou: users
+
+dn: uid=akarasulu,ou=users,ou=system
+cn: Alex Karasulu
+sn: Karasulu
+givenname: Alex
+objectclass: top
+objectclass: person
+objectclass: organizationalPerson
+objectclass: inetOrgPerson
+ou: Engineering
+ou: People
+l: Bogusville
+uid: akarasulu
+mail: [EMAIL PROTECTED]
+telephonenumber: +1 408 555 4798
+facsimiletelephonenumber: +1 408 555 9751
+roomnumber: 4612
+userpassword: test
+
+dn: ou=groups,ou=system
+objectClass: top
+objectClass: organizationalUnit
+ou: groups
+
+dn: cn=administrators,ou=groups,ou=system
+objectClass: top
+objectclass: groupofuniquenames
+cn: administrators
+ou: groups
+uniquemember: uid=akarasulu,ou=users,ou=system
+
Modified:
incubator/directory/eve/trunk/backend/core/src/test/org/apache/eve/jndi/SearchContextTest.java
==============================================================================
---
incubator/directory/eve/trunk/backend/core/src/test/org/apache/eve/jndi/SearchContextTest.java
(original)
+++
incubator/directory/eve/trunk/backend/core/src/test/org/apache/eve/jndi/SearchContextTest.java
Sun Oct 31 01:49:28 2004
@@ -67,7 +67,7 @@
map.put( result.getName(), result.getAttributes() );
}
- assertEquals( "Expected number of results returned was incorrect!", 3,
map.size() );
+ assertEquals( "Expected number of results returned was incorrect!", 5,
map.size() );
assertTrue( map.containsKey( "ou=testing00,ou=system" ) );
assertTrue( map.containsKey( "ou=testing01,ou=system" ) );
assertTrue( map.containsKey( "ou=testing02,ou=system" ) );
@@ -90,7 +90,7 @@
map.put( result.getName(), result.getAttributes() );
}
- assertEquals( "Expected number of results returned was incorrect", 5,
map.size() );
+ assertEquals( "Expected number of results returned was incorrect", 9,
map.size() );
assertTrue( map.containsKey( "ou=system" ) );
assertTrue( map.containsKey( "ou=testing00,ou=system" ) );
assertTrue( map.containsKey( "ou=testing01,ou=system" ) );