From 94693c79a1632fbf72f4714ddfc9b434366e89d6 Mon Sep 17 00:00:00 2001
From: Matthew Swift <matthew.swift@forgerock.com>
Date: Tue, 20 Sep 2011 14:46:13 +0000
Subject: [PATCH] Fix OPENDJ-289: Don't fail requests using the result code returned in a disconnect notification

---
 opendj-sdk/opendj3/opendj-ldap-sdk/src/main/java/com/forgerock/opendj/ldap/LDAPConnection.java |   22 ++++++++++++++++++++--
 1 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/opendj-sdk/opendj3/opendj-ldap-sdk/src/main/java/com/forgerock/opendj/ldap/LDAPConnection.java b/opendj-sdk/opendj3/opendj-ldap-sdk/src/main/java/com/forgerock/opendj/ldap/LDAPConnection.java
index ed6f75b..705c271 100644
--- a/opendj-sdk/opendj3/opendj-ldap-sdk/src/main/java/com/forgerock/opendj/ldap/LDAPConnection.java
+++ b/opendj-sdk/opendj3/opendj-ldap-sdk/src/main/java/com/forgerock/opendj/ldap/LDAPConnection.java
@@ -877,7 +877,24 @@
       }
 
       // Mark the connection as invalid.
-      connectionInvalidReason = reason;
+      if (!isDisconnectNotification)
+      {
+        // Connection termination was detected locally, so use the provided
+        // reason for all subsequent requests.
+        connectionInvalidReason = reason;
+      }
+      else
+      {
+        // Connection termination was triggered remotely. We don't want to
+        // blindly pass on the result code to requests since it could be
+        // confused for a genuine response. For example, if the disconnect
+        // contained the invalidCredentials result code then this could be
+        // misinterpreted as a genuine authentication failure for subsequent
+        // bind requests.
+        connectionInvalidReason = Responses.newResult(
+            ResultCode.CLIENT_SIDE_SERVER_DOWN).setDiagnosticMessage(
+            "Connection closed by server");
+      }
     }
 
     // First abort all outstanding requests.
@@ -887,7 +904,7 @@
           .remove(requestID);
       if (future != null)
       {
-        future.adaptErrorResult(reason);
+        future.adaptErrorResult(connectionInvalidReason);
       }
     }
 
@@ -937,6 +954,7 @@
     {
       for (final ConnectionEventListener listener : listeners)
       {
+        // Use the reason provided in the disconnect notification.
         listener.handleConnectionError(isDisconnectNotification,
             newErrorResult(reason));
       }

--
Gitblit v1.10.0