You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2010/10/27 17:35:56 UTC

svn commit: r1028009 - in /directory/apacheds/branches/apacheds-config: server-config/src/main/java/org/apache/directory/server/config/ service/src/main/java/org/apache/directory/server/

Author: elecharny
Date: Wed Oct 27 15:35:55 2010
New Revision: 1028009

URL: http://svn.apache.org/viewvc?rev=1028009&view=rev
Log:
o Renamed the ConfigCreator to ConfigBuilder
o Added the missing create methods
o Used it in the ApacheDsService class

Added:
    directory/apacheds/branches/apacheds-config/server-config/src/main/java/org/apache/directory/server/config/ConfigBuilder.java
      - copied, changed from r1027980, directory/apacheds/branches/apacheds-config/server-config/src/main/java/org/apache/directory/server/config/ConfigCreator.java
Removed:
    directory/apacheds/branches/apacheds-config/server-config/src/main/java/org/apache/directory/server/config/ConfigCreator.java
Modified:
    directory/apacheds/branches/apacheds-config/service/src/main/java/org/apache/directory/server/ApacheDsService.java

Copied: directory/apacheds/branches/apacheds-config/server-config/src/main/java/org/apache/directory/server/config/ConfigBuilder.java (from r1027980, directory/apacheds/branches/apacheds-config/server-config/src/main/java/org/apache/directory/server/config/ConfigCreator.java)
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-config/server-config/src/main/java/org/apache/directory/server/config/ConfigBuilder.java?p2=directory/apacheds/branches/apacheds-config/server-config/src/main/java/org/apache/directory/server/config/ConfigBuilder.java&p1=directory/apacheds/branches/apacheds-config/server-config/src/main/java/org/apache/directory/server/config/ConfigCreator.java&r1=1027980&r2=1028009&rev=1028009&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-config/server-config/src/main/java/org/apache/directory/server/config/ConfigCreator.java (original)
+++ directory/apacheds/branches/apacheds-config/server-config/src/main/java/org/apache/directory/server/config/ConfigBuilder.java Wed Oct 27 15:35:55 2010
@@ -32,10 +32,13 @@ import java.util.Map;
 import java.util.Set;
 import java.util.TreeSet;
 
+import org.apache.directory.server.changepw.ChangePasswordServer;
 import org.apache.directory.server.config.beans.ChangeLogBean;
+import org.apache.directory.server.config.beans.ChangePasswordServerBean;
 import org.apache.directory.server.config.beans.DirectoryServiceBean;
 import org.apache.directory.server.config.beans.ExtendedOpHandlerBean;
 import org.apache.directory.server.config.beans.HttpServerBean;
+import org.apache.directory.server.config.beans.HttpWebAppBean;
 import org.apache.directory.server.config.beans.IndexBean;
 import org.apache.directory.server.config.beans.InterceptorBean;
 import org.apache.directory.server.config.beans.JdbmIndexBean;
@@ -65,6 +68,7 @@ import org.apache.directory.server.core.
 import org.apache.directory.server.core.partition.impl.btree.jdbm.JdbmIndex;
 import org.apache.directory.server.core.partition.impl.btree.jdbm.JdbmPartition;
 import org.apache.directory.server.integration.http.HttpServer;
+import org.apache.directory.server.integration.http.WebApp;
 import org.apache.directory.server.kerberos.kdc.KdcServer;
 import org.apache.directory.server.kerberos.shared.crypto.encryption.EncryptionType;
 import org.apache.directory.server.ldap.ExtendedOperationHandler;
@@ -94,10 +98,10 @@ import org.slf4j.LoggerFactory;
  *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
