mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

Ludovic Poitou
21.38.2011 a567a3136472c3cb288026f03f71243b3d99b513
Fix issue OPENDJ-239.
1 files modified
44 ■■■■■ changed files
opendj3/opendj-ldap-sdk/src/main/java/com/forgerock/opendj/ldap/LDAPConnection.java 44 ●●●●● patch | view | raw | blame | history
opendj3/opendj-ldap-sdk/src/main/java/com/forgerock/opendj/ldap/LDAPConnection.java
@@ -23,6 +23,7 @@
 *
 *
 *      Copyright 2010 Sun Microsystems, Inc.
 *      Portions Copyright 2011 ForgeRock AS
 */
package com.forgerock.opendj.ldap;
@@ -293,13 +294,6 @@
        future.adaptErrorResult(connectionInvalidReason);
        return future;
      }
      if (!bindOrStartTLSInProgress.compareAndSet(false, true))
      {
        future.setResultOrError(Responses.newBindResult(
            ResultCode.OPERATIONS_ERROR).setDiagnosticMessage(
            "Bind or Start TLS operation in progress"));
        return future;
      }
      if (!pendingRequests.isEmpty())
      {
        future.setResultOrError(Responses.newBindResult(
@@ -308,6 +302,14 @@
        return future;
      }
      if (!bindOrStartTLSInProgress.compareAndSet(false, true))
      {
        future.setResultOrError(Responses.newBindResult(
            ResultCode.OPERATIONS_ERROR).setDiagnosticMessage(
            "Bind or Start TLS operation in progress"));
        return future;
      }
      pendingRequests.put(messageID, future);
    }
@@ -331,6 +333,8 @@
    {
      pendingRequests.remove(messageID);
      bindOrStartTLSInProgress.set(false);
      // FIXME: what other sort of IOExceptions can be thrown?
      // FIXME: Is this the best result code?
      final Result errorResult = Responses.newResult(
@@ -499,13 +503,6 @@
        future.adaptErrorResult(connectionInvalidReason);
        return future;
      }
      if (!bindOrStartTLSInProgress.compareAndSet(false, true))
      {
        future.setResultOrError(request.getResultDecoder()
            .newExtendedErrorResult(ResultCode.OPERATIONS_ERROR, "",
                "Bind or Start TLS operation in progress"));
        return future;
      }
      if (request.getOID().equals(StartTLSExtendedRequest.OID))
      {
        if (!pendingRequests.isEmpty())
@@ -520,6 +517,24 @@
          future.setResultOrError(request.getResultDecoder()
              .newExtendedErrorResult(ResultCode.OPERATIONS_ERROR, "",
                  "This connection is already TLS enabled"));
          return future;
        }
        if (!bindOrStartTLSInProgress.compareAndSet(false, true))
        {
          future.setResultOrError(request.getResultDecoder()
                .newExtendedErrorResult(ResultCode.OPERATIONS_ERROR, "",
                    "Bind or Start TLS operation in progress"));
          return future;
        }
      }
      else
      {
        if (bindOrStartTLSInProgress.get())
        {
          future.setResultOrError(request.getResultDecoder()
                .newExtendedErrorResult(ResultCode.OPERATIONS_ERROR, "",
                    "Bind or Start TLS operation in progress"));
          return future;
        }
      }
      pendingRequests.put(messageID, future);
@@ -541,6 +556,7 @@
    catch (final IOException e)
    {
      pendingRequests.remove(messageID);
      bindOrStartTLSInProgress.set(false);
      // FIXME: what other sort of IOExceptions can be thrown?
      // FIXME: Is this the best result code?