You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by ak...@apache.org on 2005/10/29 02:58:04 UTC
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/
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 @@
<prop key="java.naming.security.principal">uid=admin,ou=system</prop>
<prop key="java.naming.security.credentials">secret</prop>
<prop key="java.naming.ldap.attributes.binary">photo personalSignature audio jpegPhoto javaSerializedData userPassword userCertificate cACertificate authorityRevocationList certificateRevocationList crossCertificatePair x500UniqueIdentifier krb5Key</prop>
+ <prop key="kdc.entryBaseDn">ou=Users,dc=apache,dc=org</prop>
</props>
</property>
</bean>
<bean id="configuration" class="org.apache.ldap.server.configuration.MutableServerStartupConfiguration">
<property name="workingDirectory"><value>apache.org</value></property>
+
+ <!-- Uncomment below to have the server load entries on startup! -->
+ <!-- ldifDirectory property can point to a relative file, directory or -->
+ <!-- can point to an absolute path to either using the URL path -->
+ <!-- notation: i.e. file:///Users/jack/apacheds/ldifs -->
+
+ <!-- Entries will optionally be filtered using LdifLoadFilters in the -->
+ <!-- order specified. The included Krb5KdcEntryFilter will filter -->
+ <!-- kerberos principals creating keys for them using their -->
+ <!-- userPassword attribute if present. -->
+
+ <!--
+ <property name="ldifDirectory">
+ <value>blah.ldif</value>
+ </property>
+ <property name="ldifFilters">
+ <list>
+ <bean class="org.apache.protocol.common.store.Krb5KdcEntryFilter"/>
+ </list>
+ </property>
+ -->
+
<property name="allowAnonymousAccess"><value>false</value></property>
<property name="accessControlEnabled"><value>false</value></property>
<property name="enableNtp"><value>false</value></property>
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.