-public class ConfigCreator
+public class ConfigBuilder
 {
     /** The logger for this class */
-    private static final Logger LOG = LoggerFactory.getLogger( ConfigCreator.class );
+    private static final Logger LOG = LoggerFactory.getLogger( ConfigBuilder.class );
 
     /** LDIF file filter */
     private static FilenameFilter ldifFilter = new FilenameFilter()
@@ -121,7 +125,7 @@ public class ConfigCreator
      * @return a list of instantiated Interceptor objects
      * @throws Exception If the instanciation failed
      */
-    private static List<Interceptor> createInterceptors( List<InterceptorBean> interceptorBeans ) throws LdapException
+    public static List<Interceptor> createInterceptors( List<InterceptorBean> interceptorBeans ) throws LdapException
     {
         List<Interceptor> interceptors = new ArrayList<Interceptor>( interceptorBeans.size() );
         
@@ -410,6 +414,27 @@ public class ConfigCreator
         return transports;
     }
 
+    
+    /**
+     * Helper method to create an Array of EncryptionTypes from an array of Strings
+     */
+    private static EncryptionType[] createEncryptionTypes( List<String> encryptionTypes )
+    {
+        if ( ( encryptionTypes == null ) || ( encryptionTypes.size() == 0 ) )
+        {
+            return new EncryptionType[0];
+        }
+        
+        EncryptionType[] types = new EncryptionType[encryptionTypes.size()];
+        int pos = 0;
+        
+        for ( String encryptionType : encryptionTypes )
+        {
+            types[pos++] = EncryptionType.valueOf( encryptionType );
+        }
+        
+        return types;
+    }
 
     /**
      * Instantiates a NtpServer based on the configuration present in the partition 
@@ -505,7 +530,8 @@ public class ConfigCreator
         kdcServer.setEmptyAddressesAllowed( kdcServerBean.isKrbEmptyAddressesAllowed() );
         
         // EncryptionType
-        kdcServer.setEncryptionTypes( kdcServerBean.getKrbEncryptionTypes().toArray( new EncryptionType[]{} ) );
+        EncryptionType[] encryptionTypes = createEncryptionTypes( kdcServerBean.getKrbEncryptionTypes() );
+        kdcServer.setEncryptionTypes( encryptionTypes );
         
         // ForwardableAllowed
         kdcServer.setForwardableAllowed( kdcServerBean.isKrbForwardableAllowed() );
@@ -546,6 +572,39 @@ public class ConfigCreator
     
     
     /**
+     * Instantiates the HttpWebApps based on the configuration present in the partition 
+     *
+     * @param httpWebAppBeans The list of HttpWebAppBeans containing the HttpWebAppBeans configuration
+     * @return Instances of HttpWebAppBean
+     * @throws LdapException
+     */
+    public static Set<WebApp> createHttpWebApps( List<HttpWebAppBean> httpWebAppBeans, DirectoryService directoryService ) throws LdapException
+    {
+        if ( ( httpWebAppBeans == null ) || ( httpWebAppBeans.size() == 0 ) )
+        {
+            return null;
+        }
+        
+        Set<WebApp> webApps = new HashSet<WebApp>();
+
+        for ( HttpWebAppBean httpWebAppBean : httpWebAppBeans )
+        {
+            WebApp webApp = new WebApp();
+            
+            // HttpAppCtxPath
+            webApp.setContextPath( httpWebAppBean.getHttpAppCtxPath() );
+            
+            // HttpWarFile
+            webApp.setWarFile( httpWebAppBean.getHttpWarFile() );
+            
+            webApps.add( webApp );
+        }
+        
+        return webApps;
+    }
+    
+    
+    /**
      * Instantiates a HttpServer based on the configuration present in the partition 
      *
      * @param httpServerBean The HttpServerBean containing the HttpServer configuration
@@ -566,16 +625,87 @@ public class ConfigCreator
         httpServer.setConfFile( httpServerBean.getHttpConfFile() );
         
         // The transports
-        //httpServer.setPort( httpServerBean.get )
+        TransportBean[] transports = httpServerBean.getTransports();
+        
+        for ( TransportBean transportBean : transports )
+        {
+            if ( transportBean instanceof TcpTransportBean )
+            {
+                httpServer.setPort( transportBean.getSystemPort() );
+                break;
+            }
+        }
         
         // The webApps
-        httpServer.setWebApps( createWebApps( httpServerBean.getHttpWebApps()) );
+        httpServer.setWebApps( createHttpWebApps( httpServerBean.getHttpWebApps(), directoryService ) );
         
         return httpServer;
     }
     
     
     /**
+     * Instantiates a ChangePasswordServer based on the configuration present in the partition 
+     *
+     * @param ldapServerBean The ChangePasswordServerBean containing the ChangePasswordServer configuration
+     * @return Instance of ChangePasswordServer
+     * @throws LdapException
+     */
+    public static ChangePasswordServer createChangePasswordServer( ChangePasswordServerBean changePasswordServerBean, DirectoryService directoryService ) throws LdapException
+    {
+        // Fist, do nothing if the LdapServer is disabled
+        if ( !changePasswordServerBean.isEnabled() )
+        {
+            return null;
+        }
+
+        ChangePasswordServer changePasswordServer = new ChangePasswordServer();
+        changePasswordServer.setEnabled( true );
+        changePasswordServer.setDirectoryService( directoryService );
+
+        // AllowableClockSkew
+        changePasswordServer.setAllowableClockSkew( changePasswordServerBean.getKrbAllowableClockSkew() );
+
+        // TODO CatalogBased
+        //changePasswordServer.setCatalogBased( changePasswordServerBean.isCatalogBase() );
+
+        // EmptyAddressesAllowed
+        changePasswordServer.setEmptyAddressesAllowed( changePasswordServerBean.isKrbEmptyAddressesAllowed() );
+
+        // EncryptionTypes
+        EncryptionType[] encryptionTypes = createEncryptionTypes( changePasswordServerBean.getKrbEncryptionTypes() );
+        changePasswordServer.setEncryptionTypes( encryptionTypes );
+
+        // PolicyCategoryCount
+        changePasswordServer.setPolicyCategoryCount( changePasswordServerBean.getChgPwdPolicyCategoryCount() );
+
+        // PolicyPasswordLength
+        changePasswordServer.setPolicyPasswordLength( changePasswordServerBean.getChgPwdPolicyPasswordLength() );
+
+        // policyTokenSize
+        changePasswordServer.setPolicyTokenSize( changePasswordServerBean.getChgPwdPolicyTokenSize() );
+
+        // PrimaryRealm
+        changePasswordServer.setPrimaryRealm( changePasswordServerBean.getKrbPrimaryRealm() );
+
+        // SearchBaseDn
+        changePasswordServer.setSearchBaseDn( changePasswordServerBean.getSearchBaseDn().getName() );
+
+        // Id/Name
+        changePasswordServer.setServiceName( changePasswordServerBean.getServerId() );
+        changePasswordServer.setServiceId( changePasswordServerBean.getServerId() );
+
+        // ServicePrincipal
+        changePasswordServer.setServicePrincipal( changePasswordServerBean.getChgPwdServicePrincipal() );
+
+        // Transports
+        Transport[] transports = createTransports( changePasswordServerBean.getTransports() );
+        changePasswordServer.setTransports( transports );
+        
+        return changePasswordServer;
+    }
+    
+    
+    /**
      * Instantiates a LdapServer based on the configuration present in the partition 
      *
      * @param ldapServerBean The LdapServerBean containing the LdapServer configuration
@@ -708,7 +838,7 @@ public class ConfigCreator
      * @return An JdbmIndex instance
      * @throws Exception If the instance cannot be created
      */
-    private static JdbmIndex<?, Entry> createJdbmIndex( JdbmPartition partition, JdbmIndexBean<String, Entry> jdbmIndexBean )
+    public static JdbmIndex<?, Entry> createJdbmIndex( JdbmPartition partition, JdbmIndexBean<String, Entry> jdbmIndexBean )
     {
         JdbmIndex<String, Entry> index = new JdbmIndex<String, Entry>();
         

Modified: directory/apacheds/branches/apacheds-config/service/src/main/java/org/apache/directory/server/ApacheDsService.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-config/service/src/main/java/org/apache/directory/server/ApacheDsService.java?rev=1028009&r1=1028008&r2=1028009&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-config/service/src/main/java/org/apache/directory/server/ApacheDsService.java (original)
+++ directory/apacheds/branches/apacheds-config/service/src/main/java/org/apache/directory/server/ApacheDsService.java Wed Oct 27 15:35:55 2010
@@ -29,8 +29,16 @@ import java.util.Map;
 import java.util.UUID;
 
 import org.apache.directory.server.changepw.ChangePasswordServer;
+import org.apache.directory.server.config.ConfigBuilder;
 import org.apache.directory.server.config.ConfigPartitionReader;
 import org.apache.directory.server.config.LdifConfigExtractor;
+import org.apache.directory.server.config.beans.ChangePasswordServerBean;
+import org.apache.directory.server.config.beans.ConfigBean;
+import org.apache.directory.server.config.beans.DirectoryServiceBean;
+import org.apache.directory.server.config.beans.HttpServerBean;
+import org.apache.directory.server.config.beans.KdcServerBean;
+import org.apache.directory.server.config.beans.LdapServerBean;
+import org.apache.directory.server.config.beans.NtpServerBean;
 import org.apache.directory.server.core.CoreSession;
 import org.apache.directory.server.core.DirectoryService;
 import org.apache.directory.server.core.entry.ClonedServerEntry;
@@ -107,7 +115,7 @@ public class ApacheDsService
     private SingleFileLdifPartition configPartition;
 
     private ConfigPartitionReader cpReader;
-
+    
     // variables used during the initial startup to update the mandatory operational
     // attributes
     private UuidSyntaxChecker uuidChecker = new UuidSyntaxChecker();
@@ -133,6 +141,7 @@ public class ApacheDsService
     public void start( InstanceLayout instanceLayout ) throws Exception
     {
         File partitionsDir = instanceLayout.getPartitionsDirectory();
+        
         if ( !partitionsDir.exists() )
         {
             LOG.info( "partition directory doesn't exist, creating {}", partitionsDir.getAbsolutePath() );
@@ -140,31 +149,40 @@ public class ApacheDsService
         }
 
         LOG.info( "using partition dir {}", partitionsDir.getAbsolutePath() );
+        
         initSchemaLdifPartition( instanceLayout );
         initConfigPartition( instanceLayout );
 
+        // Read the configuration
         cpReader = new ConfigPartitionReader( configPartition, partitionsDir );
+        
+        ConfigBean configBean = cpReader.readConfig( "ou=config" );
+        
+        DirectoryServiceBean directoryServiceBean = configBean.getDirectoryServiceBean( "default" );
+        
+        // Initialize the DirectoryService now
+        DirectoryService directoryService = initDirectoryService( instanceLayout, directoryServiceBean );
 
         // start the LDAP server
-        startLdap( instanceLayout );
+        startLdap( directoryServiceBean.getLdapServerBean(), directoryService );
 
         // start the NTP server
-        startNtp();
+        startNtp( directoryServiceBean.getNtpServerBean(), directoryService );
 
         // Initialize the DNS server (Not ready yet)
-        // initDns( layout );
+        // initDns( configBean );
 
         // Initialize the DHCP server (Not ready yet)
-        // initDhcp( layout );
+        // initDhcp( configBean );
 
         // start the ChangePwd server (Not ready yet)
-        startChangePwd();
+        startChangePwd( directoryServiceBean.getChangePasswordServerBean(), directoryService );
 
         // start the Kerberos server
-        startKerberos();
+        startKerberos( directoryServiceBean.getKdcServerBean(), directoryService );
 
         // start the jetty http server
-        startHttpServer();
+        startHttpServer( directoryServiceBean.getHttpServerBean(), directoryService );
     }
 
 
@@ -228,7 +246,7 @@ public class ApacheDsService
         }
         else
         {
-            LdifConfigExtractor.extractSingleFileConfig( instanceLayout.getConfDirectory(), true );
+            LdifConfigExtractor.extractSingleFileConfig( instanceLayout.getConfDirectory(), LdifConfigExtractor.LDIF_CONFIG_FILE, true );
             isConfigPartitionFirstExtraction = true;
         }
 
@@ -240,19 +258,15 @@ public class ApacheDsService
 
         configPartition.initialize();
     }
