Return-Path: Delivered-To: apmail-directory-commits-archive@www.apache.org Received: (qmail 39593 invoked from network); 29 Oct 2005 00:58:28 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 29 Oct 2005 00:58:28 -0000 Received: (qmail 57838 invoked by uid 500); 29 Oct 2005 00:58:27 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 57812 invoked by uid 500); 29 Oct 2005 00:58:27 -0000 Mailing-List: contact commits-help@directory.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@directory.apache.org Delivered-To: mailing list commits@directory.apache.org Received: (qmail 57801 invoked by uid 99); 29 Oct 2005 00:58:27 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 28 Oct 2005 17:58:27 -0700 X-ASF-Spam-Status: No, hits=-8.6 required=10.0 tests=ALL_TRUSTED,INFO_TLD,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [209.237.227.194] (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.29) with SMTP; Fri, 28 Oct 2005 17:58:23 -0700 Received: (qmail 39494 invoked by uid 65534); 29 Oct 2005 00:58:05 -0000 Message-ID: <20051029005805.39485.qmail@minotaur.apache.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r329335 - in /directory/apacheds/trunk: core/src/main/schema/ main/ main/src/main/java/org/apache/ldap/server/configuration/ main/src/main/java/org/apache/ldap/server/jndi/ Date: Sat, 29 Oct 2005 00:58:04 -0000 To: commits@directory.apache.org From: akarasulu@apache.org X-Mailer: svnmailer-1.0.5 X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Author: akarasulu Date: Fri Oct 28 17:57:58 2005 New Revision: 329335 URL: http://svn.apache.org/viewcvs?rev=329335&view=rev Log: changes ... o added ldif loading capability - configuration was modified to point to a file or directory to load LDIF files: if file its loaded, if directory contents of directory are loaded in the order of a alphabetical listing - added configuration for LDIF filtering while loading - incorporated changes from 329334 to use filters o server remembers if it loaded an LDIF and does not attempt to load it again - added schema elements to support this - added area under ou=loadedLdifFiles,ou=configuration,ou=system to keep a timestamped reference to the file that was LDIF loaded Modified: directory/apacheds/trunk/core/src/main/schema/apache.schema directory/apacheds/trunk/main/server.xml directory/apacheds/trunk/main/src/main/java/org/apache/ldap/server/configuration/MutableServerStartupConfiguration.java directory/apacheds/trunk/main/src/main/java/org/apache/ldap/server/configuration/ServerStartupConfiguration.java directory/apacheds/trunk/main/src/main/java/org/apache/ldap/server/jndi/ServerContextFactory.java Modified: directory/apacheds/trunk/core/src/main/schema/apache.schema URL: http://svn.apache.org/viewcvs/directory/apacheds/trunk/core/src/main/schema/apache.schema?rev=329335&r1=329334&r2=329335&view=diff ============================================================================== --- directory/apacheds/trunk/core/src/main/schema/apache.schema (original) +++ directory/apacheds/trunk/core/src/main/schema/apache.schema Fri Oct 28 17:57:58 2005 @@ -173,3 +173,28 @@ STRUCTURAL MUST ( cn $ apacheCatalogEntryBaseDn ) MAY ( apacheCatalogEntryName ) ) + +attributetype ( 1.2.6.1.4.1.18060.1.1.1.3.19 + NAME 'windowsFilePath' + DESC 'A windows file path where case does not make a difference' + EQUALITY caseIgnoreIA5Match + SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 SINGLE-VALUE ) + +attributetype ( 1.2.6.1.4.1.18060.1.1.1.3.20 + NAME 'unixFilePath' + DESC 'A UNIX file path where case does make a difference' + EQUALITY caseExactIA5Match + SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 SINGLE-VALUE ) + +objectclass ( 1.2.6.1.4.1.18060.1.1.1.4.6 + NAME 'windowsFile' + SUP top + STRUCTURAL + MUST ( windowsFilePath ) ) + +objectclass ( 1.2.6.1.4.1.18060.1.1.1.4.7 + NAME 'unixFile' + SUP top + STRUCTURAL + MUST ( unixFilePath ) ) + Modified: directory/apacheds/trunk/main/server.xml URL: http://svn.apache.org/viewcvs/directory/apacheds/trunk/main/server.xml?rev=329335&r1=329334&r2=329335&view=diff ============================================================================== --- directory/apacheds/trunk/main/server.xml (original) +++ directory/apacheds/trunk/main/server.xml Fri Oct 28 17:57:58 2005 @@ -13,12 +13,35 @@ uid=admin,ou=system secret photo personalSignature audio jpegPhoto javaSerializedData userPassword userCertificate cACertificate authorityRevocationList certificateRevocationList crossCertificatePair x500UniqueIdentifier krb5Key + ou=Users,dc=apache,dc=org apache.org + + + + + + + + + + + + + false false false Modified: directory/apacheds/trunk/main/src/main/java/org/apache/ldap/server/configuration/MutableServerStartupConfiguration.java URL: http://svn.apache.org/viewcvs/directory/apacheds/trunk/main/src/main/java/org/apache/ldap/server/configuration/MutableServerStartupConfiguration.java?rev=329335&r1=329334&r2=329335&view=diff ============================================================================== --- directory/apacheds/trunk/main/src/main/java/org/apache/ldap/server/configuration/MutableServerStartupConfiguration.java (original) +++ directory/apacheds/trunk/main/src/main/java/org/apache/ldap/server/configuration/MutableServerStartupConfiguration.java Fri Oct 28 17:57:58 2005 @@ -115,4 +115,14 @@ { super.setExtendedOperationHandlers( handlers ); } + + public void setLdifDirectory( File ldifDirectory ) + { + super.setLdifDirectory( ldifDirectory ); + } + + public void setLdifFilters( List ldifFilters ) + { + super.setLdifFilters( ldifFilters ); + } } Modified: directory/apacheds/trunk/main/src/main/java/org/apache/ldap/server/configuration/ServerStartupConfiguration.java URL: http://svn.apache.org/viewcvs/directory/apacheds/trunk/main/src/main/java/org/apache/ldap/server/configuration/ServerStartupConfiguration.java?rev=329335&r1=329334&r2=329335&view=diff ============================================================================== --- directory/apacheds/trunk/main/src/main/java/org/apache/ldap/server/configuration/ServerStartupConfiguration.java (original) +++ directory/apacheds/trunk/main/src/main/java/org/apache/ldap/server/configuration/ServerStartupConfiguration.java Fri Oct 28 17:57:58 2005 @@ -21,10 +21,14 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; +import java.util.List; +import java.io.File; import org.apache.ldap.server.protocol.ExtendedOperationHandler; import org.apache.mina.registry.ServiceRegistry; import org.apache.mina.registry.SimpleServiceRegistry; +import org.apache.protocol.common.store.LdifLoadFilter; + /** * A {@link StartupConfiguration} that starts up ApacheDS with network layer support. @@ -44,6 +48,8 @@ private boolean enableChangePassword = false; private boolean enableNtp = false; private final Collection extendedOperationHandlers = new ArrayList(); + private File ldifDirectory = null; + private final List ldifFilters = new ArrayList(); protected ServerStartupConfiguration() { @@ -168,12 +174,12 @@ } this.minaServiceRegistry = minaServiceRegistry; } - + public Collection getExtendedOperationHandlers() { return new ArrayList( extendedOperationHandlers ); } - + protected void setExtendedOperationHandlers( Collection handlers ) { for( Iterator i = handlers.iterator(); i.hasNext(); ) @@ -184,8 +190,38 @@ "The specified handler collection contains an element which is not an ExtendedOperationHandler." ); } } - + this.extendedOperationHandlers.clear(); this.extendedOperationHandlers.addAll( handlers ); + } + + public File getLdifDirectory() + { + return this.ldifDirectory; + } + + protected void setLdifDirectory( File ldifDirectory ) + { + this.ldifDirectory = ldifDirectory; + } + + public List getLdifFilters() + { + return new ArrayList( ldifFilters ); + } + + protected void setLdifFilters( List filters ) + { + for( int ii = 0; ii < filters.size(); ii++ ) + { + if( !( filters.get( ii ) instanceof LdifLoadFilter ) ) + { + throw new IllegalArgumentException( + "The specified filter collection contains an element which is not an LdifLoadFilter." ); + } + } + + this.ldifFilters.clear(); + this.ldifFilters.addAll( filters ); } } Modified: directory/apacheds/trunk/main/src/main/java/org/apache/ldap/server/jndi/ServerContextFactory.java URL: http://svn.apache.org/viewcvs/directory/apacheds/trunk/main/src/main/java/org/apache/ldap/server/jndi/ServerContextFactory.java?rev=329335&r1=329334&r2=329335&view=diff ============================================================================== --- directory/apacheds/trunk/main/src/main/java/org/apache/ldap/server/jndi/ServerContextFactory.java (original) +++ directory/apacheds/trunk/main/src/main/java/org/apache/ldap/server/jndi/ServerContextFactory.java Fri Oct 28 17:57:58 2005 @@ -18,11 +18,17 @@ import java.io.IOException; +import java.io.FileFilter; +import java.io.File; import java.net.InetSocketAddress; import java.util.Hashtable; import java.util.Iterator; import javax.naming.NamingException; +import javax.naming.Context; +import javax.naming.directory.DirContext; +import javax.naming.directory.Attributes; +import javax.naming.directory.BasicAttributes; import org.apache.kerberos.kdc.KdcConfiguration; import org.apache.kerberos.kdc.KerberosServer; @@ -39,6 +45,7 @@ import org.apache.ntp.NtpServer; import org.apache.ntp.NtpConfiguration; import org.apache.protocol.common.LoadStrategy; +import org.apache.protocol.common.store.LdifFileLoader; import org.apache.changepw.ChangePasswordServer; import org.apache.changepw.ChangePasswordConfiguration; import org.slf4j.Logger; @@ -55,7 +62,9 @@ */ public class ServerContextFactory extends CoreContextFactory { - private static Logger log = LoggerFactory.getLogger( ServerContextFactory.class.getName() ); + private static final Logger log = LoggerFactory.getLogger( ServerContextFactory.class.getName() ); + private static final String LDIF_FILES_DN = "ou=loadedLdifFiles,ou=configuration,ou=system"; + private static Service ldapService; private static KerberosServer kdcServer; private static ChangePasswordServer changePasswordServer; @@ -122,6 +131,8 @@ ( ServerStartupConfiguration ) service.getConfiguration().getStartupConfiguration(); Hashtable env = service.getConfiguration().getEnvironment(); + loadLdifs( service ); + if ( cfg.isEnableNetworking() ) { setupRegistry( cfg ); @@ -169,6 +180,149 @@ } } } + + + private void ensureLdifFileBase( DirContext root ) throws NamingException + { + Attributes entry = new BasicAttributes( "ou", "loadedLdifFiles", true ); + entry.put( "objectClass", "top" ); + entry.get( "objectClass" ).add( "organizationalUnit" ); + try + { + root.createSubcontext( LDIF_FILES_DN, entry ); + log.info( "Creating " + LDIF_FILES_DN ); + } + catch( NamingException e ) { log.info( LDIF_FILES_DN + " exists" );} + } + + + private final static String WINDOWSFILE_ATTR = "windowsFilePath"; + private final static String UNIXFILE_ATTR = "unixFilePath"; + private final static String WINDOWSFILE_OC = "windowsFile"; + private final static String UNIXFILE_OC = "unixFile"; + private void addFileEntry( DirContext root, File ldif ) throws NamingException + { + String rdnAttr = File.pathSeparatorChar == '\\' ? WINDOWSFILE_ATTR : UNIXFILE_ATTR; + String oc = File.pathSeparatorChar == '\\' ? WINDOWSFILE_OC : UNIXFILE_OC; + StringBuffer buf = new StringBuffer(); + buf.append( rdnAttr ); + buf.append( "=" ); + buf.append( ldif.getAbsolutePath() ); + buf.append( "," ); + buf.append( LDIF_FILES_DN ); + + Attributes entry = new BasicAttributes( rdnAttr, ldif.getAbsolutePath(), true ); + entry.put( "objectClass", "top" ); + entry.get( "objectClass" ).add( oc ); + root.createSubcontext( buf.toString(), entry ); + } + + + private Attributes getLdifFileEntry( DirContext root, File ldif ) + { + String rdnAttr = File.pathSeparatorChar == '\\' ? "windowsFile" : "unixFile"; + StringBuffer buf = new StringBuffer(); + buf.append( rdnAttr ); + buf.append( "=" ); + buf.append( ldif.getAbsolutePath() ); + buf.append( "," ); + buf.append( LDIF_FILES_DN ); + + try + { + return root.getAttributes( buf.toString(), new String[]{ "createTimestamp" }); + } + catch ( NamingException e ) + { + return null; + } + } + + + private void loadLdifs( DirectoryService service ) throws NamingException + { + ServerStartupConfiguration cfg = + ( ServerStartupConfiguration ) service.getConfiguration().getStartupConfiguration(); + + // log and bail if property not set + if ( cfg.getLdifDirectory() == null ) + { + log.info( "LDIF load directory not specified. No LDIF files will be loaded." ); + return; + } + + // log and bail if LDIF directory does not exists + if ( !cfg.getLdifDirectory().exists() ) + { + log.warn( "LDIF load directory '" + cfg.getLdifDirectory().getAbsolutePath() + + "' does not exist. No LDIF files will be loaded."); + return; + } + + // get an initial context to the rootDSE for creating the LDIF entries + Hashtable env = ( Hashtable ) service.getConfiguration().getEnvironment().clone(); + env.put( Context.PROVIDER_URL, "" ); + DirContext root = ( DirContext ) this.getInitialContext( env ); + + // make sure the configuration area for loaded ldif files is present + ensureLdifFileBase( root ); + + // if ldif directory is a file try to load it + if ( !cfg.getLdifDirectory().isDirectory() ) + { + log.info( "LDIF load directory '" + cfg.getLdifDirectory().getAbsolutePath() + + "' is a file. Will attempt to load as LDIF." ); + Attributes fileEntry = getLdifFileEntry( root, cfg.getLdifDirectory() ); + if ( fileEntry != null ) + { + String time = ( String ) fileEntry.get( "createTimestamp" ).get(); + log.info( "Load of LDIF file '" + cfg.getLdifDirectory().getAbsolutePath() + + "' skipped. It has already been loaded on " + time + "." ); + return; + } + LdifFileLoader loader = new LdifFileLoader( root, cfg.getLdifDirectory(), cfg.getLdifFilters() ); + loader.execute(); + + addFileEntry( root, cfg.getLdifDirectory() ); + return; + } + + // get all the ldif files within the directory (should be sorted alphabetically) + File[] ldifFiles = cfg.getLdifDirectory().listFiles( new FileFilter() + { + public boolean accept( File pathname ) + { + boolean isLdif = pathname.getName().toLowerCase().endsWith( ".ldif" ); + return pathname.isFile() && pathname.canRead() && isLdif; + } + }); + + // log and bail if we could not find any LDIF files + if ( ldifFiles == null || ldifFiles.length == 0 ) + { + log.warn( "LDIF load directory '" + cfg.getLdifDirectory().getAbsolutePath() + + "' does not contain any LDIF files. No LDIF files will be loaded."); + return; + } + + // load all the ldif files and load each one that is loaded + for ( int ii = 0; ii < ldifFiles.length; ii++ ) + { + Attributes fileEntry = getLdifFileEntry( root, ldifFiles[ii] ); + if ( fileEntry != null ) + { + String time = ( String ) fileEntry.get( "createTimestamp" ).get(); + log.info( "Load of LDIF file '" + ldifFiles[ii].getAbsolutePath() + + "' skipped. It has already been loaded on " + time + "." ); + continue; + } + LdifFileLoader loader = new LdifFileLoader( root, ldifFiles[ii], cfg.getLdifFilters() ); + int count = loader.execute(); + addFileEntry( root, cfg.getLdifDirectory() ); + log.info( "Loaded " + count + " entries from LDIF file '" + ldifFiles[ii].getAbsolutePath() + "'" ); + } + } + /** * Starts up the MINA registry so various protocol providers can be started.