You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2010/01/22 17:41:55 UTC
svn commit: r902161 [3/3] - in /directory/clients/ldap/trunk: ./
ldap-client-api/ ldap-client-api/src/ ldap-client-api/src/main/
ldap-client-api/src/main/java/ ldap-client-api/src/main/java/org/
ldap-client-api/src/main/java/org/apache/ ldap-client-api...
Added: directory/clients/ldap/trunk/ldap-client-api/src/main/java/org/apache/directory/shared/ldap/client/api/LdapConnectionConfig.java
URL: http://svn.apache.org/viewvc/directory/clients/ldap/trunk/ldap-client-api/src/main/java/org/apache/directory/shared/ldap/client/api/LdapConnectionConfig.java?rev=902161&view=auto
==============================================================================
--- directory/clients/ldap/trunk/ldap-client-api/src/main/java/org/apache/directory/shared/ldap/client/api/LdapConnectionConfig.java (added)
+++ directory/clients/ldap/trunk/ldap-client-api/src/main/java/org/apache/directory/shared/ldap/client/api/LdapConnectionConfig.java Fri Jan 22 16:41:54 2010
@@ -0,0 +1,221 @@
+/*
+ * 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.shared.ldap.client.api;
+
+import java.security.SecureRandom;
+
+import javax.net.ssl.KeyManager;
+import javax.net.ssl.TrustManager;
+
+
+/**
+ * A class to hold the configuration for creating an LdapConnection.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class LdapConnectionConfig
+{
+
+ /** Define the default ports for LDAP and LDAPS */
+ public static final int DEFAULT_LDAP_PORT = 389;
+
+ public static final int DEFAULT_LDAPS_PORT = 636;
+
+ /** The default host : localhost */
+ public static final String DEFAULT_LDAP_HOST = "127.0.0.1";
+
+ /** The LDAP version */
+ public static int LDAP_V3 = 3;
+
+ /** The default timeout for operation : 30 seconds */
+ public static final long DEFAULT_TIMEOUT = 30000L;
+
+ /** the default protocol used for creating SSL context */
+ public static final String DEFAULT_SSL_PROTOCOL = "TLS";
+
+ // --- private members ----
+
+ /** A flag indicating if we are using SSL or not, default value is false */
+ private boolean useSsl = false;
+
+ /** The selected LDAP port */
+ private int ldapPort;
+
+ /** the remote LDAP host */
+ private String ldapHost;
+
+ /** a valid DN to authenticate the user */
+ private String name;
+
+ /** user's credentials ( current implementation supports password only); it must be a non-null value */
+ private byte[] credentials;
+
+ /** an array of key managers, if set, will be used while initializing the SSL context */
+ private KeyManager[] keyManagers;
+
+ /** an instance of SecureRandom, if set, will be used while initializing the SSL context */
+ private SecureRandom secureRandom;
+
+ /** an array of certificate trust managers, if set, will be used while initializing the SSL context */
+ private TrustManager[] trustManagers;
+
+ /** name of the protocol used for creating SSL context, default value is "TLS" */
+ private String sslProtocol = DEFAULT_SSL_PROTOCOL;
+
+ public boolean isUseSsl()
+ {
+ return useSsl;
+ }
+
+
+ public void setUseSsl( boolean useSsl )
+ {
+ this.useSsl = useSsl;
+ }
+
+
+ public int getLdapPort()
+ {
+ return ldapPort;
+ }
+
+
+ public void setLdapPort( int ldapPort )
+ {
+ this.ldapPort = ldapPort;
+ }
+
+
+ public String getLdapHost()
+ {
+ return ldapHost;
+ }
+
+
+ public void setLdapHost( String ldapHost )
+ {
+ this.ldapHost = ldapHost;
+ }
+
+
+ public String getName()
+ {
+ return name;
+ }
+
+
+ public void setName( String name )
+ {
+ this.name = name;
+ }
+
+
+ public byte[] getCredentials()
+ {
+ return credentials;
+ }
+
+
+ public void setCredentials( byte[] credentials )
+ {
+ this.credentials = credentials;
+ }
+
+
+ public int getDefaultLdapPort()
+ {
+ return DEFAULT_LDAP_PORT;
+ }
+
+
+ public int getDefaultLdapsPort()
+ {
+ return DEFAULT_LDAPS_PORT;
+ }
+
+
+ public String getDefaultLdapHost()
+ {
+ return DEFAULT_LDAP_HOST;
+ }
+
+
+ public long getDefaultTimeout()
+ {
+ return DEFAULT_TIMEOUT;
+ }
+
+
+ public int getSupportedLdapVersion()
+ {
+ return LDAP_V3;
+ }
+
+
+ public TrustManager[] getTrustManagers()
+ {
+ return trustManagers;
+ }
+
+
+ public void setTrustManagers( TrustManager[] trustManagers )
+ {
+ this.trustManagers = trustManagers;
+ }
+
+
+ public String getSslProtocol()
+ {
+ return sslProtocol;
+ }
+
+
+ public void setSslProtocol( String sslProtocol )
+ {
+ this.sslProtocol = sslProtocol;
+ }
+
+
+ public KeyManager[] getKeyManagers()
+ {
+ return keyManagers;
+ }
+
+
+ public void setKeyManagers( KeyManager[] keyManagers )
+ {
+ this.keyManagers = keyManagers;
+ }
+
+
+ public SecureRandom getSecureRandom()
+ {
+ return secureRandom;
+ }
+
+
+ public void setSecureRandom( SecureRandom secureRandom )
+ {
+ this.secureRandom = secureRandom;
+ }
+
+}
Added: directory/clients/ldap/trunk/ldap-client-api/src/main/java/org/apache/directory/shared/ldap/client/api/LdapConnectionPool.java
URL: http://svn.apache.org/viewvc/directory/clients/ldap/trunk/ldap-client-api/src/main/java/org/apache/directory/shared/ldap/client/api/LdapConnectionPool.java?rev=902161&view=auto
==============================================================================
--- directory/clients/ldap/trunk/ldap-client-api/src/main/java/org/apache/directory/shared/ldap/client/api/LdapConnectionPool.java (added)
+++ directory/clients/ldap/trunk/ldap-client-api/src/main/java/org/apache/directory/shared/ldap/client/api/LdapConnectionPool.java Fri Jan 22 16:41:54 2010
@@ -0,0 +1,88 @@
+/*
+ * 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.shared.ldap.client.api;
+
+
+import org.apache.commons.pool.impl.GenericObjectPool;
+
+
+/**
+ * A pool implementation for LdapConnection objects.
+ *
+ * This class is just a wrapper around the commons GenericObjectPool, and has
+ * a more meaningful name to represent the pool type
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class LdapConnectionPool extends GenericObjectPool
+{
+ /** the LdapConnection factory*/
+ private PoolableLdapConnectionFactory factory;
+
+
+ public LdapConnectionPool()
+ {
+ super();
+ }
+
+
+ public LdapConnectionPool( PoolableLdapConnectionFactory factory )
+ {
+ super( factory );
+ this.factory = factory;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void setFactory( PoolableLdapConnectionFactory factory )
+ {
+ this.factory = factory;
+ super.setFactory( factory );
+ }
+
+
+ /**
+ * gives a LdapConnection fetched from the pool
+ *
+ * @return an LdapConnection object from pool
+ * @throws Exception
+ */
+ public LdapConnection getConnection() throws Exception
+ {
+ return ( LdapConnection ) super.borrowObject();
+ }
+
+
+ /**
+ * places the given LdapConnection back in the pool
+ *
+ * @param connection the LdapConnection to be released
+ * @throws Exception
+ */
+ public void releaseConnection( LdapConnection connection ) throws Exception
+ {
+ super.returnObject( connection );
+ }
+
+}
Added: directory/clients/ldap/trunk/ldap-client-api/src/main/java/org/apache/directory/shared/ldap/client/api/PoolableLdapConnectionFactory.java
URL: http://svn.apache.org/viewvc/directory/clients/ldap/trunk/ldap-client-api/src/main/java/org/apache/directory/shared/ldap/client/api/PoolableLdapConnectionFactory.java?rev=902161&view=auto
==============================================================================
--- directory/clients/ldap/trunk/ldap-client-api/src/main/java/org/apache/directory/shared/ldap/client/api/PoolableLdapConnectionFactory.java (added)
+++ directory/clients/ldap/trunk/ldap-client-api/src/main/java/org/apache/directory/shared/ldap/client/api/PoolableLdapConnectionFactory.java Fri Jan 22 16:41:54 2010
@@ -0,0 +1,111 @@
+/*
+ * 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.shared.ldap.client.api;
+
+
+import org.apache.commons.pool.PoolableObjectFactory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * A factory for creating LdapConnection objects managed by LdapConnectionPool.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class PoolableLdapConnectionFactory implements PoolableObjectFactory
+{
+
+ /** configuration object for the connection */
+ private LdapConnectionConfig config;
+
+ private static final Logger LOG = LoggerFactory.getLogger( PoolableLdapConnectionFactory.class );
+
+
+ /**
+ *
+ * Creates a new instance of PoolableLdapConnectionFactory for the
+ * server running on localhost at the port 10389
+ *
+ * @param config the configuration for creating LdapConnections
+ */
+ public PoolableLdapConnectionFactory( LdapConnectionConfig config )
+ {
+ this.config = config;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void activateObject( Object obj ) throws Exception
+ {
+ LOG.debug( "activating {}", obj );
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void destroyObject( Object obj ) throws Exception
+ {
+ LOG.debug( "destroying {}", obj );
+ LdapConnection connection = ( LdapConnection ) obj;
+ connection.unBind();
+ connection.close();
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public Object makeObject() throws Exception
+ {
+ LOG.debug( "creating a LDAP connection" );
+
+ LdapConnection connection = new LdapConnection( config );
+ connection.bind( config.getName(), config.getCredentials() );
+ return connection;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void passivateObject( Object obj ) throws Exception
+ {
+ LOG.debug( "passivating {}", obj );
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean validateObject( Object obj )
+ {
+ LOG.debug( "validating {}", obj );
+
+ LdapConnection connection = ( LdapConnection ) obj;
+ return connection.isSessionValid();
+ }
+
+}
Added: directory/clients/ldap/trunk/ldap-client-api/src/test/resources/log4j.properties
URL: http://svn.apache.org/viewvc/directory/clients/ldap/trunk/ldap-client-api/src/test/resources/log4j.properties?rev=902161&view=auto
==============================================================================
--- directory/clients/ldap/trunk/ldap-client-api/src/test/resources/log4j.properties (added)
+++ directory/clients/ldap/trunk/ldap-client-api/src/test/resources/log4j.properties Fri Jan 22 16:41:54 2010
@@ -0,0 +1,24 @@
+#############################################################################
+# 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.
+#############################################################################
+log4j.rootCategory=OFF, stdout
+
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender
+log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
+log4j.appender.stdout.layout.ConversionPattern=[%d{HH:mm:ss}] %p [%c] - %m%n
+
+#log4j.logger.org.apache.directory.shared.client.api=DEBUG
+log4j.logger.org.apache.directory.shared.asn1.ber=ERROR
\ No newline at end of file
Propchange: directory/clients/ldap/trunk/ldap-client-test/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Fri Jan 22 16:41:54 2010
@@ -0,0 +1,4 @@
+target
+.classpath
+.project
+.settings
Added: directory/clients/ldap/trunk/ldap-client-test/pom.xml
URL: http://svn.apache.org/viewvc/directory/clients/ldap/trunk/ldap-client-test/pom.xml?rev=902161&view=auto
==============================================================================
--- directory/clients/ldap/trunk/ldap-client-test/pom.xml (added)
+++ directory/clients/ldap/trunk/ldap-client-test/pom.xml Fri Jan 22 16:41:54 2010
@@ -0,0 +1,83 @@
+<?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.directory.client.ldap</groupId>
+ <artifactId>ldap-client</artifactId>
+ <version>0.1-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>ldap-client-test</artifactId>
+ <name>Apache Directory Shared LDAP Client API test</name>
+ <inceptionYear>2009</inceptionYear>
+
+ <issueManagement>
+ <system>jira</system>
+ <url>http://issues.apache.org/jira/browse/DIRAPI</url>
+ </issueManagement>
+
+ <description>
+ Client LDAP API Tests
+ </description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.directory.shared</groupId>
+ <artifactId>shared-all</artifactId>
+ <version>${org.apache.directory.shared.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.directory.server</groupId>
+ <artifactId>apacheds-all</artifactId>
+ <version>${org.apache.directory.server.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.mina</groupId>
+ <artifactId>mina-core</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <excludes>
+ <exclude>**/Abstract*</exclude>
+ <exclude>**/*RegressionTest*</exclude>
+ </excludes>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
+
Added: directory/clients/ldap/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/LdapConnectionTest.java
URL: http://svn.apache.org/viewvc/directory/clients/ldap/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/LdapConnectionTest.java?rev=902161&view=auto
==============================================================================
--- directory/clients/ldap/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/LdapConnectionTest.java (added)
+++ directory/clients/ldap/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/LdapConnectionTest.java Fri Jan 22 16:41:54 2010
@@ -0,0 +1,110 @@
+/*
+ * 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.shared.client.api;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
+
+import java.io.IOException;
+import java.util.List;
+
+import org.apache.directory.server.annotations.CreateLdapServer;
+import org.apache.directory.server.annotations.CreateTransport;
+import org.apache.directory.server.core.integ.AbstractLdapTestUnit;
+import org.apache.directory.server.core.integ.FrameworkRunner;
+import org.apache.directory.shared.ldap.client.api.LdapConnection;
+import org.apache.directory.shared.ldap.client.api.exception.LdapException;
+import org.apache.directory.shared.ldap.client.api.messages.BindResponse;
+import org.apache.directory.shared.ldap.name.LdapDN;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+/**
+ * Test the LdapConnection class
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+@RunWith ( FrameworkRunner.class )
+@CreateLdapServer (
+ transports =
+ {
+ @CreateTransport( protocol = "LDAP" ),
+ @CreateTransport( protocol = "LDAPS" )
+ })
+public class LdapConnectionTest extends AbstractLdapTestUnit
+{
+
+ /**
+ * Test a successful bind request
+ *
+ * @throws IOException
+ */
+ @Test
+ public void testBindRequest() throws Exception
+ {
+ LdapConnection connection = new LdapConnection( "localhost", ldapServer.getPort() );
+
+ try
+ {
+ BindResponse bindResponse = connection.bind( "uid=admin,ou=system", "secret" );
+
+ assertNotNull( bindResponse );
+
+ //connection.unBind();
+ }
+ catch ( LdapException le )
+ {
+ fail();
+ }
+ catch ( IOException ioe )
+ {
+ fail();
+ }
+ finally
+ {
+ try
+ {
+ connection.close();
+ }
+ catch( IOException ioe )
+ {
+ fail();
+ }
+ }
+ }
+
+
+ @Test
+ @Ignore
+ public void testGetSupportedControls() throws Exception
+ {
+ LdapConnection connection = new LdapConnection( "localhost", ldapServer.getPort() );
+
+ LdapDN dn = new LdapDN( "uid=admin,ou=system" );
+ connection.bind( dn.getName(), "secret" );
+
+ List<String> controlList = connection.getSupportedConrols();
+ assertNotNull( controlList );
+ assertFalse( controlList.isEmpty() );
+ }
+}
Added: directory/clients/ldap/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/LdapSSLConnectionTest.java
URL: http://svn.apache.org/viewvc/directory/clients/ldap/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/LdapSSLConnectionTest.java?rev=902161&view=auto
==============================================================================
--- directory/clients/ldap/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/LdapSSLConnectionTest.java (added)
+++ directory/clients/ldap/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/LdapSSLConnectionTest.java Fri Jan 22 16:41:54 2010
@@ -0,0 +1,165 @@
+/*
+ * 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.shared.client.api;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
+
+import java.io.IOException;
+import java.security.cert.CertificateException;
+import java.security.cert.X509Certificate;
+import java.util.List;
+
+import javax.net.ssl.TrustManager;
+import javax.net.ssl.X509TrustManager;
+
+import org.apache.directory.server.annotations.CreateLdapServer;
+import org.apache.directory.server.annotations.CreateTransport;
+import org.apache.directory.server.annotations.SaslMechanism;
+import org.apache.directory.server.core.integ.AbstractLdapTestUnit;
+import org.apache.directory.server.core.integ.FrameworkRunner;
+import org.apache.directory.server.ldap.handlers.bind.cramMD5.CramMd5MechanismHandler;
+import org.apache.directory.server.ldap.handlers.bind.digestMD5.DigestMd5MechanismHandler;
+import org.apache.directory.server.ldap.handlers.bind.gssapi.GssapiMechanismHandler;
+import org.apache.directory.server.ldap.handlers.bind.ntlm.NtlmMechanismHandler;
+import org.apache.directory.server.ldap.handlers.bind.plain.PlainMechanismHandler;
+import org.apache.directory.server.ldap.handlers.extended.StoredProcedureExtendedOperationHandler;
+import org.apache.directory.shared.ldap.client.api.LdapConnection;
+import org.apache.directory.shared.ldap.client.api.LdapConnectionConfig;
+import org.apache.directory.shared.ldap.client.api.messages.BindResponse;
+import org.apache.directory.shared.ldap.constants.SupportedSaslMechanisms;
+import org.apache.directory.shared.ldap.name.LdapDN;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+/**
+ * Test the LdapConnection class with SSL enabled
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+@RunWith ( FrameworkRunner.class )
+@CreateLdapServer (
+ transports =
+ {
+ @CreateTransport( protocol = "LDAP" ),
+ @CreateTransport( protocol = "LDAPS" )
+ },
+ saslHost="localhost",
+ saslMechanisms =
+ {
+ @SaslMechanism( name=SupportedSaslMechanisms.PLAIN, implClass=PlainMechanismHandler.class ),
+ @SaslMechanism( name=SupportedSaslMechanisms.CRAM_MD5, implClass=CramMd5MechanismHandler.class),
+ @SaslMechanism( name=SupportedSaslMechanisms.DIGEST_MD5, implClass=DigestMd5MechanismHandler.class),
+ @SaslMechanism( name=SupportedSaslMechanisms.GSSAPI, implClass=GssapiMechanismHandler.class),
+ @SaslMechanism( name=SupportedSaslMechanisms.NTLM, implClass=NtlmMechanismHandler.class),
+ @SaslMechanism( name=SupportedSaslMechanisms.GSS_SPNEGO, implClass=NtlmMechanismHandler.class)
+ },
+ extendedOpHandlers =
+ {
+ StoredProcedureExtendedOperationHandler.class
+ })
+public class LdapSSLConnectionTest extends AbstractLdapTestUnit
+{
+ private LdapConnectionConfig config;
+
+
+ @Before
+ public void setup()
+ {
+ X509TrustManager X509 = new X509TrustManager()
+ {
+ public void checkClientTrusted( X509Certificate[] x509Certificates, String s ) throws CertificateException
+ {
+ }
+
+ public void checkServerTrusted( X509Certificate[] x509Certificates, String s ) throws CertificateException
+ {
+ }
+
+ public X509Certificate[] getAcceptedIssuers()
+ {
+ return new X509Certificate[0];
+ }
+ };
+
+ config = new LdapConnectionConfig();
+ config.setLdapHost( "localhost" );
+ config.setUseSsl( true );
+ config.setLdapPort( ldapServer.getPortSSL() );
+ config.setTrustManagers( new TrustManager[]{ X509 } );
+ }
+
+
+ /**
+ * Test a successful bind request
+ *
+ * @throws IOException
+ */
+ @Test
+ public void testBindRequest()
+ {
+ LdapConnection connection = null;
+ try
+ {
+ connection = new LdapConnection( config );
+ BindResponse bindResponse = connection.bind( "uid=admin,ou=system", "secret" );
+
+ assertNotNull( bindResponse );
+
+ connection.unBind();
+ }
+ catch ( Exception le )
+ {
+ le.printStackTrace();
+ fail();
+ }
+ finally
+ {
+ try
+ {
+ if( connection != null )
+ {
+ connection.close();
+ }
+ }
+ catch( IOException ioe )
+ {
+ fail();
+ }
+ }
+ }
+
+
+ @Test
+ public void testGetSupportedControls() throws Exception
+ {
+ LdapConnection connection = new LdapConnection( config );
+
+ LdapDN dn = new LdapDN( "uid=admin,ou=system" );
+ connection.bind( dn.getName(), "secret" );
+
+ List<String> controlList = connection.getSupportedConrols();
+ assertNotNull( controlList );
+ assertFalse( controlList.isEmpty() );
+ }
+}
Added: directory/clients/ldap/trunk/ldap-client-test/src/test/resources/log4j.properties
URL: http://svn.apache.org/viewvc/directory/clients/ldap/trunk/ldap-client-test/src/test/resources/log4j.properties?rev=902161&view=auto
==============================================================================
--- directory/clients/ldap/trunk/ldap-client-test/src/test/resources/log4j.properties (added)
+++ directory/clients/ldap/trunk/ldap-client-test/src/test/resources/log4j.properties Fri Jan 22 16:41:54 2010
@@ -0,0 +1,24 @@
+#############################################################################
+# 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.
+#############################################################################
+log4j.rootCategory=OFF, stdout
+
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender
+log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
+log4j.appender.stdout.layout.ConversionPattern=[%d{HH:mm:ss}] %p [%c] - %m%n
+
+#log4j.logger.org.apache.directory.shared.client.api=DEBUG
+log4j.logger.org.apache.directory.shared.asn1.ber=ERROR
\ No newline at end of file
Added: directory/clients/ldap/trunk/pom.xml
URL: http://svn.apache.org/viewvc/directory/clients/ldap/trunk/pom.xml?rev=902161&view=auto
==============================================================================
--- directory/clients/ldap/trunk/pom.xml (added)
+++ directory/clients/ldap/trunk/pom.xml Fri Jan 22 16:41:54 2010
@@ -0,0 +1,114 @@
+<?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.directory.project</groupId>
+ <artifactId>project</artifactId>
+ <version>16</version>
+ </parent>
+
+ <groupId>org.apache.directory.client.ldap</groupId>
+ <artifactId>ldap-client</artifactId>
+ <version>0.1-SNAPSHOT</version>
+ <name>Apache Directory LDAP Client</name>
+ <inceptionYear>2009</inceptionYear>
+ <packaging>pom</packaging>
+
+ <properties>
+ <projectName>Apache Directory LDAP API</projectName>
+ <distMgmtSiteUrl>scpexe://people.apache.org/www/directory.apache.org/apacheds/gen-docs/${version}/</distMgmtSiteUrl>
+
+ <!-- Set versions for depending projects -->
+ <org.apache.directory.shared.version>0.9.18-SNAPSHOT</org.apache.directory.shared.version>
+ <org.apache.directory.server.version>1.5.6-SNAPSHOT</org.apache.directory.server.version>
+ <commons.pool.version>1.5.4</commons.pool.version>
+ <mina.core.version>2.0.0-RC1</mina.core.version>
+ <junit.version>4.7</junit.version>
+ <skin.version>1.0.1</skin.version>
+ </properties>
+
+ <url>http://directory.apache.org/apacheds/1.5</url>
+
+ <issueManagement>
+ <system>jira</system>
+ <url>http://issues.apache.org/jira/browse/DIRAPI</url>
+ </issueManagement>
+
+ <description>
+ Client LDAP API
+ </description>
+
+ <dependencyManagement>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.directory.shared</groupId>
+ <artifactId>shared-ldap</artifactId>
+ <version>${org.apache.directory.shared.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.directory.shared</groupId>
+ <artifactId>shared-cursor</artifactId>
+ <version>${org.apache.directory.shared.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>commons-pool</groupId>
+ <artifactId>commons-pool</artifactId>
+ <version>${commons.pool.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>${junit.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.mina</groupId>
+ <artifactId>mina-core</artifactId>
+ <version>${mina.core.version}</version>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
+
+ <modules>
+ <module>ldap-client-api</module>
+ <module>ldap-client-test</module>
+ </modules>
+
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <excludes>
+ <exclude>**/Abstract*</exclude>
+ <exclude>**/*RegressionTest*</exclude>
+ </excludes>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
+