-
-
-    /**
-     * start the LDAP server
-     */
-    private void startLdap( InstanceLayout instanceLayout ) throws Exception
+    
+    
+    private DirectoryService initDirectoryService( InstanceLayout instanceLayout, DirectoryServiceBean directoryServiceBean ) throws Exception
     {
-        LOG.info( "Starting the LDAP server" );
-
-        printBanner( BANNER_LDAP );
+        LOG.info( "Initializing the DirectoryService..." );
+        
         long startTime = System.currentTimeMillis();
 
-        DirectoryService directoryService = cpReader.createDirectoryService();
+        DirectoryService directoryService = ConfigBuilder.createDirectoryService( directoryServiceBean, "default" );
         directoryService.setSchemaManager( schemaManager );
 
         SchemaPartition schemaPartition = directoryService.getSchemaService().getSchemaPartition();
@@ -263,9 +277,6 @@ public class ApacheDsService
 
         directoryService.setWorkingDirectory( instanceLayout.getInstanceDirectory() );
 
-        ldapServer = cpReader.createLdapServer();
-        ldapServer.setDirectoryService( directoryService );
-
         directoryService.startup();
 
         AttributeType ocAt = schemaManager.lookupAttributeTypeRegistry( SchemaConstants.OBJECT_CLASS_AT );
@@ -308,6 +319,26 @@ public class ApacheDsService
             LOG.info( "schema partition data was successfully updated" );
         }
 
