You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by ka...@apache.org on 2010/01/13 20:38:30 UTC

svn commit: r898917 - in /directory/apacheds/branches/apacheds-cidit/default-config/src/main/java/org/apache/directory/server/config: CiDITDirectoryServiceFactory.java ConfigPartitionReader.java

Author: kayyagari
Date: Wed Jan 13 19:38:30 2010
New Revision: 898917

URL: http://svn.apache.org/viewvc?rev=898917&view=rev
Log:
o added support for instantiating transports and ldapserver
o added code to test the startup of LdapServer instance returned by the ConfigPartitionReader

Modified:
    directory/apacheds/branches/apacheds-cidit/default-config/src/main/java/org/apache/directory/server/config/CiDITDirectoryServiceFactory.java
    directory/apacheds/branches/apacheds-cidit/default-config/src/main/java/org/apache/directory/server/config/ConfigPartitionReader.java

Modified: directory/apacheds/branches/apacheds-cidit/default-config/src/main/java/org/apache/directory/server/config/CiDITDirectoryServiceFactory.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-cidit/default-config/src/main/java/org/apache/directory/server/config/CiDITDirectoryServiceFactory.java?rev=898917&r1=898916&r2=898917&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-cidit/default-config/src/main/java/org/apache/directory/server/config/CiDITDirectoryServiceFactory.java (original)
+++ directory/apacheds/branches/apacheds-cidit/default-config/src/main/java/org/apache/directory/server/config/CiDITDirectoryServiceFactory.java Wed Jan 13 19:38:30 2010
@@ -23,19 +23,12 @@
 import java.io.File;
 import java.util.List;
 
-import javax.naming.directory.SearchControls;
-
 import org.apache.commons.io.FileUtils;
 import org.apache.directory.server.core.DefaultDirectoryService;
 import org.apache.directory.server.core.DirectoryService;
-import org.apache.directory.server.core.entry.ClonedServerEntry;
 import org.apache.directory.server.core.partition.ldif.LdifPartition;
 import org.apache.directory.server.core.schema.SchemaPartition;
-import org.apache.directory.server.xdbm.ForwardIndexEntry;
-import org.apache.directory.server.xdbm.IndexCursor;
-import org.apache.directory.server.xdbm.search.SearchEngine;
-import org.apache.directory.shared.ldap.filter.PresenceNode;
-import org.apache.directory.shared.ldap.message.AliasDerefMode;
+import org.apache.directory.server.ldap.LdapServer;
 import org.apache.directory.shared.ldap.schema.SchemaManager;
 import org.apache.directory.shared.ldap.schema.ldif.extractor.SchemaLdifExtractor;
 import org.apache.directory.shared.ldap.schema.ldif.extractor.impl.DefaultSchemaLdifExtractor;
@@ -129,7 +122,7 @@
             throw new Exception( "Schema load failed : " + ExceptionUtils.printErrors( errors ) );
         }
         
-        LdifConfigExtractor.extract( workDir, false );
+        LdifConfigExtractor.extract( workDir, true );
         
         LdifPartition configPartition = new LdifPartition();
         configPartition.setId( "config" );
@@ -155,13 +148,22 @@
         dirService.setSchemaManager( schemaManager );
         dirService.startup();
         
-        System.out.println( dirService.isStarted() );
+        System.out.println( "started dirservice " + dirService.isStarted() );
+        
+        LdapServer server = cpReader.getLdapServer();
+        server.setDirectoryService( dirService );
+        
+        server.start();
+        
+        System.out.println( "started LDAP server " + server.isStarted() );
         
-        dirService.shutdown();
-        System.out.println( dirService.isStarted() );
+        // wait for 10 min to test conecting from studio
+        Thread.sleep( 10 * 60 * 1000 );
+        
+        server.stop();
     }
 
-    
+
     public static void main( String[] args ) throws Exception
     {
         CiDITDirectoryServiceFactory ciditDSFactory = new CiDITDirectoryServiceFactory();

Modified: directory/apacheds/branches/apacheds-cidit/default-config/src/main/java/org/apache/directory/server/config/ConfigPartitionReader.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-cidit/default-config/src/main/java/org/apache/directory/server/config/ConfigPartitionReader.java?rev=898917&r1=898916&r2=898917&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-cidit/default-config/src/main/java/org/apache/directory/server/config/ConfigPartitionReader.java (original)
+++ directory/apacheds/branches/apacheds-cidit/default-config/src/main/java/org/apache/directory/server/config/ConfigPartitionReader.java Wed Jan 13 19:38:30 2010
@@ -41,6 +41,10 @@
 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.core.partition.ldif.LdifPartition;
+import org.apache.directory.server.ldap.LdapServer;
+import org.apache.directory.server.protocol.shared.transport.TcpTransport;
+import org.apache.directory.server.protocol.shared.transport.Transport;
+import org.apache.directory.server.protocol.shared.transport.UdpTransport;
 import org.apache.directory.server.xdbm.ForwardIndexEntry;
 import org.apache.directory.server.xdbm.Index;
 import org.apache.directory.server.xdbm.IndexCursor;
@@ -48,6 +52,8 @@
 import org.apache.directory.shared.ldap.NotImplementedException;
 import org.apache.directory.shared.ldap.entry.Entry;
 import org.apache.directory.shared.ldap.entry.EntryAttribute;
+import org.apache.directory.shared.ldap.entry.client.ClientStringValue;
+import org.apache.directory.shared.ldap.filter.EqualityNode;
 import org.apache.directory.shared.ldap.filter.PresenceNode;
 import org.apache.directory.shared.ldap.message.AliasDerefMode;
 import org.apache.directory.shared.ldap.name.LdapDN;
@@ -103,7 +109,49 @@
         workDir = configPartition.getPartitionDir().getParentFile();        
     }
 
