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 2014/11/05 10:58:18 UTC

svn commit: r1636845 - /directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/PoolableLdapConnectionFactory.java

Author: elecharny
Date: Wed Nov  5 09:58:17 2014
New Revision: 1636845

URL: http://svn.apache.org/r1636845
Log:
Added some check for the connection, and authent. If teh conneciton is not authenticated, we bind it.

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

Modified: directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/PoolableLdapConnectionFactory.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/PoolableLdapConnectionFactory.java?rev=1636845&r1=1636844&r2=1636845&view=diff
==============================================================================
--- directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/PoolableLdapConnectionFactory.java (original)
+++ directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/PoolableLdapConnectionFactory.java Wed Nov  5 09:58:17 2014
@@ -78,21 +78,28 @@ public class PoolableLdapConnectionFacto
     /**
      * {@inheritDoc}
      */
-    public void destroyObject( LdapConnection connection ) 
+    public void destroyObject( LdapConnection connection )
     {
         LOG.debug( "Destroying {}", connection );
-        try {
-            connection.unBind();
-        }
-        catch ( LdapException e ) {
-            LOG.error( "unable to unbind connection: {}", e.getMessage() );
-            LOG.debug( "unable to unbind connection:", e );
+        if ( connection.isConnected() )
+        {
+            try
+            {
+                connection.unBind();
+            }
+            catch ( LdapException e )
+            {
+                LOG.error( "unable to unbind connection: {}", e.getMessage() );
+                LOG.debug( "unable to unbind connection:", e );
+            }
         }
 
-        try {
+        try
+        {
             connection.close();
         }
-        catch ( IOException e ) {
+        catch ( IOException e )
+        {
             LOG.error( "unable to close connection: {}", e.getMessage() );
             LOG.debug( "unable to close connection:", e );
         }
@@ -128,10 +135,10 @@ public class PoolableLdapConnectionFacto
     public void passivateObject( LdapConnection connection ) throws LdapException
     {
         LOG.debug( "Passivating {}", connection );
-        
+
         // in case connection configuration was modified, or rebound to a
         // different identity, we reinitialize before returning to the pool.
-        connectionFactory.bindConnection( 
+        connectionFactory.bindConnection(
             connectionFactory.configureConnection( connection ) );
     }
 
@@ -145,13 +152,30 @@ public class PoolableLdapConnectionFacto
 
         if ( connection.isConnected() )
         {
-            try
+            if ( connection.isAuthenticated() )
             {
-                return connection.lookup( Dn.ROOT_DSE, SchemaConstants.NO_ATTRIBUTE ) != null;
+                try
+                {
+                    return connection.lookup( Dn.ROOT_DSE, SchemaConstants.NO_ATTRIBUTE ) != null;
+                }
+                catch ( LdapException le )
+                {
+                    return false;
+                }
             }
-            catch ( LdapException le )
+            else
             {
-                return false;
+                // We have to bind the connection
+                try
+                {
+                    connectionFactory.bindConnection( connection );
+
+                    return true;
+                }
+                catch ( LdapException le )
+                {
+                    return false;
+                }
             }
         }
         else