directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kayyag...@apache.org
Subject svn commit: r791534 - in /directory/shared/trunk/client-api/src/main/java/org/apache/directory/shared/ldap/client/api: LdapConnection.java LdapConnectionConfig.java PoolableLdapConnectionFactory.java
Date Mon, 06 Jul 2009 16:26:30 GMT
Author: kayyagari
Date: Mon Jul  6 16:26:30 2009
New Revision: 791534

URL: http://svn.apache.org/viewvc?rev=791534&view=rev
Log:
o added a class for holding the configuratio of LdapConnection
o updated LdapConnection and connection pool factory classes to use this

Added:
    directory/shared/trunk/client-api/src/main/java/org/apache/directory/shared/ldap/client/api/LdapConnectionConfig.java
Modified:
    directory/shared/trunk/client-api/src/main/java/org/apache/directory/shared/ldap/client/api/LdapConnection.java
    directory/shared/trunk/client-api/src/main/java/org/apache/directory/shared/ldap/client/api/PoolableLdapConnectionFactory.java

Modified: directory/shared/trunk/client-api/src/main/java/org/apache/directory/shared/ldap/client/api/LdapConnection.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/client-api/src/main/java/org/apache/directory/shared/ldap/client/api/LdapConnection.java?rev=791534&r1=791533&r2=791534&view=diff
==============================================================================
--- directory/shared/trunk/client-api/src/main/java/org/apache/directory/shared/ldap/client/api/LdapConnection.java
(original)
+++ directory/shared/trunk/client-api/src/main/java/org/apache/directory/shared/ldap/client/api/LdapConnection.java
Mon Jul  6 16:26:30 2009
@@ -127,8 +127,8 @@
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-// TODO : implement a pool
-// TODO : handle the MessageId for an abandonRequest
+// TODO : handle the MessageId for an abandonRequest adding Futures to async methods and
+//        check how to handle the synchronous methods for abandoning
 // TODO : return the created request, instead of an LdapResponse ( partly completed )
 
 /**
@@ -147,32 +147,13 @@
     /** logger for reporting errors that might not be handled properly upstream */
     private static final Logger LOG = LoggerFactory.getLogger( LdapConnection.class );
 
-    /** Define the default ports for LDAP and LDAPS */
-    private static final int DEFAULT_LDAP_PORT = 389; 
-    private static final int DEFAULT_LDAPS_PORT = 636;
-    
-    /** The default host : localhost */
-    private static final String DEFAULT_LDAP_HOST = "127.0.0.1";
-    
-    /** The LDAP version */
-    private static int LDAP_V3 = 3;
-    
     private static final String LDAP_RESPONSE = "LdapReponse";
     
-    /** A flag indicating if we are using SSL or not */
-    private boolean useSsl = false;
-    
-    /** The default timeout for operation : 30 seconds */
-    private static final long DEFAULT_TIMEOUT = 30000L;
-    
     /** The timeout used for response we are waiting for */ 
-    private long timeOut = DEFAULT_TIMEOUT;
-    
-    /** The selected LDAP port */
-    private int ldapPort;
+    private long timeOut = LdapConnectionConfig.DEFAULT_TIMEOUT;
     
-    /** the remote LDAP host */
-    private String ldapHost;
+    /** configuration object for the connection */
+    private LdapConnectionConfig config = new LdapConnectionConfig();
     
     /** The connector open with the remote server */
     private IoConnector connector;
@@ -465,15 +446,27 @@
      */
     public LdapConnection()
     {
-        useSsl = false;
-        ldapPort = DEFAULT_LDAP_PORT;
-        ldapHost = DEFAULT_LDAP_HOST;
+        config.setUseSsl( false );
+        config.setLdapPort( config.getDefaultLdapPort() );
+        config.setLdapHost( config.getDefaultLdapHost() );
         messageId = new AtomicInteger();
         operationMutex = new Semaphore(1);
     }
     
     
     /**
+     * 
+     * Creates a new instance of LdapConnection with the given connection configuration.
+     *
+     * @param config the configuration of the LdapConnection
+     */
+    public LdapConnection( LdapConnectionConfig config )
+    {
+        this.config = config;
+    }
+    
+    
+    /**
      * Create a new instance of a LdapConnection on localhost,
      * port 389 if the SSL flag is off, or 636 otherwise.
      * 
@@ -481,9 +474,9 @@
      */
     public LdapConnection( boolean useSsl )
     {
-        this.useSsl = useSsl;
-        ldapPort = ( useSsl ? DEFAULT_LDAPS_PORT : DEFAULT_LDAP_PORT );
-        ldapHost = DEFAULT_LDAP_HOST;
+        config.setUseSsl( useSsl );
+        config.setLdapPort( useSsl ? config.getDefaultLdapsPort() : config.getDefaultLdapPort()
);
+        config.setLdapHost( config.getDefaultLdapHost() );
         messageId = new AtomicInteger();
         operationMutex = new Semaphore(1);
     }