+    
+    /**
+     * reads the LDAP server configuration and instantiates without setting a DirectoryService 
+     *
+     * @return the LdapServer instance without a DirectoryService
+     * @throws Exception
+     */
+    public LdapServer getLdapServer() throws Exception
+    {
+        EqualityNode filter = new EqualityNode( "objectClass", new ClientStringValue( "ads-ldapServer" ) );
+        SearchControls controls = new SearchControls();
+        controls.setSearchScope( SearchControls.SUBTREE_SCOPE );
+
+        IndexCursor cursor = se.cursor( configPartition.getSuffixDn(), AliasDerefMode.NEVER_DEREF_ALIASES, filter,
+            controls );
+
+        if ( !cursor.next() )
+        {
+            throw new Exception( "No LDAP server was configured under the DN " + configPartition.getSuffixDn() );
+        }
+
+        ForwardIndexEntry<Long, Long> forwardEntry = ( ForwardIndexEntry<Long, Long> ) cursor.get();
+        cursor.close();
 
+        ClonedServerEntry ldapServerEntry = configPartition.lookup( forwardEntry.getId() );
+        LOG.debug( "LDAP Server Entry {}", ldapServerEntry );
+        if( !isEnabled( ldapServerEntry ) )
+        {
+            return null;
+        }
+        
+        LdapServer server = new LdapServer();
+        server.setServiceId( getString( "ads-serverId", ldapServerEntry ) );
+        
+        LdapDN transportsDN = new LdapDN( getString( "ads-transports", ldapServerEntry ) );
+        transportsDN.normalize( schemaManager.getNormalizerMapping() );
+        Transport[] transports = getTransports( transportsDN );
+        server.setTransports( transports );
+
+        return server;
+    }
+
+    
     /**
      * 
      * instantiates a DirectoryService based on the configuration present in the partition 
@@ -214,6 +262,7 @@
         if ( testEntryAttr != null )
         {
             //process the test entries, should this be a FS location?
+            //dirService.setTestEntries( testEntries );
         }
 
         if ( !isEnabled( dsEntry ) )
@@ -398,6 +447,79 @@
     }
     
     
+    private Transport[] getTransports( LdapDN transportsDN ) throws Exception
+    {
+        PresenceNode filter = new PresenceNode( "ads-transportId" );
+        SearchControls controls = new SearchControls();
+        controls.setSearchScope( SearchControls.ONELEVEL_SCOPE );
+        IndexCursor cursor = se.cursor( transportsDN, AliasDerefMode.NEVER_DEREF_ALIASES, filter, controls );
+        
+        List<Transport> transports = new ArrayList<Transport>();
+        
+        while( cursor.next() )
+        {
+            ForwardIndexEntry<Long, Long> forwardEntry = ( ForwardIndexEntry<Long, Long> ) cursor.get();
+            ServerEntry transportEntry = configPartition.lookup( forwardEntry.getId() );
+            if( !isEnabled( transportEntry ) )
+            {
+                continue;
+            }
+            
+            transports.add( getTransport( transportEntry ) );
+        }
+        
+        return transports.toArray( new Transport[]{} );
+    }
+    
+    
+    
+    private Transport getTransport( Entry transportEntry ) throws Exception
+    {
+        Transport transport = null;
+     
+        EntryAttribute ocAttr = transportEntry.get( "objectClass" );
+        if( ocAttr.contains( "ads-tcpTransport" ) )
+        {
+            transport = new TcpTransport();
+        }
+        else if( ocAttr.contains( "ads-udpTransport" ) )
+        {
+            transport = new UdpTransport();
+        }
+        
+        transport.setPort( getInt( "ads-systemPort", transportEntry ) );
+        EntryAttribute addressAttr = transportEntry.get( "ads-transportAddress" );
+        if( addressAttr != null )
+        {
+            transport.setAddress( addressAttr.getString() );
+        }
+        else
+        {
+            transport.setAddress( "0.0.0.0" );
+        }
+        
+        EntryAttribute backlogAttr = transportEntry.get( "ads-transportBacklog" );
+        if( backlogAttr != null )
+        {
+            transport.setBackLog( Integer.parseInt( backlogAttr.getString() ) );
+        }
+        
+        EntryAttribute sslAttr = transportEntry.get( "ads-transportEnableSSL" );
+        if( sslAttr != null )
+        {
+            transport.setEnableSSL( Boolean.parseBoolean( sslAttr.getString() ) );
+        }
+        
+        EntryAttribute nbThreadsAttr = transportEntry.get( "ads-transportNbThreads" );
+        if( nbThreadsAttr != null )
+        {
+            transport.setNbThreads( Integer.parseInt( nbThreadsAttr.getString() ) );
+        }
+
+        return transport;
+    }
+    
+    
     /**
      * internal class used for holding the Interceptor classname and order configuration
      */