import redback components sources
http://svn.codehaus.org/redback/components/trunk/ r1724.


git-svn-id: https://svn.apache.org/repos/asf/archiva/redback/redback-components/trunk@1310262 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/pom.xml b/pom.xml
new file mode 100644
index 0000000..ce8ae60
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,119 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ 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.
+-->
+<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">
+  <parent>
+    <groupId>org.codehaus.redback.components</groupId>
+    <artifactId>redback-components</artifactId>
+    <version>1.3-SNAPSHOT</version>
+    <relativePath>../redback-components-parent/pom.xml</relativePath>
+  </parent>
+  <modelVersion>4.0.0</modelVersion>
+  <artifactId>spring-apacheds</artifactId>
+  <name>Spring Apache Directory Server Components</name>
+  <version>1.1-SNAPSHOT</version>
+
+  <url>http://redback.codehaus.org/components/${project.artifactId}</url>
+
+  <distributionManagement>
+    <site>
+      <id>codehaus.org</id>
+      <url>dav:https://dav.codehaus.org/redback/components/${project.artifactId}</url>
+    </site>
+  </distributionManagement>
+
+  <scm>
+    <connection>scm:svn:https://svn.codehaus.org/redback/components/trunk/spring-apacheds</connection>
+    <developerConnection>scm:svn:https://svn.codehaus.org/redback/components/trunk/spring-apacheds</developerConnection>
+    <url>http://fisheye.codehaus.org/browse/redback/components/trunk/spring-apacheds</url>
+  </scm>
+
+  <properties>
+    <apacheds.version>1.5.1</apacheds.version>
+  </properties>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.directory.server</groupId>
+      <artifactId>apacheds-core</artifactId>
+      <version>${apacheds.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.directory.server</groupId>
+      <artifactId>apacheds-core-shared</artifactId>
+      <version>${apacheds.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.directory.server</groupId>
+      <artifactId>apacheds-server-jndi</artifactId>
+      <version>${apacheds.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.directory.server</groupId>
+      <artifactId>apacheds-bootstrap-partition</artifactId>
+      <version>${apacheds.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.directory.server</groupId>
+      <artifactId>apacheds-schema-registries</artifactId>
+      <version>${apacheds.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.directory.server</groupId>
+      <artifactId>apacheds-schema-extras</artifactId>
+      <version>${apacheds.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-api</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>javax.inject</groupId>
+      <artifactId>javax.inject</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.springframework</groupId>
+      <artifactId>spring-core</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.springframework</groupId>
+      <artifactId>spring-context</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.springframework</groupId>
+      <artifactId>spring-context-support</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.springframework</groupId>
+      <artifactId>spring-beans</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.springframework</groupId>
+      <artifactId>spring-test</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>jcl-over-slf4j</artifactId>
+      <version>${slf4jVersion}</version>
+      <scope>test</scope>
+    </dependency>
+
+  </dependencies>
+
+</project>
diff --git a/src/main/java/org/codehaus/redback/components/apacheds/ApacheDs.java b/src/main/java/org/codehaus/redback/components/apacheds/ApacheDs.java
new file mode 100644
index 0000000..ac512d0
--- /dev/null
+++ b/src/main/java/org/codehaus/redback/components/apacheds/ApacheDs.java
@@ -0,0 +1,69 @@
+package org.codehaus.redback.components.apacheds;
+
+import javax.naming.NamingException;
+import javax.naming.directory.InitialDirContext;
+import javax.naming.directory.Attributes;
+import java.io.File;
+import java.util.Set;
+
+/**
+ * @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
+ * @version $Id$
+ */
+public interface ApacheDs
+{
+    String ROLE = ApacheDs.class.getName();
+
+    // ----------------------------------------------------------------------
+    // Configuration
+    // ----------------------------------------------------------------------
+
+    void setBasedir( File basedir );
+
+    void setPort( int port );
+    
+    int getPort();
+    
+    void setEnableNetworking( boolean enableNetworking );
+
+    void addPartition( String name, String root, Set indexedAttributes, Attributes partitionAttributes )
+        throws NamingException;
+
+    void addPartition( Partition partition )
+        throws NamingException;
+
+    /**
+     * Creates a partition usable for testing and other light usage.
+     *
+     * @param name The name of the partition. Will be used as the directory name when persisted.
+     * @param domainComponents E.g. "plexus", "codehaus", "org"
+     * @throws NamingException
+     */
+    Partition addSimplePartition( String name, String[] domainComponents )
+        throws NamingException;
+
+    // ----------------------------------------------------------------------
+    // Server control
+    // ----------------------------------------------------------------------
+
+    void startServer()
+        throws Exception;
+
+    void stopServer()
+        throws Exception;
+
+    void sync()
+        throws Exception;
+
+    boolean isStopped();
+
+    // ----------------------------------------------------------------------
+    //
+    // ----------------------------------------------------------------------
+
+    InitialDirContext getAdminContext()
+        throws NamingException;
+
+    InitialDirContext getSystemContext()
+        throws NamingException;
+}
diff --git a/src/main/java/org/codehaus/redback/components/apacheds/DefaultApacheDs.java b/src/main/java/org/codehaus/redback/components/apacheds/DefaultApacheDs.java
new file mode 100644
index 0000000..85cc3e0
--- /dev/null
+++ b/src/main/java/org/codehaus/redback/components/apacheds/DefaultApacheDs.java
@@ -0,0 +1,335 @@
+package org.codehaus.redback.components.apacheds;
+
+/*
+ * Copyright 2001-2007 The Codehaus.
+ *
+ * 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.
+ */
+
+import org.apache.directory.server.configuration.MutableServerStartupConfiguration;
+import org.apache.directory.server.core.configuration.MutablePartitionConfiguration;
+import org.apache.directory.server.core.configuration.ShutdownConfiguration;
+import org.apache.directory.server.core.configuration.SyncConfiguration;
+import org.apache.directory.server.jndi.ServerContextFactory;
+import org.apache.directory.server.ldap.LdapConfiguration;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.naming.Context;
+import javax.naming.NamingException;
+import javax.naming.directory.Attribute;
+import javax.naming.directory.Attributes;
+import javax.naming.directory.BasicAttribute;
+import javax.naming.directory.BasicAttributes;
+import javax.naming.directory.InitialDirContext;
+import java.io.File;
+import java.util.HashSet;
+import java.util.Hashtable;
+import java.util.Properties;
+import java.util.Set;
+
+/**
+ * @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
+ * @author Olivier Lamy
+ * @version $Id$
+ */
+public class DefaultApacheDs
+    implements ApacheDs
+{
+
+    private Logger logger = LoggerFactory.getLogger( getClass() );
+
+    // ----------------------------------------------------------------------
+    // Configuration
+    // ----------------------------------------------------------------------
+
+    private boolean enableNetworking;
+
+    private File basedir;
+
+    private int port;
+
+    private String password;
+
+    // ----------------------------------------------------------------------
+    //
+    // ----------------------------------------------------------------------
+
+    private boolean stopped;
+
+    private MutableServerStartupConfiguration configuration;
+
+    private Set partitionConfigurations = new HashSet();
+
+    // ----------------------------------------------------------------------
+    // ApacheDs Implementation
+    // ----------------------------------------------------------------------
+
+    public void setBasedir( File basedir )
+    {
+        this.basedir = basedir;
+    }
+
+    public void setEnableNetworking( boolean enableNetworking )
+    {
+        this.enableNetworking = enableNetworking;
+    }
+
+    public InitialDirContext getAdminContext()
+        throws NamingException
+    {
+        assertIsStarted();
+
+        Hashtable environment = new Hashtable( configuration.toJndiEnvironment() );
+        environment.put( Context.INITIAL_CONTEXT_FACTORY, ServerContextFactory.class.getName() );
+        environment.put( Context.SECURITY_PRINCIPAL, "uid=admin,ou=system" );
+        environment.put( Context.SECURITY_CREDENTIALS, password );
+        environment.put( Context.SECURITY_AUTHENTICATION, "simple" );
+//        environment.put( Context.PROVIDER_URL, "dc=hauskeeper,dc=codehaus,dc=org" );
+        return new InitialDirContext( environment );
+    }
+
+    public InitialDirContext getSystemContext()
+        throws NamingException
+    {
+        assertIsStarted();
+
+        Hashtable environment = new Hashtable( configuration.toJndiEnvironment() );
+        environment.put( Context.INITIAL_CONTEXT_FACTORY, ServerContextFactory.class.getName() );
+        environment.put( Context.SECURITY_PRINCIPAL, "uid=admin,ou=system" );
+        environment.put( Context.SECURITY_CREDENTIALS, password );
+        environment.put( Context.SECURITY_AUTHENTICATION, "simple" );
+        environment.put( Context.PROVIDER_URL, "ou=system" );
+        return new InitialDirContext( environment );
+    }
+
+    public void addPartition( String name, String root, Set indexedAttributes, Attributes partitionAttributes )
+        throws NamingException
+    {
+        MutablePartitionConfiguration configuration = new MutablePartitionConfiguration();
+        configuration.setId( name );
+        configuration.setSuffix( root );
+        configuration.setIndexedAttributes( indexedAttributes );
+        configuration.setContextEntry( partitionAttributes );
+        partitionConfigurations.add( configuration );
+    }
+
+    public void addPartition( Partition partition )
+        throws NamingException
+    {
+        MutablePartitionConfiguration configuration = new MutablePartitionConfiguration();
+
+        configuration.setId( partition.getName() );
+        configuration.setSuffix( partition.getSuffix() );
+        configuration.setIndexedAttributes( partition.getIndexedAttributes() );
+        configuration.setContextEntry( partition.getContextAttributes() );
+        //configuration.setSynchOnWrite( true );
+        configuration.setCacheSize( 1 );
+        //configuration.setOptimizerEnabled( false );
+        partitionConfigurations.add( configuration );
+    }
+
+    public Partition addSimplePartition( String name, String[] domainComponents )
+        throws NamingException
+    {
+        if ( domainComponents.length == 0 )
+        {
+            throw new NamingException( "Illegal argument, there has to be at least one domain component." );
+        }
+
+        StringBuilder suffix = new StringBuilder();
+
+        for ( int i = 0; i < domainComponents.length; i++ )
+        {
+            String dc = domainComponents[i];
+
+            suffix.append( "dc=" ).append( dc );
+
+            if ( i != domainComponents.length - 1 )
+            {
+                suffix.append( "," );
+            }
+        }
+
+        // ----------------------------------------------------------------------
+        // The root entry of the partition
+        // ----------------------------------------------------------------------
+
+        Attributes attributes = new BasicAttributes( true );
+        attributes.put( "dc", domainComponents[0] );
+        Attribute objectClass = new BasicAttribute( "objectClass" );
+        objectClass.add( "top" );
+        objectClass.add( "domain" );
+        objectClass.add( "extensibleObject" );
+        attributes.put( objectClass );
+
+        Partition partition = new Partition();
+        partition.setName( name );
+        partition.setSuffix( suffix.toString() );
+        partition.setContextAttributes( attributes );
+        HashSet set = new HashSet();
+        set.add( "uid" );
+        set.add( "cn" );
+        partition.setIndexedAttributes( set );
+
+        addPartition( partition );
+
+        return partition;
+    }
+
+    public void startServer()
+        throws Exception
+    {
+        logger.info( "Starting Apache Directory Server server." );
+
+        logger.info( "ApacheDS basedir: " + basedir.getAbsolutePath() );
+
+        File logs = new File( basedir, "logs" );
+
+        if ( !logs.exists() && !logs.mkdirs() )
+        {
+            throw new Exception( "Could not create logs directory: " + logs.getAbsolutePath() );
+        }
+
+        Properties environment = new Properties();
+        environment.setProperty( "java.naming.security.authentication", "simple" );
+        environment.setProperty( "java.naming.security.principal", "uid=admin,ou=system" );
+        if ( password != null )
+        {
+            environment.setProperty( "java.naming.security.credentials", password );
+        }
+        MutableServerStartupConfiguration configuration = new MutableServerStartupConfiguration();
+        configuration.setWorkingDirectory( basedir );
+        configuration.setAllowAnonymousAccess( true );
+        //configuration.setEnableNtp( false );
+        //configuration.setEnableKerberos( false );
+        //configuration.setEnableChangePassword( false );
+        LdapConfiguration config = new LdapConfiguration();
+        config.setIpPort( port );
+        configuration.setLdapConfiguration( config );
+        configuration.setEnableNetworking( enableNetworking );
+        configuration.setSynchPeriodMillis( 100 );
+
+        if ( configuration.getPartitionConfigurations() == null || ( configuration.getPartitionConfigurations() != null
+            && configuration.getPartitionConfigurations().isEmpty() ) )
+        {
+            configuration.setPartitionConfigurations( partitionConfigurations );
+        }
+        Properties env = new Properties();
+        env.setProperty( Context.SECURITY_PRINCIPAL, "uid=admin,ou=system" );
+        if ( password != null )
+        {
+            env.setProperty( Context.SECURITY_CREDENTIALS, password );
+        }
+        env.setProperty( Context.SECURITY_AUTHENTICATION, "simple" );
+        env.setProperty( Context.PROVIDER_URL, "ou=system" );
+        env.setProperty( Context.INITIAL_CONTEXT_FACTORY, ServerContextFactory.class.getName() );
+        env.putAll( configuration.toJndiEnvironment() );
+        InitialDirContext context = new InitialDirContext( env );
+
+        //Attributes inetAttributes = context.getAttributes( "cn=inetorgperson,ou=schema" );
+
+        //inetAttributes.remove( "m-disabled" );
+
+        this.configuration = configuration;
+
+        logger.info( "Started Apache Directory Server server." );
+
+        stopped = false;
+    }
+
+    public void stopServer()
+        throws Exception
+    {
+        if ( stopped )
+        {
+            throw new Exception( "Already stopped." );
+        }
+
+        logger.info( "Stopping Apache Directory Server server." );
+
+        sync();
+
+        stopped = true;
+
+        Hashtable env = new Hashtable();
+        env.putAll( new ShutdownConfiguration().toJndiEnvironment() );
+        new InitialDirContext( env );
+
+        logger.info( "Apache Directory Server server stopped." );
+    }
+
+    public boolean isStopped()
+    {
+        return stopped;
+    }
+
+    public void sync()
+        throws Exception
+    {
+        logger.info( "Sync'ing Apache Directory Server server." );
+
+        Hashtable env = new Hashtable();
+        env.putAll( new SyncConfiguration().toJndiEnvironment() );
+        new InitialDirContext( env );
+    }
+
+
+    public void stop()
+    {
+        try
+        {
+            if ( !stopped )
+            {
+                stopServer();
+            }
+        }
+        catch ( Exception e )
+        {
+            throw new RuntimeException( "Error while stopping Apache Directory Server server.", e );
+        }
+    }
+
+    // ----------------------------------------------------------------------
+    //
+    // ----------------------------------------------------------------------
+
+    private void assertIsStarted()
+        throws NamingException
+    {
+        if ( configuration == null )
+        {
+            throw new NamingException( "The server has to be started before used." );
+        }
+    }
+
+    public int getPort()
+    {
+        return port;
+    }
+
+    public void setPort( int port )
+    {
+        this.port = port;
+    }
+
+    public String getPassword()
+    {
+        return password;
+    }
+
+    public void setPassword( String password )
+    {
+        this.password = password;
+    }
+}
diff --git a/src/main/java/org/codehaus/redback/components/apacheds/Partition.java b/src/main/java/org/codehaus/redback/components/apacheds/Partition.java
new file mode 100644
index 0000000..20a1a01
--- /dev/null
+++ b/src/main/java/org/codehaus/redback/components/apacheds/Partition.java
@@ -0,0 +1,71 @@
+package org.codehaus.redback.components.apacheds;
+
+import javax.naming.directory.Attributes;
+import javax.naming.directory.BasicAttributes;
+import java.util.Set;
+import java.util.HashSet;
+
+/**
+ * @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
+ * @version $Id$
+ */
+public class Partition
+{
+    private String name;
+
+    private String suffix;
+
+    private Set indexedAttributes;
+
+    private Attributes contextAttributes;
+
+    public String getName()
+    {
+        return name;
+    }
+
+    public void setName( String name )
+    {
+        this.name = name;
+    }
+
+    public String getSuffix()
+    {
+        return suffix;
+    }
+
+    public void setSuffix( String suffix )
+    {
+        this.suffix = suffix;
+    }
+
+    public Set getIndexedAttributes()
+    {
+        if ( indexedAttributes == null )
+        {
+            indexedAttributes = new HashSet();
+        }
+
+        return indexedAttributes;
+    }
+
+    public void setIndexedAttributes( Set indexedAttributes )
+    {
+        this.indexedAttributes = indexedAttributes;
+    }
+
+    public Attributes getContextAttributes()
+    {
+        if ( contextAttributes == null )
+        {
+            contextAttributes = new BasicAttributes();
+        }
+
+        return contextAttributes;
+    }
+
+    public void setContextAttributes( Attributes contextAttributes )
+    {
+        this.contextAttributes = contextAttributes;
+    }
+}
diff --git a/src/test/java/org/codehaus/redback/components/apacheds/ApacheDsTest.java b/src/test/java/org/codehaus/redback/components/apacheds/ApacheDsTest.java
new file mode 100644
index 0000000..014aee2
--- /dev/null
+++ b/src/test/java/org/codehaus/redback/components/apacheds/ApacheDsTest.java
@@ -0,0 +1,165 @@
+package org.codehaus.redback.components.apacheds;
+
+/*
+ * Copyright 2001-2007 The Codehaus.
+ *
+ * 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.
+ */
+
+import junit.framework.TestCase;
+import org.apache.directory.shared.ldap.util.AttributeUtils;
+import org.codehaus.redback.components.apacheds.ApacheDs;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+import javax.inject.Inject;
+import javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
+import javax.naming.directory.Attribute;
+import javax.naming.directory.Attributes;
+import javax.naming.directory.BasicAttribute;
+import javax.naming.directory.BasicAttributes;
+import javax.naming.directory.DirContext;
+import javax.naming.directory.InitialDirContext;
+import javax.naming.directory.SearchControls;
+import javax.naming.directory.SearchResult;
+import java.io.File;
+
+/**
+ * @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
+ * @author Olivier Lamy
+ * @version $Id$
+ */
+
+@RunWith( SpringJUnit4ClassRunner.class )
+@ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml", "classpath*:/spring-context.xml" } )
+public class ApacheDsTest
+    extends TestCase
+{
+    private String suffix = "dc=plexus,dc=codehaus,dc=org";
+
+    @Inject
+    private ApacheDs apacheDs;
+
+    protected void setUp()
+        throws Exception
+    {
+        super.setUp();
+
+
+                
+    }
+
+    @Test
+    public void testBasic()
+        throws Exception
+    {
+
+        apacheDs.setBasedir( new File( "./target/plexus-home" ) );
+        
+        apacheDs.addSimplePartition( "test", new String[]{"plexus", "codehaus", "org"} ).getSuffix();
+        apacheDs.startServer();
+
+        InitialDirContext context = apacheDs.getAdminContext();
+
+        String cn = "trygvis";
+        createUser( context, cn, createDn( cn ) );
+        assertExist( context, createDn( cn ), "cn", cn );
+
+        cn = "bolla";
+        createUser( context, cn, createDn( cn ) );
+        assertExist( context, createDn( cn ), "cn", cn );
+
+        SearchControls ctls = new SearchControls();
+
+        ctls.setDerefLinkFlag( true );
+        ctls.setSearchScope( SearchControls.ONELEVEL_SCOPE );
+        ctls.setReturningAttributes( new String[] { "*" } );
+
+        String filter = "(&(objectClass=inetOrgPerson)(cn=trygvis))";        
+        
+        NamingEnumeration<SearchResult> results = context.search( suffix, filter, ctls );
+       
+        assertTrue( "a result should have been returned", results.hasMoreElements() );
+        
+        SearchResult result = results.nextElement();
+        
+        Attributes attrs = result.getAttributes();
+        
+        System.out.println( AttributeUtils.toString( attrs ) );
+        
+        assertFalse( "should only have one result returned", results.hasMoreElements() );
+        
+        apacheDs.stopServer();
+
+
+
+        // ----------------------------------------------------------------------
+        // Start it again
+        // ----------------------------------------------------------------------
+
+        apacheDs.startServer();
+
+        context = apacheDs.getAdminContext();
+        
+        assertExist( context, createDn( "trygvis" ), "cn", "trygvis" );
+        context.unbind( createDn( "trygvis" ) );
+        assertExist( context, createDn( "bolla" ), "cn", "bolla" );
+        context.unbind( createDn( "bolla" ) );
+
+        apacheDs.stopServer();
+    }
+
+    private void createUser( DirContext context, String cn, String dn )
+        throws NamingException
+    {
+        Attributes attributes = new BasicAttributes();
+        BasicAttribute objectClass = new BasicAttribute( "objectClass" );
+        objectClass.add( "top" );
+        objectClass.add( "inetOrgPerson" );
+        attributes.put( objectClass );
+        attributes.put( "cn", cn );
+        attributes.put( "sn", cn );
+        context.createSubcontext( dn, attributes );
+    }
+
+    private String createDn( String cn )
+    {
+        return "cn=" + cn + "," + suffix;
+    }
+
+    private void assertExist( DirContext context, String dn, String attribute, String value )
+        throws NamingException
+    {
+    	SearchControls ctls = new SearchControls();
+
+        ctls.setDerefLinkFlag( true );
+        ctls.setSearchScope( SearchControls.ONELEVEL_SCOPE );
+        ctls.setReturningAttributes( new String[] { "*" } );
+    	   	
+    	BasicAttributes matchingAttributes = new BasicAttributes();
+    	matchingAttributes.put( attribute, value );
+    	
+    	NamingEnumeration<SearchResult> results = context.search( suffix, matchingAttributes );
+    	//NamingEnumeration<SearchResult> results = context.search( suffix, "(" + attribute + "=" + value + ")", ctls  );
+
+        assertTrue( results.hasMoreElements() );    	
+    	SearchResult result = results.nextElement();    	
+    	Attributes attrs = result.getAttributes();    	
+    	Attribute testAttr = attrs.get( attribute );    	
+    	assertEquals( value, testAttr.get() );
+      
+    }
+}
diff --git a/src/test/resources/spring-context.xml b/src/test/resources/spring-context.xml
new file mode 100755
index 0000000..934516d
--- /dev/null
+++ b/src/test/resources/spring-context.xml
@@ -0,0 +1,35 @@
+<?xml version="1.0"?>
+
+<!--
+  ~ 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.
+  -->
+<beans xmlns="http://www.springframework.org/schema/beans"
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xmlns:context="http://www.springframework.org/schema/context"
+       xsi:schemaLocation="http://www.springframework.org/schema/beans
+           http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
+           http://www.springframework.org/schema/context 
+           http://www.springframework.org/schema/context/spring-context-2.5.xsd">
+
+  <bean name="apacheDS" class="org.codehaus.redback.components.apacheds.DefaultApacheDs">
+    <property name="basedir" value="./target/apacheds"/>
+    <property name="port" value="10390"/>
+    <property name="enableNetworking" value="true"/>
+    <property name="password" value="secret"/>
+  </bean>
+</beans>
\ No newline at end of file