@@ -497,9 +490,9 @@
      */
     public LdapConnection( String server )
     {
-        useSsl = false;
-        ldapPort = DEFAULT_LDAP_PORT;
-        ldapHost = server;
+        config.setUseSsl( false );
+        config.setLdapPort( config.getDefaultLdapPort() );
+        config.setLdapHost( server );
         messageId = new AtomicInteger();
         operationMutex = new Semaphore(1);
     }
@@ -515,9 +508,9 @@
      */
     public LdapConnection( String server, boolean useSsl )
     {
-        this.useSsl = useSsl;
-        ldapPort = ( useSsl ? DEFAULT_LDAPS_PORT : DEFAULT_LDAP_PORT );
-        ldapHost = DEFAULT_LDAP_HOST;
+        config.setUseSsl( useSsl );
+        config.setLdapPort( useSsl ? config.getDefaultLdapsPort() : config.getDefaultLdapPort()
);
+        config.setLdapHost( server );
         messageId = new AtomicInteger();
         operationMutex = new Semaphore(1);
     }
@@ -532,11 +525,7 @@
      */
     public LdapConnection( String server, int port )
     {
-        useSsl = false;
-        ldapPort = port;
-        ldapHost = server;
-        messageId = new AtomicInteger();
-        operationMutex = new Semaphore(1);
+        this( server, port, false );
     }
     
     
@@ -551,9 +540,9 @@
      */
     public LdapConnection( String server, int port, boolean useSsl )
     {
-        this.useSsl = useSsl;
-        ldapPort = port;
-        ldapHost = server;
+        config.setUseSsl( useSsl );
+        config.setLdapPort( port );
+        config.setLdapHost( server );
         messageId = new AtomicInteger();
         operationMutex = new Semaphore(1);
     }
@@ -583,7 +572,7 @@
             connector.getFilterChain().addLast( "ldapCodec", ldapProtocolFilter );
     
             // If we use SSL, we have to add the SslFilter to the chain
-            if ( useSsl ) 
+            if ( config.isUseSsl() ) 
             {
                 SSLContext sslContext = null; // BogusSslContextFactory.getInstance( false
);
                 SslFilter sslFilter = new SslFilter( sslContext );
@@ -596,7 +585,7 @@
         }
         
         // Build the connection address
-        SocketAddress address = new InetSocketAddress( ldapHost , ldapPort );
+        SocketAddress address = new InetSocketAddress( config.getLdapHost() , config.getLdapPort()
);
         
         // And create the connection future
         ConnectFuture connectionFuture = connector.connect( address );
@@ -1020,7 +1009,7 @@
         BindRequestCodec request =  new BindRequestCodec();
         
         // Set the version
-        request.setVersion( LDAP_V3 );
+        request.setVersion( LdapConnectionConfig.LDAP_V3 );
         
         // Set the name
         try
@@ -2177,4 +2166,16 @@
             }
         }
     }
+
+
+    /**
+     * gives the configuration information of the connection
+     * 
+     * @return the configuration of the connection
+     */
+    public LdapConnectionConfig getConfig()
+    {
+        return config;
+    }
+    
 }

