You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by jc...@apache.org on 2006/12/13 20:41:45 UTC
svn commit: r486813 - in
/directory/sandbox/jconlon/osgi-apacheds/protocol-ldap-osgi: ./ java/
java/org/ java/org/apache/ java/org/apache/directory/
java/org/apache/directory/osgi/ java/org/apache/directory/osgi/backend/
resources/ src/ src/main/ src/m...
Author: jconlon
Date: Wed Dec 13 11:41:43 2006
New Revision: 486813
URL: http://svn.apache.org/viewvc?view=rev&rev=486813
Log:
added a ldap protocol provider subproject
Added:
directory/sandbox/jconlon/osgi-apacheds/protocol-ldap-osgi/
directory/sandbox/jconlon/osgi-apacheds/protocol-ldap-osgi/java/
directory/sandbox/jconlon/osgi-apacheds/protocol-ldap-osgi/java/org/
directory/sandbox/jconlon/osgi-apacheds/protocol-ldap-osgi/java/org/apache/
directory/sandbox/jconlon/osgi-apacheds/protocol-ldap-osgi/java/org/apache/directory/
directory/sandbox/jconlon/osgi-apacheds/protocol-ldap-osgi/java/org/apache/directory/osgi/
directory/sandbox/jconlon/osgi-apacheds/protocol-ldap-osgi/java/org/apache/directory/osgi/backend/
directory/sandbox/jconlon/osgi-apacheds/protocol-ldap-osgi/java/org/apache/directory/osgi/backend/IntegrationTest.java
directory/sandbox/jconlon/osgi-apacheds/protocol-ldap-osgi/pom.xml
directory/sandbox/jconlon/osgi-apacheds/protocol-ldap-osgi/resources/
directory/sandbox/jconlon/osgi-apacheds/protocol-ldap-osgi/resources/log4j.properties
directory/sandbox/jconlon/osgi-apacheds/protocol-ldap-osgi/resources/nonspecific.ldif
directory/sandbox/jconlon/osgi-apacheds/protocol-ldap-osgi/server.properties
directory/sandbox/jconlon/osgi-apacheds/protocol-ldap-osgi/src/
directory/sandbox/jconlon/osgi-apacheds/protocol-ldap-osgi/src/main/
directory/sandbox/jconlon/osgi-apacheds/protocol-ldap-osgi/src/main/java/
directory/sandbox/jconlon/osgi-apacheds/protocol-ldap-osgi/src/main/java/org/
directory/sandbox/jconlon/osgi-apacheds/protocol-ldap-osgi/src/main/java/org/apache/
directory/sandbox/jconlon/osgi-apacheds/protocol-ldap-osgi/src/main/java/org/apache/directory/
directory/sandbox/jconlon/osgi-apacheds/protocol-ldap-osgi/src/main/java/org/apache/directory/server/
directory/sandbox/jconlon/osgi-apacheds/protocol-ldap-osgi/src/main/java/org/apache/directory/server/ldap/
directory/sandbox/jconlon/osgi-apacheds/protocol-ldap-osgi/src/main/java/org/apache/directory/server/ldap/osgi/
directory/sandbox/jconlon/osgi-apacheds/protocol-ldap-osgi/src/main/java/org/apache/directory/server/ldap/osgi/DefaultServerConfigurator.java
directory/sandbox/jconlon/osgi-apacheds/protocol-ldap-osgi/src/main/java/org/apache/directory/server/ldap/osgi/LdapConfig.java
directory/sandbox/jconlon/osgi-apacheds/protocol-ldap-osgi/src/main/java/org/apache/directory/server/ldap/osgi/LdapServer.java
directory/sandbox/jconlon/osgi-apacheds/protocol-ldap-osgi/src/main/java/org/apache/directory/server/ldap/osgi/LdapServerFactory.java
directory/sandbox/jconlon/osgi-apacheds/protocol-ldap-osgi/src/main/resources/
directory/sandbox/jconlon/osgi-apacheds/protocol-ldap-osgi/src/main/resources/META-INF/
directory/sandbox/jconlon/osgi-apacheds/protocol-ldap-osgi/src/main/resources/META-INF/spring/
directory/sandbox/jconlon/osgi-apacheds/protocol-ldap-osgi/src/main/resources/META-INF/spring/server-osgi.xml
directory/sandbox/jconlon/osgi-apacheds/protocol-ldap-osgi/src/main/resources/META-INF/spring/server.xml
directory/sandbox/jconlon/osgi-apacheds/protocol-ldap-osgi/src/test/
directory/sandbox/jconlon/osgi-apacheds/protocol-ldap-osgi/src/test/java/
directory/sandbox/jconlon/osgi-apacheds/protocol-ldap-osgi/src/test/java/org/
directory/sandbox/jconlon/osgi-apacheds/protocol-ldap-osgi/src/test/java/org/apache/
directory/sandbox/jconlon/osgi-apacheds/protocol-ldap-osgi/src/test/java/org/apache/directory/
directory/sandbox/jconlon/osgi-apacheds/protocol-ldap-osgi/src/test/java/org/apache/directory/server/
directory/sandbox/jconlon/osgi-apacheds/protocol-ldap-osgi/src/test/java/org/apache/directory/server/ldap/
directory/sandbox/jconlon/osgi-apacheds/protocol-ldap-osgi/src/test/java/org/apache/directory/server/ldap/osgi/
directory/sandbox/jconlon/osgi-apacheds/protocol-ldap-osgi/src/test/java/org/apache/directory/server/ldap/osgi/IntegrationTest.java
directory/sandbox/jconlon/osgi-apacheds/protocol-ldap-osgi/src/test/java/org/apache/directory/server/ldap/osgi/MockInitialContextFactory.java
directory/sandbox/jconlon/osgi-apacheds/protocol-ldap-osgi/src/test/resources/
directory/sandbox/jconlon/osgi-apacheds/protocol-ldap-osgi/src/test/resources/log4j.properties
directory/sandbox/jconlon/osgi-apacheds/protocol-ldap-osgi/src/test/resources/mockInitialContextFactory.xml
Added: directory/sandbox/jconlon/osgi-apacheds/protocol-ldap-osgi/java/org/apache/directory/osgi/backend/IntegrationTest.java
URL: http://svn.apache.org/viewvc/directory/sandbox/jconlon/osgi-apacheds/protocol-ldap-osgi/java/org/apache/directory/osgi/backend/IntegrationTest.java?view=auto&rev=486813
==============================================================================
--- directory/sandbox/jconlon/osgi-apacheds/protocol-ldap-osgi/java/org/apache/directory/osgi/backend/IntegrationTest.java (added)
+++ directory/sandbox/jconlon/osgi-apacheds/protocol-ldap-osgi/java/org/apache/directory/osgi/backend/IntegrationTest.java Wed Dec 13 11:41:43 2006
@@ -0,0 +1,185 @@
+/*
+ * Copyright 2006 the original author or authors.
+ *
+ * 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.directory.osgi.backend;
+
+
+import java.io.File;
+
+import javax.naming.Context;
+import javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
+import javax.naming.directory.DirContext;
+import javax.naming.directory.SearchControls;
+import javax.naming.directory.SearchResult;
+import javax.naming.spi.InitialContextFactory;
+
+import org.apache.directory.server.core.configuration.MutableStartupConfiguration;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.config.PropertiesFactoryBean;
+import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
+
+/**
+ * Integration test the service locally (outside of OSGi).
+ * Use AbstractOsgiTests and a separate integration test project
+ * for testing inside of OSGi.
+ *
+ * @author Adrian Colyer
+ */
+public class IntegrationTest extends AbstractDependencyInjectionSpringContextTests {
+ /** the log for this class */
+ private static final Logger log = LoggerFactory
+ .getLogger(IntegrationTest.class);
+ private PropertiesFactoryBean propertyFactoryBean;
+ private MutableStartupConfiguration configuration;
+ private InitialContextFactoryImpl initialContextFactoryImpl;
+
+
+
+
+
+ public static boolean deleteDir(File dir) {
+ if (dir.isDirectory()) {
+ String[] children = dir.list();
+ for (int i=0; i<children.length; i++) {
+ boolean success = deleteDir(new File(dir, children[i]));
+ if (!success) {
+ return false;
+ }
+ }
+ }
+
+ // The directory is now empty so delete it
+ return dir.delete();
+ }
+
+ protected String[] getConfigLocations() {
+ return new String[] {"META-INF/spring/server.xml"};
+ }
+
+ public void setEnvironment(PropertiesFactoryBean service) {
+ this.propertyFactoryBean = service;
+ }
+
+ public void setConfiguration(MutableStartupConfiguration mutableServerStartupConfiguration) {
+ this.configuration = mutableServerStartupConfiguration;
+ }
+
+
+ public void setInitialContextFactoryImpl(
+ InitialContextFactoryImpl initialContextFactoryImpl) {
+ this.initialContextFactoryImpl=initialContextFactoryImpl;
+ }
+
+ private void deleteWorkingDirectory() {
+ File workDir = configuration.getWorkingDirectory();
+ if(workDir.exists() ){
+ boolean didDelete = deleteDir(workDir);
+ if(didDelete){
+ log.debug("Deleted "+workDir.getAbsolutePath());
+ }else{
+ log.error("Did non Delete "+workDir.getAbsolutePath());
+ }
+ }else{
+ log.debug("Couldn not find "+workDir.getAbsolutePath());
+ }
+ }
+
+ /* ==================================== Tests ===================================================*/
+ public void testEnvironment() {
+ assertNotNull(propertyFactoryBean);
+ assertTrue(
+ propertyFactoryBean.isSingleton());
+ }
+
+ public void testConfiguration() {
+ assertNotNull(configuration);
+ }
+
+ public void testInitialContextFactoryImpl() {
+// deleteWorkingDirectory();
+ assertNotNull(initialContextFactoryImpl);
+ assertTrue(initialContextFactoryImpl instanceof InitialContextFactory);
+ try {
+ initialContextFactoryImpl.getInitialContext(null);
+ fail("Did not throw a IllegalStateException because the server was not started.");
+ } catch (NamingException e) {
+ fail(e.getExplanation());
+ } catch (IllegalStateException e){
+ //expected
+ }
+ initialContextFactoryImpl.start();
+ InitialContextFactory factory = initialContextFactoryImpl;
+
+ Context context = null;
+ try {
+ context = factory.getInitialContext(null);
+ } catch (NamingException e1) {
+ fail(e1.toString());
+ }
+ assertNotNull(context);
+
+ assertTrue(context instanceof DirContext);
+
+ DirContext dirContext = (DirContext) context;
+
+ SearchControls sc = new SearchControls();
+ sc.setSearchScope(SearchControls.ONELEVEL_SCOPE);
+ NamingEnumeration ne = null;
+ try {
+ ne = dirContext
+ .search("ou=system", "(objectclass=*)", sc);
+ } catch (NamingException e) {
+ e.printStackTrace();
+ fail(e.toString());
+ }
+ assertNotNull(ne);
+ int count = 0;
+ try {
+
+ while (ne.hasMore()) {
+ count++;
+ SearchResult sr = (SearchResult) ne.next();
+ log.debug('\n' + sr.toString());
+// assertEquals("uid=admin,ou=system", sr.getName());
+ }
+ } catch (NamingException e) {
+ e.printStackTrace();
+ fail(e.toString());
+ } finally {
+ try {
+ ne.close();
+ } catch (NamingException e) {
+ fail(e.toString());
+ }
+ }
+ assertEquals(5
+ ,count);
+ try {
+ initialContextFactoryImpl.stop();
+ } catch (Exception e) {
+ fail(e.toString());
+ }
+
+ }
+
+
+
+
+
+
+
+}
Added: directory/sandbox/jconlon/osgi-apacheds/protocol-ldap-osgi/pom.xml
URL: http://svn.apache.org/viewvc/directory/sandbox/jconlon/osgi-apacheds/protocol-ldap-osgi/pom.xml?view=auto&rev=486813
==============================================================================
--- directory/sandbox/jconlon/osgi-apacheds/protocol-ldap-osgi/pom.xml (added)
+++ directory/sandbox/jconlon/osgi-apacheds/protocol-ldap-osgi/pom.xml Wed Dec 13 11:41:43 2006
@@ -0,0 +1,160 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.directory.server</groupId>
+ <artifactId>build</artifactId>
+ <version>1.5.0-SNAPSHOT</version>
+ </parent>
+ <artifactId>apacheds-protocol-ldap-osgi</artifactId>
+ <name>${pom.artifactId} Spring enabled bundle</name>
+ <packaging>bundle</packaging>
+ <description>
+ The ApacheDS LDAP Network Service packaged as a Spring enabled OSGi bundle.
+ </description>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Bundle-SymbolicName>
+ ${pom.artifactId}
+ </Bundle-SymbolicName>
+ <Export-Package>
+ !META-INF.*,org.apache.directory.server.ldap.osgi,
+ *
+ </Export-Package>
+ <DynamicImport-Package>
+ antlr, org.apache.directory.server.core.jndi
+ </DynamicImport-Package>
+ <Import-Package>
+ !javax.swing,!javax.swing.*,*
+ </Import-Package>
+
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.directory.server</groupId>
+ <artifactId>apacheds-protocol-ldap</artifactId>
+ <version>${pom.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.directory.server</groupId>
+ <artifactId>apacheds-core</artifactId>
+ <version>${pom.version}</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.directory.server</groupId>
+ <artifactId>apacheds-protocol-shared</artifactId>
+ <version>${pom.version}</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.mina</groupId>
+ <artifactId>mina-core</artifactId>
+ <version>1.1.0-SNAPSHOT</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.mina</groupId>
+ <artifactId>mina-filter-ssl</artifactId>
+ <version>1.1.0-SNAPSHOT</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.directory.shared</groupId>
+ <artifactId>shared-asn1</artifactId>
+ <version>0.9.6-SNAPSHOT</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.directory.shared</groupId>
+ <artifactId>shared-asn1-codec</artifactId>
+ <version>0.9.6-SNAPSHOT</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.directory.shared</groupId>
+ <artifactId>shared-ldap</artifactId>
+ <version>0.9.6-SNAPSHOT</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>antlr</groupId>
+ <artifactId>antlr</artifactId>
+ <version>2.7.2</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>commons-lang</groupId>
+ <artifactId>commons-lang</artifactId>
+ <version>2.0</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>commons-collections</groupId>
+ <artifactId>commons-collections</artifactId>
+ <version>3.1</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.osgi.compendium</artifactId>
+ <version>0.8.0-SNAPSHOT</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.servicebinder</artifactId>
+ <version>0.8.0-SNAPSHOT</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-simple</artifactId>
+ <version>1.0</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>jcl104-over-slf4j</artifactId>
+ <version>1.0-rc5</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.osgi</groupId>
+ <artifactId>spring-mock</artifactId>
+ <version>2.1-SNAPSHOT</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.osgi</groupId>
+ <artifactId>spring-core</artifactId>
+ <version>2.1-SNAPSHOT</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.osgi</groupId>
+ <artifactId>spring-context</artifactId>
+ <version>2.1-SNAPSHOT</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.osgi</groupId>
+ <artifactId>spring-beans</artifactId>
+ <version>2.1-SNAPSHOT</version>
+ <scope>test</scope>
+ </dependency>
+
+ </dependencies>
+</project>
Added: directory/sandbox/jconlon/osgi-apacheds/protocol-ldap-osgi/resources/log4j.properties
URL: http://svn.apache.org/viewvc/directory/sandbox/jconlon/osgi-apacheds/protocol-ldap-osgi/resources/log4j.properties?view=auto&rev=486813
==============================================================================
--- directory/sandbox/jconlon/osgi-apacheds/protocol-ldap-osgi/resources/log4j.properties (added)
+++ directory/sandbox/jconlon/osgi-apacheds/protocol-ldap-osgi/resources/log4j.properties Wed Dec 13 11:41:43 2006
@@ -0,0 +1,60 @@
+# $Id: log4j.properties,v 1.3 2004/9/3 9:55 jconlon Exp $
+# Log4j properties file suitable for server or deployment use.
+# Author: John Conlon
+
+# Application coverage: junit test of apacheds.
+
+# Note: Logging adds visibility into the inner workings of production and
+# library components. However it does add another layer of configuration
+# complexity. The following are some guidelines:
+
+# For deployment place this file along with other resource files in the
+# WEB-INF/classes directory of the web application or on an appropriate
+# location in the classpath.
+
+# ==============================================================================
+
+# RootCategory all other categories inherit from this
+log4j.rootCategory=WARN,console
+
+# Production classes that use logging
+log4j.category.org.apache.ldap.server=DEBUG
+log4j.category.org.apache.directory.osgi.backend=DEBUG
+#log4j.category.org.apache.directory.server.core.DefaultDirectoryService=ERROR
+log4j.category.org.apache.directory.server.core.configuration=DEBUG
+log4j.category.org.apache.directory.server.protocol.shared.store=DEBUG
+
+
+# Console Appender
+log4j.appender.console=org.apache.log4j.ConsoleAppender
+
+# use stdout
+log4j.appender.console.target=System.out
+
+# Deployment File Appender
+log4j.appender.file=org.apache.log4j.RollingFileAppender
+log4j.appender.file.layout=org.apache.log4j.PatternLayout
+log4j.appender.file.layout.ConversionPattern=%d{DATE} %-5p %c{2} %M.%L %x - %m\n
+log4j.appender.file.file=application.log
+log4j.appender.file.maxBackupIndex=3
+log4j.appender.file.maxFileSize=100KB
+
+# console's layout is a PatternLayout, using the conversion pattern
+log4j.appender.console.layout=org.apache.log4j.PatternLayout
+
+# Deployment console
+# %d{DATE} %-5p %c{2} %M.%L %x - %m\n. Thus, the log output will
+# d - include the date,
+# p - followed by the priority of the log request,
+# c - followed by the two rightmost components of the category name,
+# M - followed by the callers method name,
+# l - followed by the line number,
+# x - the nested disgnostic context
+# m - finally the message itself.
+# Refer to the documentation of PatternLayout for further information
+# on the syntax of the ConversionPattern key.
+# log4j.appender.console.layout.ConversionPattern=%d{DATE} %-5p %c{2} %M.%L %x - %m\n
+
+# Development console
+# l - location information replaces the date field.
+log4j.appender.console.layout.ConversionPattern=%-5p %l - %m%n
\ No newline at end of file
Added: directory/sandbox/jconlon/osgi-apacheds/protocol-ldap-osgi/resources/nonspecific.ldif
URL: http://svn.apache.org/viewvc/directory/sandbox/jconlon/osgi-apacheds/protocol-ldap-osgi/resources/nonspecific.ldif?view=auto&rev=486813
==============================================================================
--- directory/sandbox/jconlon/osgi-apacheds/protocol-ldap-osgi/resources/nonspecific.ldif (added)
+++ directory/sandbox/jconlon/osgi-apacheds/protocol-ldap-osgi/resources/nonspecific.ldif Wed Dec 13 11:41:43 2006
@@ -0,0 +1,14 @@
+dn: cn=person0,dc=example,dc=com
+objectClass: person
+cn: cn_person0
+sn: sn_person0
+
+dn: cn=person1,dc=example,dc=com
+objectClass: organizationalPerson
+cn: cn_person1
+sn: sn_person1
+
+dn: cn=person2,dc=example,dc=com
+objectClass: inetOrgPerson
+cn: cn_person2
+sn: sn_person2
Added: directory/sandbox/jconlon/osgi-apacheds/protocol-ldap-osgi/server.properties
URL: http://svn.apache.org/viewvc/directory/sandbox/jconlon/osgi-apacheds/protocol-ldap-osgi/server.properties?view=auto&rev=486813
==============================================================================
--- directory/sandbox/jconlon/osgi-apacheds/protocol-ldap-osgi/server.properties (added)
+++ directory/sandbox/jconlon/osgi-apacheds/protocol-ldap-osgi/server.properties Wed Dec 13 11:41:43 2006
@@ -0,0 +1,4 @@
+#external spring properties file
+#defaultServerConfigurator.defaultFactoryConfiguration[server.net.ldaps.port]=10636
+#defaultServerConfigurator.defaultFactoryConfiguration[server.net.ldap.port]=10389
+defaultServerConfigurator.delaySeconds=1
Added: directory/sandbox/jconlon/osgi-apacheds/protocol-ldap-osgi/src/main/java/org/apache/directory/server/ldap/osgi/DefaultServerConfigurator.java
URL: http://svn.apache.org/viewvc/directory/sandbox/jconlon/osgi-apacheds/protocol-ldap-osgi/src/main/java/org/apache/directory/server/ldap/osgi/DefaultServerConfigurator.java?view=auto&rev=486813
==============================================================================
--- directory/sandbox/jconlon/osgi-apacheds/protocol-ldap-osgi/src/main/java/org/apache/directory/server/ldap/osgi/DefaultServerConfigurator.java (added)
+++ directory/sandbox/jconlon/osgi-apacheds/protocol-ldap-osgi/src/main/java/org/apache/directory/server/ldap/osgi/DefaultServerConfigurator.java Wed Dec 13 11:41:43 2006
@@ -0,0 +1,120 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.directory.server.ldap.osgi;
+
+
+import java.util.Properties;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.ScheduledFuture;
+import java.util.concurrent.TimeUnit;
+
+import javax.naming.spi.InitialContextFactory;
+
+import org.osgi.service.cm.ConfigurationException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * DefaultServerStarter a runnable that schedules configuration of a default ldap server.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class DefaultServerConfigurator implements Runnable
+{
+
+ private static final Logger log = LoggerFactory.getLogger( DefaultServerConfigurator.class );
+
+ private static final String SERVER_USE_FACTORY_INSTANCE = "server.use.factory.instance";
+
+ private LdapServerFactory ldapServerFactory;
+
+ private Properties defaultProperties;
+
+ private InitialContextFactory initialContextFactory;
+
+ private long delaySeconds;
+
+
+ /**
+ *
+ * Schedules this Runnable with the delaySeconds.
+ *
+ * @param ldapServerFactory
+ * @param scheduledExecutor
+ * @return scheduledFuture
+ */
+ ScheduledFuture<?> schedule( LdapServerFactory ldapServerFactory, ScheduledExecutorService scheduledExecutor )
+ {
+ this.ldapServerFactory = ldapServerFactory;
+ this.initialContextFactory = ldapServerFactory.getInitialContextFactory();
+ log.info( "Scheduling the configuration of a default ldap server in {} seconds", delaySeconds );
+ return scheduledExecutor.schedule( this, delaySeconds, TimeUnit.SECONDS );
+ }
+
+
+ public void run()
+ {
+ if ( ldapServerFactory == null || initialContextFactory == null )
+ {
+ log
+ .warn( ldapServerFactory == null ? "Failed to start the default server because the LdapServerFactory is null"
+ : "Failed to start the default server because the InitialContextFactory is null." );
+ return;
+ }
+ log.info( "Configuring a default ldap server with properties {}.", defaultProperties );
+ try
+ {
+ defaultProperties.put( SERVER_USE_FACTORY_INSTANCE, initialContextFactory );
+ ldapServerFactory.updated( LdapServerFactory.DEFAULT_PID, defaultProperties );
+ }
+ catch ( ConfigurationException e )
+ {
+ log.error( "Failed to start the defaultServer", e );
+ }
+ }
+
+
+ public Properties getDefaultFactoryConfiguration()
+ {
+ return defaultProperties;
+ }
+
+
+ public void setDefaultFactoryConfiguration( Properties defaultConfiguration )
+ {
+ this.defaultProperties = defaultConfiguration;
+ }
+
+
+ public long getDelaySeconds()
+ {
+ return delaySeconds;
+ }
+
+
+ public void setDelaySeconds( long delay )
+ {
+ this.delaySeconds = delay;
+ }
+
+}
Added: directory/sandbox/jconlon/osgi-apacheds/protocol-ldap-osgi/src/main/java/org/apache/directory/server/ldap/osgi/LdapConfig.java
URL: http://svn.apache.org/viewvc/directory/sandbox/jconlon/osgi-apacheds/protocol-ldap-osgi/src/main/java/org/apache/directory/server/ldap/osgi/LdapConfig.java?view=auto&rev=486813
==============================================================================
--- directory/sandbox/jconlon/osgi-apacheds/protocol-ldap-osgi/src/main/java/org/apache/directory/server/ldap/osgi/LdapConfig.java (added)
+++ directory/sandbox/jconlon/osgi-apacheds/protocol-ldap-osgi/src/main/java/org/apache/directory/server/ldap/osgi/LdapConfig.java Wed Dec 13 11:41:43 2006
@@ -0,0 +1,147 @@
+/*
+ * Copyright 2005 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.directory.server.ldap.osgi;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.directory.server.core.DirectoryService;
+import org.apache.directory.server.core.configuration.Configuration;
+import org.apache.directory.server.core.configuration.ConfigurationException;
+
+public class LdapConfig extends Configuration
+{
+ private static final long serialVersionUID = 6738567218407227901L;
+
+
+ public static String LDAP_PORT_KEY = "ldap.port";
+ public static String LDAPS_PORT_KEY = "ldaps.port";
+
+ private static String LDAP_PORT_DEFAULT = "10389";
+ private static String LDAPS_PORT_DEFAULT = "10636";
+
+ private static String SERVICE_PID = "service.pid";
+ private static String PID = "org.apache.ldap";
+ private static String name = "Apache LDAP Service";
+
+ private Map<String,String> configuration = new HashMap<String,String>();
+
+ /**
+ * Creates a new instance with default settings.
+ */
+ public LdapConfig()
+ {
+ this( getDefaultConfig() );
+ }
+
+ /**
+ * Creates a new instance with default settings that operates on the
+ * {@link DirectoryService} with the specified ID.
+ */
+ public LdapConfig( String instanceId )
+ {
+ this( getDefaultConfig() );
+ setInstanceId( instanceId );
+ }
+
+ public LdapConfig( Map<String,String> properties )
+ {
+ if ( properties == null )
+ {
+ configuration = getDefaultConfig();
+ }
+ else
+ {
+ configuration.putAll( properties );
+ }
+
+ int port = getPort();
+
+ if ( port < 1 || port > 0xFFFF )
+ {
+ throw new ConfigurationException( "Invalid value: " + LDAP_PORT_KEY + "=" + port );
+ }
+
+ int securePort = getSecurePort();
+
+ if ( securePort < 1 || securePort > 0xFFFF )
+ {
+ throw new ConfigurationException( "Invalid value: " + LDAPS_PORT_KEY + "=" + securePort );
+ }
+ }
+
+ public boolean isDifferent( Map config )
+ {
+ if ( getPort() != ( (Integer) config.get( LDAP_PORT_KEY ) ).intValue() )
+ {
+ return true;
+ }
+
+ if ( getSecurePort() != ( (Integer) config.get( LDAPS_PORT_KEY ) ).intValue() )
+ {
+ return true;
+ }
+
+ return true;
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public int getPort()
+ {
+ String key = LDAP_PORT_KEY;
+
+ if ( configuration.containsKey( key ) )
+ {
+ return Integer.parseInt( get( key ) );
+ }
+
+ return Integer.parseInt( LDAP_PORT_DEFAULT );
+ }
+
+ public int getSecurePort()
+ {
+ String key = LDAPS_PORT_KEY;
+
+ if ( configuration.containsKey( key ) )
+ {
+ return Integer.parseInt( get( key ) );
+ }
+
+ return Integer.parseInt( LDAPS_PORT_DEFAULT );
+ }
+
+ public static Map<String,String> getDefaultConfig()
+ {
+ Map<String,String> defaults = new HashMap<String,String>();
+
+ defaults.put( SERVICE_PID, PID );
+ defaults.put( LDAP_PORT_KEY, LDAP_PORT_DEFAULT );
+ defaults.put( LDAPS_PORT_KEY, LDAPS_PORT_DEFAULT );
+
+ return defaults;
+ }
+
+ private String get( String key )
+ {
+ return (String) configuration.get( key );
+ }
+}
Added: directory/sandbox/jconlon/osgi-apacheds/protocol-ldap-osgi/src/main/java/org/apache/directory/server/ldap/osgi/LdapServer.java
URL: http://svn.apache.org/viewvc/directory/sandbox/jconlon/osgi-apacheds/protocol-ldap-osgi/src/main/java/org/apache/directory/server/ldap/osgi/LdapServer.java?view=auto&rev=486813
==============================================================================
--- directory/sandbox/jconlon/osgi-apacheds/protocol-ldap-osgi/src/main/java/org/apache/directory/server/ldap/osgi/LdapServer.java (added)
+++ directory/sandbox/jconlon/osgi-apacheds/protocol-ldap-osgi/src/main/java/org/apache/directory/server/ldap/osgi/LdapServer.java Wed Dec 13 11:41:43 2006
@@ -0,0 +1,82 @@
+/*
+ * Copyright 2005 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.directory.server.ldap.osgi;
+
+import java.io.IOException;
+import java.net.InetSocketAddress;
+import java.util.Hashtable;
+import java.util.Map;
+
+import org.apache.directory.server.core.configuration.StartupConfiguration;
+import org.apache.directory.server.ldap.LdapProtocolProvider;
+import org.apache.directory.shared.ldap.exception.LdapNamingException;
+import org.apache.mina.common.IoAcceptor;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class LdapServer
+{
+ /** the log for this class */
+ private static final Logger log = LoggerFactory.getLogger( LdapServer.class );
+
+ private LdapConfig config;
+ private IoAcceptor acceptor;
+ private LdapProtocolProvider provider;
+
+ public LdapServer( LdapConfig config, IoAcceptor acceptor, Hashtable env )
+ {
+ this.config = config;
+ this.acceptor = acceptor;
+
+ String name = config.getName();
+ int port = config.getPort();
+
+ try
+ {
+ provider = new LdapProtocolProvider( new StartupConfiguration(), (Hashtable) env.clone() );
+
+ acceptor.bind( new InetSocketAddress( port ), provider.getHandler() );
+
+ log.debug( "{} listening on port {}", name, new Integer( port ) );
+ }
+ catch ( LdapNamingException lne )
+ {
+ log.error( lne.getMessage(), lne );
+ }
+ catch ( IOException ioe )
+ {
+ log.error( ioe.getMessage(), ioe );
+ }
+ }
+
+ public boolean isDifferent( Map newConfig )
+ {
+ return config.isDifferent( newConfig );
+ }
+
+ public void destroy()
+ {
+ acceptor.unbind( new InetSocketAddress( config.getPort() ) );
+
+ acceptor = null;
+ provider = null;
+
+ log.debug( "{} has stopped listening on port {}", config.getName(), new Integer( config.getPort() ) );
+ }
+}
+
Added: directory/sandbox/jconlon/osgi-apacheds/protocol-ldap-osgi/src/main/java/org/apache/directory/server/ldap/osgi/LdapServerFactory.java
URL: http://svn.apache.org/viewvc/directory/sandbox/jconlon/osgi-apacheds/protocol-ldap-osgi/src/main/java/org/apache/directory/server/ldap/osgi/LdapServerFactory.java?view=auto&rev=486813
==============================================================================
--- directory/sandbox/jconlon/osgi-apacheds/protocol-ldap-osgi/src/main/java/org/apache/directory/server/ldap/osgi/LdapServerFactory.java (added)
+++ directory/sandbox/jconlon/osgi-apacheds/protocol-ldap-osgi/src/main/java/org/apache/directory/server/ldap/osgi/LdapServerFactory.java Wed Dec 13 11:41:43 2006
@@ -0,0 +1,206 @@
+package org.apache.directory.server.ldap.osgi;
+
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+
+import javax.naming.spi.InitialContextFactory;
+
+import org.apache.directory.server.core.configuration.StartupConfiguration;
+import org.apache.mina.common.IoAcceptor;
+import org.apache.mina.transport.socket.nio.SocketAcceptor;
+import org.osgi.service.cm.ConfigurationException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+public class LdapServerFactory
+{
+
+ private static final String APACHE_LDAP_SERVICE_FACTORY = "Apache LDAP Service Factory";
+
+ private static final Logger log = LoggerFactory.getLogger( LdapServerFactory.class );
+
+ static final String DEFAULT_PID = "org.apache.ldap.default";
+
+ private Hashtable env;
+
+ private final Map<String, LdapServer> servers = Collections.synchronizedMap( new HashMap<String, LdapServer>() );
+
+ private final IoAcceptor acceptor = new SocketAcceptor();
+
+ private InitialContextFactory initialContextFactory;
+
+ private ScheduledExecutorService exec = null;
+
+ private DefaultServerConfigurator defaultServerConfigurator;
+
+
+ public void updated( String pid, Map config ) throws ConfigurationException
+ {
+ log.debug( getName() + " updating {} with {}", pid, config );
+ LdapConfig ldapConfig = new LdapConfig( config );
+
+ synchronized ( servers )
+ {
+ if ( pid.equals( DEFAULT_PID ) && servers.size() > 0 )
+ {
+ return;
+ }
+
+ // As soon as we get a "non-default"-config, delete default
+ if ( !pid.equals( DEFAULT_PID ) )
+ {
+ deleted( DEFAULT_PID );
+ }
+
+ // For a given pid, do we have the service?
+ LdapServer server = ( LdapServer ) servers.get( pid );
+
+ // If we don't have the service, create it with the config.
+ // Or, if we do have the service, re-create it if the config is
+ // different.
+ if ( server == null || server.isDifferent( config ) )
+ {
+ deleted( pid );
+
+ server = new LdapServer( ldapConfig, acceptor, env );
+ servers.put( pid, server );
+
+ }
+ }
+ }
+
+
+ public void deleted( String pid )
+ {
+ synchronized ( servers )
+ {
+ LdapServer server = ( LdapServer ) servers.remove( pid );
+
+ if ( server != null )
+ {
+ server.destroy();
+ }
+ }
+ }
+
+
+ public String getName()
+ {
+ return APACHE_LDAP_SERVICE_FACTORY;
+ }
+
+
+ /**
+ * All required services have been bound, but our service(s) are not yet
+ * registered. Schedule the configuration of a default server if one is not already
+ * set in the config admin.
+ */
+ public void init()
+ {
+ log.debug( "Initializing" );
+ try
+ {
+ env = new Hashtable( new StartupConfiguration().toJndiEnvironment() );
+ loadEnvironment( env );
+ exec = Executors.newScheduledThreadPool( 1 );
+ defaultServerConfigurator.schedule( this, exec );
+ }
+ catch ( RuntimeException e )
+ {
+ log.error( "Failed to initialize",e );
+ throw e;
+ }
+ }
+
+
+ /**
+ * Invalidation has started and our services have been unregistered, but any
+ * required services have not been unbound yet.
+ */
+ public void destroy()
+ {
+ log.info( "Deactivating all LDAP Servers." );
+ if ( exec != null )
+ {
+ exec.shutdownNow();
+ exec = null;
+ }
+ synchronized ( servers )
+ {
+ Iterator it = servers.values().iterator();
+
+ while ( it.hasNext() )
+ {
+ LdapServer ldapServer = ( LdapServer ) it.next();
+ ldapServer.destroy();
+ }
+
+ servers.clear();
+ }
+ }
+
+
+ public InitialContextFactory getInitialContextFactory()
+ {
+ return initialContextFactory;
+ }
+
+
+ /**
+ * Invoked when the InitialContextFactory registers in the OSGi runtime.
+ *
+ * @param initialContextFactory
+ */
+ public void setInitialContextFactory( InitialContextFactory initialContextFactory )
+ {
+ this.initialContextFactory = initialContextFactory;
+ }
+
+
+ /**
+ * Invoked when the InitialContextFactory unregisters from the OSGi runtime.
+ * This stops all ldap servers.
+ *
+ * @param initialContextFactory
+ */
+ public void unsetInitialContextFactory( InitialContextFactory initialContextFactory )
+ {
+ log.debug( "InitialContextFactory is unset. Stopping all servers." );
+ this.initialContextFactory = null;
+ destroy();
+ }
+
+
+ int serverCount()
+ {
+ synchronized ( servers )
+ {
+ return servers.size();
+ }
+ }
+
+
+ public DefaultServerConfigurator getDefaultServerConfigurator()
+ {
+ return defaultServerConfigurator;
+ }
+
+
+ public void setDefaultServerConfigurator( DefaultServerConfigurator defaultServerStarter )
+ {
+ this.defaultServerConfigurator = defaultServerStarter;
+ }
+
+
+ private void loadEnvironment( Hashtable env )
+ {
+ env.putAll( defaultServerConfigurator.getDefaultFactoryConfiguration() );
+ }
+}
Added: directory/sandbox/jconlon/osgi-apacheds/protocol-ldap-osgi/src/main/resources/META-INF/spring/server-osgi.xml
URL: http://svn.apache.org/viewvc/directory/sandbox/jconlon/osgi-apacheds/protocol-ldap-osgi/src/main/resources/META-INF/spring/server-osgi.xml?view=auto&rev=486813
==============================================================================
--- directory/sandbox/jconlon/osgi-apacheds/protocol-ldap-osgi/src/main/resources/META-INF/spring/server-osgi.xml (added)
+++ directory/sandbox/jconlon/osgi-apacheds/protocol-ldap-osgi/src/main/resources/META-INF/spring/server-osgi.xml Wed Dec 13 11:41:43 2006
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:osgi="http://www.springframework.org/schema/osgi"
+ xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
+ http://www.springframework.org/schema/osgi http://www.springframework.org/schema/osgi/spring-osgi.xsd">
+
+ <osgi:reference id="initialContextFactoryService"
+ interface="javax.naming.spi.InitialContextFactory" />
+
+ <osgi:config id="ldapProperties" factory="true"
+ persistent-id="org.apache.ldap.factory">
+ <osgi:config-listener ref="ldapServerFactory"
+ update-method="updated" deleted-method="deleted" />
+ </osgi:config>
+
+</beans>
\ No newline at end of file
Added: directory/sandbox/jconlon/osgi-apacheds/protocol-ldap-osgi/src/main/resources/META-INF/spring/server.xml
URL: http://svn.apache.org/viewvc/directory/sandbox/jconlon/osgi-apacheds/protocol-ldap-osgi/src/main/resources/META-INF/spring/server.xml?view=auto&rev=486813
==============================================================================
--- directory/sandbox/jconlon/osgi-apacheds/protocol-ldap-osgi/src/main/resources/META-INF/spring/server.xml (added)
+++ directory/sandbox/jconlon/osgi-apacheds/protocol-ldap-osgi/src/main/resources/META-INF/spring/server.xml Wed Dec 13 11:41:43 2006
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
+
+ <bean id="propertyConfigurer"
+ class="org.springframework.beans.factory.config.PropertyOverrideConfigurer">
+ <property name="location">
+ <bean
+ class="org.springframework.core.io.FileSystemResource">
+ <constructor-arg value="server.properties" />
+ </bean>
+ </property>
+ <property name="ignoreInvalidKeys" value="true" />
+ </bean>
+
+ <bean id="ldapServerFactory"
+ class="org.apache.directory.server.ldap.osgi.LdapServerFactory"
+ init-method="init" destroy-method="destroy">
+ <property name="defaultServerConfigurator"
+ ref="defaultServerConfigurator" />
+ <property name="initialContextFactory"
+ ref="initialContextFactoryService" />
+ </bean>
+
+ <bean id="defaultServerConfigurator"
+ class="org.apache.directory.server.ldap.osgi.DefaultServerConfigurator">
+ <property name="defaultFactoryConfiguration">
+ <props>
+ <prop key="java.naming.provider.url">
+ uid=admin,ou=system
+ </prop>
+ <prop key="java.naming.factory.initial">
+ org.apache.directory.server.core.jndi.CoreContextFactory
+ </prop>
+ <prop key="asn.1.berlib.provider">
+ org.apache.ldap.common.berlib.asn1.SnickersProvider
+ </prop>
+ <prop key="server.disable.anonymous">true</prop>
+ <!--
+ <prop key="server.net.ldap.port">389</prop>
+ <prop key="server.net.ldaps.port">636</prop>
+ -->
+ <prop
+ key="java.naming.ldap.attributes.binary">photo personalSignature audio jpegPhoto javaSerializedData userPassword userCertificate cACertificate authorityRevocationList certificateRevocationList crossCertificatePair x500UniqueIdentifier krb5Key
+ </prop>
+ </props>
+ </property>
+ <!-- How long to wait before starting the default ldap server. -->
+ <property name="delaySeconds" value="5" />
+ </bean>
+
+</beans>
Added: directory/sandbox/jconlon/osgi-apacheds/protocol-ldap-osgi/src/test/java/org/apache/directory/server/ldap/osgi/IntegrationTest.java
URL: http://svn.apache.org/viewvc/directory/sandbox/jconlon/osgi-apacheds/protocol-ldap-osgi/src/test/java/org/apache/directory/server/ldap/osgi/IntegrationTest.java?view=auto&rev=486813
==============================================================================
--- directory/sandbox/jconlon/osgi-apacheds/protocol-ldap-osgi/src/test/java/org/apache/directory/server/ldap/osgi/IntegrationTest.java (added)
+++ directory/sandbox/jconlon/osgi-apacheds/protocol-ldap-osgi/src/test/java/org/apache/directory/server/ldap/osgi/IntegrationTest.java Wed Dec 13 11:41:43 2006
@@ -0,0 +1,87 @@
+/*
+ * Copyright 2006 the original author or authors.
+ *
+ * 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.directory.server.ldap.osgi;
+
+
+import java.util.Properties;
+import java.util.concurrent.TimeUnit;
+
+import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
+
+
+/**
+ *
+ * IntegrationTest tests the service locally (outside of OSGi) within a Spring container.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class IntegrationTest extends AbstractDependencyInjectionSpringContextTests
+{
+ private LdapServerFactory ldapServerFactory;
+ private DefaultServerConfigurator defaultServerConfigurator;
+
+ protected String[] getConfigLocations()
+ {
+ return new String[]
+ { "mockInitialContextFactory.xml", "META-INF/spring/server.xml" };
+ }
+
+
+ public void setLdapServerFactory( LdapServerFactory ldapServerFactory )
+ {
+ this.ldapServerFactory = ldapServerFactory;
+ }
+
+
+ public void setDefaultServerConfigurator( DefaultServerConfigurator defaultServerConfigurator )
+ {
+ this.defaultServerConfigurator = defaultServerConfigurator;
+ }
+
+
+ /* ==================================== Tests ===================================================*/
+ public void testEnvironment()
+ {
+ assertNotNull( defaultServerConfigurator );
+ Properties properties = defaultServerConfigurator.getDefaultFactoryConfiguration();
+ assertFalse( properties.isEmpty() );
+// assertEquals( "10636", properties.get( "server.net.ldaps.port" ) );
+// assertEquals( "10389", properties.get( "server.net.ldap.port" ) );
+ assertEquals(1, defaultServerConfigurator.getDelaySeconds());
+ assertEquals(0, ldapServerFactory.serverCount() );
+ }
+
+ public void testLdapServerFactory()
+ {
+ assertNotNull( ldapServerFactory );
+
+ assertEquals( 0, ldapServerFactory.serverCount() );
+ try
+ {
+ TimeUnit.SECONDS.sleep( defaultServerConfigurator.getDelaySeconds()*2);
+ assertEquals( 1, ldapServerFactory.serverCount() );
+ }
+ catch ( InterruptedException e )
+ {
+ fail("Should not be interupted " +e);
+
+ }
+
+ }
+
+
+}
Added: directory/sandbox/jconlon/osgi-apacheds/protocol-ldap-osgi/src/test/java/org/apache/directory/server/ldap/osgi/MockInitialContextFactory.java
URL: http://svn.apache.org/viewvc/directory/sandbox/jconlon/osgi-apacheds/protocol-ldap-osgi/src/test/java/org/apache/directory/server/ldap/osgi/MockInitialContextFactory.java?view=auto&rev=486813
==============================================================================
--- directory/sandbox/jconlon/osgi-apacheds/protocol-ldap-osgi/src/test/java/org/apache/directory/server/ldap/osgi/MockInitialContextFactory.java (added)
+++ directory/sandbox/jconlon/osgi-apacheds/protocol-ldap-osgi/src/test/java/org/apache/directory/server/ldap/osgi/MockInitialContextFactory.java Wed Dec 13 11:41:43 2006
@@ -0,0 +1,53 @@
+/*
+ * Copyright 2006 the original author or authors.
+ *
+ * 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.directory.server.ldap.osgi;
+
+
+import javax.naming.Context;
+import javax.naming.NamingException;
+import javax.naming.spi.InitialContextFactory;
+
+
+
+
+/**
+ *
+ * MockInitialContextFactory provides a mock JNDI initial context factory for the
+ * test spring configuration mockInitialContextFactory.xml.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class MockInitialContextFactory implements InitialContextFactory
+{
+ private final Context mockCtx;
+
+
+ public MockInitialContextFactory( Context ctx )
+ {
+ mockCtx = ctx;
+ }
+
+
+ public Context getInitialContext( java.util.Hashtable<?, ?> environment ) throws NamingException
+ {
+ if ( mockCtx == null )
+ {
+ throw new IllegalStateException( "mock context was not set." );
+ }
+ return mockCtx;
+ }
+}
\ No newline at end of file
Added: directory/sandbox/jconlon/osgi-apacheds/protocol-ldap-osgi/src/test/resources/log4j.properties
URL: http://svn.apache.org/viewvc/directory/sandbox/jconlon/osgi-apacheds/protocol-ldap-osgi/src/test/resources/log4j.properties?view=auto&rev=486813
==============================================================================
--- directory/sandbox/jconlon/osgi-apacheds/protocol-ldap-osgi/src/test/resources/log4j.properties (added)
+++ directory/sandbox/jconlon/osgi-apacheds/protocol-ldap-osgi/src/test/resources/log4j.properties Wed Dec 13 11:41:43 2006
@@ -0,0 +1,14 @@
+log4j.rootCategory=DEBUG,console
+
+# Production classes that use logging
+log4j.category.org.apache.directory.server.ldap.osgi=DEBUG
+#log4j.category.org.apache.directory.server.core.DefaultDirectoryService=ERROR
+log4j.category.org.apache.directory.server.core.configuration=DEBUG
+log4j.category.org.apache.directory.server.protocol.shared.store=DEBUG
+
+
+# Console Appender
+log4j.appender.console=org.apache.log4j.ConsoleAppender
+log4j.appender.console.target=System.out
+log4j.appender.console.layout=org.apache.log4j.PatternLayout
+log4j.appender.console.layout.ConversionPattern=%-5p %l - %m%n
\ No newline at end of file
Added: directory/sandbox/jconlon/osgi-apacheds/protocol-ldap-osgi/src/test/resources/mockInitialContextFactory.xml
URL: http://svn.apache.org/viewvc/directory/sandbox/jconlon/osgi-apacheds/protocol-ldap-osgi/src/test/resources/mockInitialContextFactory.xml?view=auto&rev=486813
==============================================================================
--- directory/sandbox/jconlon/osgi-apacheds/protocol-ldap-osgi/src/test/resources/mockInitialContextFactory.xml (added)
+++ directory/sandbox/jconlon/osgi-apacheds/protocol-ldap-osgi/src/test/resources/mockInitialContextFactory.xml Wed Dec 13 11:41:43 2006
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
+
+ <bean id="initialContextFactoryService"
+ class="org.apache.directory.server.ldap.osgi.MockInitialContextFactory">
+ <constructor-arg>
+ <bean class="org.springframework.mock.jndi.SimpleNamingContext"/>
+ </constructor-arg>
+ </bean>
+
+</beans>