This is an automated email from the ASF dual-hosted git repository.
martin_s pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/archiva-components.git
The following commit(s) were added to refs/heads/master by this push:
new 91e0eea Adding spring-apacheds component
91e0eea is described below
commit 91e0eea6da1b55f3dc1e65b40ba7a73f33c86005
Author: Martin Stockhammer <[email protected]>
AuthorDate: Thu Oct 17 13:51:21 2019 +0200
Adding spring-apacheds component
---
pom.xml | 3 +
spring-apacheds/.gitignore | 10 +
spring-apacheds/pom.xml | 115 +++++++
.../redback/components/apacheds/ApacheDs.java | 87 ++++++
.../components/apacheds/DefaultApacheDs.java | 338 +++++++++++++++++++++
.../redback/components/apacheds/Partition.java | 90 ++++++
spring-apacheds/src/site/site.xml | 34 +++
.../redback/components/apacheds/ApacheDsTest.java | 172 +++++++++++
.../src/test/resources/spring-context.xml | 32 ++
9 files changed, 881 insertions(+)
diff --git a/pom.xml b/pom.xml
index 281081f..a91b450 100644
--- a/pom.xml
+++ b/pom.xml
@@ -46,6 +46,7 @@
<modules>
<module>expression-evaluator</module>
+ <module>spring-apacheds</module>
</modules>
<scm>
@@ -282,6 +283,8 @@
<exclude>**/.site-content/**</exclude>
<exclude>**/.repository/**</exclude>
<exclude>git-sparse-checkout-pattern</exclude>
+ <exclude>**/target/**</exclude>
+ <exclude>**/*.iml</exclude>
</excludes>
</configuration>
<executions>
diff --git a/spring-apacheds/.gitignore b/spring-apacheds/.gitignore
new file mode 100644
index 0000000..7b6772c
--- /dev/null
+++ b/spring-apacheds/.gitignore
@@ -0,0 +1,10 @@
+.idea/**
+.project
+.classpath
+.settings
+.java-version
+target
+.DS_Store
+.site-content
+out
+*.iml
diff --git a/spring-apacheds/pom.xml b/spring-apacheds/pom.xml
new file mode 100644
index 0000000..10124cf
--- /dev/null
+++ b/spring-apacheds/pom.xml
@@ -0,0 +1,115 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ 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.
+ -->
+<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.archiva.components</groupId>
+ <artifactId>archiva-components</artifactId>
+ <version>3.0-SNAPSHOT</version>
+ </parent>
+
+ <version>3.0-SNAPSHOT</version>
+ <artifactId>archiva-components-spring-apacheds</artifactId>
+ <name>Archiva Components :: Spring Apache DS LDAP Tools</name>
+
+ <properties>
+ <apacheds.version>1.5.1</apacheds.version>
+ <site.staging.base>${project.basedir}/..</site.staging.base>
+ </properties>
+ <scm>
+ <url>${scmBrowseUrl}</url>
+ </scm>
+
+
+ <url>${webUrl}/${project.artifactId}</url>
+
+ <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.apache.logging.log4j</groupId>
+ <artifactId>log4j-jcl</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+</project>
diff --git
a/spring-apacheds/src/main/java/org/apache/archiva/redback/components/apacheds/ApacheDs.java
b/spring-apacheds/src/main/java/org/apache/archiva/redback/components/apacheds/ApacheDs.java
new file mode 100644
index 0000000..3b53c3d
--- /dev/null
+++
b/spring-apacheds/src/main/java/org/apache/archiva/redback/components/apacheds/ApacheDs.java
@@ -0,0 +1,87 @@
+package org.apache.archiva.redback.components.apacheds;
+
+/*
+ * 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.
+ */
+
+import javax.naming.NamingException;
+import javax.naming.directory.Attributes;
+import javax.naming.directory.InitialDirContext;
+import java.io.File;
+import java.util.Set;
+
+/**
+ * @author <a href="mailto:[email protected]">Trygve Laugstøl</a>
+ *
+ */
+public interface ApacheDs
+{
+
+ // ----------------------------------------------------------------------
+ // 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/spring-apacheds/src/main/java/org/apache/archiva/redback/components/apacheds/DefaultApacheDs.java
b/spring-apacheds/src/main/java/org/apache/archiva/redback/components/apacheds/DefaultApacheDs.java
new file mode 100644
index 0000000..111ca7a
--- /dev/null
+++
b/spring-apacheds/src/main/java/org/apache/archiva/redback/components/apacheds/DefaultApacheDs.java
@@ -0,0 +1,338 @@
+package org.apache.archiva.redback.components.apacheds;
+
+/*
+ * 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.
+ */
+
+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:[email protected]">Trygve Laugstøl</a>
+ * @author Olivier Lamy
+ *
+ */
+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/spring-apacheds/src/main/java/org/apache/archiva/redback/components/apacheds/Partition.java
b/spring-apacheds/src/main/java/org/apache/archiva/redback/components/apacheds/Partition.java
new file mode 100644
index 0000000..d46a630
--- /dev/null
+++
b/spring-apacheds/src/main/java/org/apache/archiva/redback/components/apacheds/Partition.java
@@ -0,0 +1,90 @@
+package org.apache.archiva.redback.components.apacheds;
+
+/*
+ * 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.
+ */
+
+import javax.naming.directory.Attributes;
+import javax.naming.directory.BasicAttributes;
+import java.util.Set;
+import java.util.HashSet;
+
+/**
+ * @author <a href="mailto:[email protected]">Trygve Laugstøl</a>
+ *
+ */
+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/spring-apacheds/src/site/site.xml
b/spring-apacheds/src/site/site.xml
new file mode 100644
index 0000000..26378ff
--- /dev/null
+++ b/spring-apacheds/src/site/site.xml
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!--
+ ~ 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.
+ -->
+
+<project name="Spring Apacheds Component" >
+
+ <publishDate format="yyyy-MM-dd" position="none" />
+
+ <body>
+ <menu ref="modules" />
+ <menu ref="reports" />
+ <menu ref="ASF" />
+ <breadcrumbs>
+ <item name="Archiva Components" href="../index.html" />
+ <item name="Spring ApacheDs" href="index.html" />
+ </breadcrumbs>
+ </body>
+</project>
diff --git
a/spring-apacheds/src/test/java/org/apache/archiva/redback/components/apacheds/ApacheDsTest.java
b/spring-apacheds/src/test/java/org/apache/archiva/redback/components/apacheds/ApacheDsTest.java
new file mode 100644
index 0000000..7293b87
--- /dev/null
+++
b/spring-apacheds/src/test/java/org/apache/archiva/redback/components/apacheds/ApacheDsTest.java
@@ -0,0 +1,172 @@
+package org.apache.archiva.redback.components.apacheds;
+
+/*
+ * 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.
+ */
+
+import junit.framework.TestCase;
+import org.apache.directory.shared.ldap.util.AttributeUtils;
+import org.apache.archiva.redback.components.apacheds.ApacheDs;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+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:[email protected]">Trygve Laugstøl</a>
+ * @author Olivier Lamy
+ *
+ */
+
+@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;
+
+ private Logger logger = LoggerFactory.getLogger( getClass() );
+
+ 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();
+
+ logger.info("Attributes {}", 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/spring-apacheds/src/test/resources/spring-context.xml
b/spring-apacheds/src/test/resources/spring-context.xml
new file mode 100755
index 0000000..8881f24
--- /dev/null
+++ b/spring-apacheds/src/test/resources/spring-context.xml
@@ -0,0 +1,32 @@
+<?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"
+ xsi:schemaLocation="http://www.springframework.org/schema/beans
+ http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
+
+ <bean name="apacheDS"
class="org.apache.archiva.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