Added: directory/shared/trunk/client-api/src/main/java/org/apache/directory/shared/ldap/client/api/LdapConnectionConfig.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/client-api/src/main/java/org/apache/directory/shared/ldap/client/api/LdapConnectionConfig.java?rev=791534&view=auto
==============================================================================
--- directory/shared/trunk/client-api/src/main/java/org/apache/directory/shared/ldap/client/api/LdapConnectionConfig.java
(added)
+++ directory/shared/trunk/client-api/src/main/java/org/apache/directory/shared/ldap/client/api/LdapConnectionConfig.java
Mon Jul  6 16:26:30 2009
@@ -0,0 +1,155 @@
+/*
+ *   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;
+
+
+/**
+ * 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;
+
+    
+    // --- 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;
+
+
+    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;
+    }
+
+}

Modified: directory/shared/trunk/client-api/src/main/java/org/apache/directory/shared/ldap/client/api/PoolableLdapConnectionFactory.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/client-api/src/main/java/org/apache/directory/shared/ldap/client/api/PoolableLdapConnectionFactory.java?rev=791534&r1=791533&r2=791534&view=diff
==============================================================================
--- directory/shared/trunk/client-api/src/main/java/org/apache/directory/shared/ldap/client/api/PoolableLdapConnectionFactory.java
(original)
+++ directory/shared/trunk/client-api/src/main/java/org/apache/directory/shared/ldap/client/api/PoolableLdapConnectionFactory.java
Mon Jul  6 16:26:30 2009
@@ -22,7 +22,6 @@
 
 
 import org.apache.commons.pool.PoolableObjectFactory;
-import org.apache.directory.shared.ldap.util.StringTools;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -36,59 +35,22 @@
 public class PoolableLdapConnectionFactory implements PoolableObjectFactory
 {
 
-    /** The selected LDAP port, default value is 10389 */
-    private int ldapPort = 10389;
-
-    /** the remote LDAP host, default value is localhost */
-    private String ldapHost = "127.0.0.1";
-
-    /** A flag indicating if we are using SSL or not, default is false */
-    private boolean useSsl = false;
-
-    /** the user name used for binding, default value is uid=admin,ou=system*/
-    private String userName;
-
-    /** credentials of the user, default value is secret*/
-    private byte[] credentials = StringTools.getBytesUtf8( "secret" );
+    /** configuration object for the connection */
+    private LdapConnectionConfig config;
 
     private static final Logger LOG = LoggerFactory.getLogger( PoolableLdapConnectionFactory.class
);
 
 
-    public PoolableLdapConnectionFactory()
-    {
-    }
-
-
     /**
      * 
      * Creates a new instance of PoolableLdapConnectionFactory for the
      * server running on localhost at the port 10389
      *
-     * @param userName the DN of the user
-     * @param credentials user's credential
+     * @param config the configuration for creating LdapConnections
      */
-    public PoolableLdapConnectionFactory( String userName, byte[] credentials )
+    public PoolableLdapConnectionFactory( LdapConnectionConfig config )
     {
-        this.userName = userName;
-        this.credentials = credentials;
-    }
-
-
-    /**
-     * 
-     * Creates a new instance of PoolableLdapConnectionFactory.
-     *
-     * @param host hostname where the LDAP server is running 
-     * @param port port of the LDAP server
-     * @param userName the DN of the user
-     * @param credentials user's credential
-     */
-    public PoolableLdapConnectionFactory( String host, int port, String userName, byte[]
credentials )
-    {
-        this.ldapHost = host;
-        this.ldapPort = port;
-        this.userName = userName;
-        this.credentials = credentials;
+        this.config = config;
     }
 
 
@@ -120,8 +82,8 @@
     {
         LOG.debug( "creating a LDAP connection" );
 
-        LdapConnection connection = new LdapConnection( ldapHost, ldapPort, useSsl );
-        connection.bind( userName, credentials );
+        LdapConnection connection = new LdapConnection( config );
+        connection.bind( config.getName(), config.getCredentials() );
         return connection;
     }
 
@@ -146,33 +108,4 @@
         return connection.isSessionValid();
     }
 
-
-    public void setLdapPort( int ldapPort )
-    {
-        this.ldapPort = ldapPort;
-    }
-
-
-    public void setLdapHost( String ldapHost )
-    {
-        this.ldapHost = ldapHost;
-    }
-
-
-    public void setUseSsl( boolean useSsl )
-    {
-        this.useSsl = useSsl;
-    }
-
-
-    public void setUserName( String userName )
-    {
-        this.userName = userName;
-    }
-
-
-    public void setCredentials( byte[] credentials )
-    {
-        this.credentials = credentials;
-    }
 }



Mime
View raw message