+        LOG.info( "DirectoryService initialized in {} milliseconds", ( System.currentTimeMillis() - startTime ) );
+        
+        return directoryService;
+    }
+
+
+    /**
+     * start the LDAP server
+     */
+    private void startLdap( LdapServerBean ldapServerBean, DirectoryService directoryService ) throws Exception
+    {
+        LOG.info( "Starting the LDAP server" );
+        long startTime = System.currentTimeMillis();
+
+        printBanner( BANNER_LDAP );
+
+        ldapServer = ConfigBuilder.createLdapServer( ldapServerBean, directoryService );
+        
+        ldapServer.setDirectoryService( directoryService );
+
         // And start the server now
         try
         {
@@ -318,34 +349,29 @@ public class ApacheDsService
             LOG.error( "Cannot start the server : " + e.getMessage() );
         }
 
-        if ( LOG.isInfoEnabled() )
-        {
-            LOG.info( "LDAP server: started in {} milliseconds", ( System.currentTimeMillis() - startTime ) + "" );
-        }
+        LOG.info( "LDAP server: started in {} milliseconds", ( System.currentTimeMillis() - startTime ) + "" );
     }
 
 
     /**
      * start the NTP server
      */
-    private void startNtp() throws Exception
+    private void startNtp( NtpServerBean ntpServerBean, DirectoryService directoryService ) throws Exception
     {
-        ntpServer = cpReader.createNtpServer();
+        LOG.info( "Starting the NTP server" );
+        long startTime = System.currentTimeMillis();
+
+        ntpServer = ConfigBuilder.createNtpServer( ntpServerBean, directoryService);
+        
         if ( ntpServer == null )
         {
-            LOG
-                .info( "Cannot find any reference to the NTP Server in the configuration : the server won't be started" );
+            LOG.info( "Cannot find any reference to the NTP Server in the configuration : the server won't be started" );
             return;
         }
 
-        System.out.println( "Starting the NTP server" );
-        LOG.info( "Starting the NTP server" );
-
         printBanner( BANNER_NTP );
-        long startTime = System.currentTimeMillis();
 
         ntpServer.start();
-        System.out.println( "NTP Server started" );
 
         if ( LOG.isInfoEnabled() )
         {
@@ -392,29 +418,26 @@ public class ApacheDsService
     /**
      * start the KERBEROS server
      */
-    private void startKerberos() throws Exception
+    private void startKerberos( KdcServerBean kdcServerBean, DirectoryService directoryService ) throws Exception
     {
-        kdcServer = cpReader.createKdcServer();
+        LOG.info( "Starting the Kerberos server" );
+        long startTime = System.currentTimeMillis();
+
+        kdcServer = ConfigBuilder.createKdcServer( kdcServerBean, directoryService );
+        
         if ( kdcServer == null )
         {
-            LOG
-                .info( "Cannot find any reference to the Kerberos Server in the configuration : the server won't be started" );
+            LOG.info( "Cannot find any reference to the Kerberos Server in the configuration : the server won't be started" );
             return;
         }
 
         getDirectoryService().startup();
         kdcServer.setDirectoryService( getDirectoryService() );
 
-        System.out.println( "Starting the Kerberos server" );
-        LOG.info( "Starting the Kerberos server" );
-
         printBanner( BANNER_KERBEROS );
-        long startTime = System.currentTimeMillis();
 
         kdcServer.start();
 
-        System.out.println( "Kerberos server started" );
-
         if ( LOG.isInfoEnabled() )
         {
             LOG.info( "Kerberos server: started in {} milliseconds", ( System.currentTimeMillis() - startTime ) + "" );
@@ -425,29 +448,28 @@ public class ApacheDsService
     /**
      * start the Change Password server
      */
-    private void startChangePwd() throws Exception
+    private void startChangePwd( ChangePasswordServerBean changePwdServerBean, DirectoryService directoryService ) throws Exception
     {
-
-        changePwdServer = cpReader.createChangePwdServer();
+        changePwdServer = ConfigBuilder.createChangePasswordServer( changePwdServerBean, directoryService );
+        
         if ( changePwdServer == null )
         {
-            LOG
-                .info( "Cannot find any reference to the Change Password Server in the configuration : the server won't be started" );
+            LOG.info( "Cannot find any reference to the Change Password Server in the configuration : the server won't be started" );
             return;
         }
 
+        LOG.info( "Starting the Change Password server" );
+        long startTime = System.currentTimeMillis();
+
         getDirectoryService().startup();
         changePwdServer.setDirectoryService( getDirectoryService() );
 
-        System.out.println( "Starting the Change Password server" );
         LOG.info( "Starting the Change Password server" );
 
         printBanner( BANNER_CHANGE_PWD );
-        long startTime = System.currentTimeMillis();
 
         changePwdServer.start();
 
-        System.out.println( "Change Password server started" );
         if ( LOG.isInfoEnabled() )
         {
             LOG.info( "Change Password server: started in {} milliseconds", ( System.currentTimeMillis() - startTime )
@@ -459,19 +481,25 @@ public class ApacheDsService
     /**
      * start the embedded HTTP server
      */
-    private void startHttpServer() throws Exception
+    private void startHttpServer( HttpServerBean httpServerBean, DirectoryService directoryService ) throws Exception
     {
-        httpServer = cpReader.createHttpServer();
+        httpServer = ConfigBuilder.createHttpServer( httpServerBean, directoryService);
+        
         if ( httpServer == null )
         {
-            LOG
-                .info( "Cannot find any reference to the HTTP Server in the configuration : the server won't be started" );
+            LOG.info( "Cannot find any reference to the HTTP Server in the configuration : the server won't be started" );
             return;
         }
 
-        if ( httpServer != null )
+        LOG.info( "Starting the Http server" );
+        long startTime = System.currentTimeMillis();
+
+        httpServer.start( getDirectoryService() );
+
+        if ( LOG.isInfoEnabled() )
         {
-            httpServer.start( getDirectoryService() );
+            LOG.info( "Http server: started in {} milliseconds", ( System.currentTimeMillis() - startTime )
+                + "" );
         }
     }