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

neil_a_wilson
07.25.2007 518c1454ceec785840cef26d8906a8fe7cf0ce1e
Update the LDAP authentication handler to fix a potential null pointer
exception that could be thrown if the connection to the server was lost between
sending the bind request and getting the bind response.

OpenDS Issue Number: 1129
2 files modified
103 ■■■■■ changed files
opends/src/server/org/opends/server/messages/ToolMessages.java 14 ●●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/tools/LDAPAuthenticationHandler.java 89 ●●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/messages/ToolMessages.java
@@ -7507,6 +7507,17 @@
  /**
   * The message ID for the message that will be used if the connection to the
   * Directory Server is closed while attempting to read the bind response from
   * the server.  This does not take any arguments.
   */
  public static final int
       MSGID_LDAPAUTH_CONNECTION_CLOSED_WITHOUT_BIND_RESPONSE =
            CATEGORY_MASK_TOOLS | SEVERITY_MASK_SEVERE_ERROR | 789;
  /**
   * Associates a set of generic messages with the message IDs defined in this
   * class.
   */
@@ -8030,6 +8041,9 @@
    registerMessage(MSGID_LDAPAUTH_CANNOT_SEND_SIMPLE_BIND,
                    "Cannot send the simple bind request:  %s.");
    registerMessage(MSGID_LDAPAUTH_CONNECTION_CLOSED_WITHOUT_BIND_RESPONSE,
                    "The connection to the Directory Server was closed " +
                    "before the bind response could be read.");
    registerMessage(MSGID_LDAPAUTH_CANNOT_READ_BIND_RESPONSE,
                    "Cannot read the bind response from the server:  " +
                    "%s.");
opends/src/server/org/opends/server/tools/LDAPAuthenticationHandler.java
@@ -347,6 +347,14 @@
    try
    {
      ASN1Element responseElement = reader.readElement();
      if (responseElement == null)
      {
        int    msgID   = MSGID_LDAPAUTH_CONNECTION_CLOSED_WITHOUT_BIND_RESPONSE;
        String message = getMessage(msgID);
        throw new ClientException(LDAPResultCode.CLIENT_SIDE_SERVER_DOWN,
                                  msgID, message);
      }
      responseMessage = LDAPMessage.decode(responseElement.decodeAsSequence());
    }
    catch (IOException ioe)
@@ -665,6 +673,14 @@
    try
    {
      ASN1Element responseElement = reader.readElement();
      if (responseElement == null)
      {
        int    msgID   = MSGID_LDAPAUTH_CONNECTION_CLOSED_WITHOUT_BIND_RESPONSE;
        String message = getMessage(msgID);
        throw new ClientException(LDAPResultCode.CLIENT_SIDE_SERVER_DOWN,
                                  msgID, message);
      }
      responseMessage = LDAPMessage.decode(responseElement.decodeAsSequence());
    }
    catch (IOException ioe)
@@ -931,6 +947,14 @@
    try
    {
      ASN1Element responseElement1 = reader.readElement();
      if (responseElement1 == null)
      {
        int    msgID   = MSGID_LDAPAUTH_CONNECTION_CLOSED_WITHOUT_BIND_RESPONSE;
        String message = getMessage(msgID);
        throw new ClientException(LDAPResultCode.CLIENT_SIDE_SERVER_DOWN,
                                  msgID, message);
      }
      responseMessage1 =
           LDAPMessage.decode(responseElement1.decodeAsSequence());
    }
@@ -1076,6 +1100,14 @@
    try
    {
      ASN1Element responseElement = reader.readElement();
      if (responseElement == null)
      {
        int    msgID   = MSGID_LDAPAUTH_CONNECTION_CLOSED_WITHOUT_BIND_RESPONSE;
        String message = getMessage(msgID);
        throw new ClientException(LDAPResultCode.CLIENT_SIDE_SERVER_DOWN,
                                  msgID, message);
      }
      responseMessage2 = LDAPMessage.decode(responseElement.decodeAsSequence());
    }
    catch (IOException ioe)
@@ -1536,6 +1568,14 @@
    try
    {
      ASN1Element responseElement1 = reader.readElement();
      if (responseElement1 == null)
      {
        int    msgID   = MSGID_LDAPAUTH_CONNECTION_CLOSED_WITHOUT_BIND_RESPONSE;
        String message = getMessage(msgID);
        throw new ClientException(LDAPResultCode.CLIENT_SIDE_SERVER_DOWN,
                                  msgID, message);
      }
      responseMessage1 =
           LDAPMessage.decode(responseElement1.decodeAsSequence());
    }
@@ -1850,6 +1890,14 @@
    try
    {
      ASN1Element responseElement = reader.readElement();
      if (responseElement == null)
      {
        int    msgID   = MSGID_LDAPAUTH_CONNECTION_CLOSED_WITHOUT_BIND_RESPONSE;
        String message = getMessage(msgID);
        throw new ClientException(LDAPResultCode.CLIENT_SIDE_SERVER_DOWN,
                                  msgID, message);
      }
      responseMessage2 = LDAPMessage.decode(responseElement.decodeAsSequence());
    }
    catch (IOException ioe)
@@ -2523,6 +2571,14 @@
    try
    {
      ASN1Element responseElement = reader.readElement();
      if (responseElement == null)
      {
        int    msgID   = MSGID_LDAPAUTH_CONNECTION_CLOSED_WITHOUT_BIND_RESPONSE;
        String message = getMessage(msgID);
        throw new ClientException(LDAPResultCode.CLIENT_SIDE_SERVER_DOWN,
                                  msgID, message);
      }
      responseMessage = LDAPMessage.decode(responseElement.decodeAsSequence());
    }
    catch (IOException ioe)
@@ -3139,6 +3195,14 @@
    try
    {
      ASN1Element responseElement = reader.readElement();
      if (responseElement == null)
      {
        int    msgID   = MSGID_LDAPAUTH_CONNECTION_CLOSED_WITHOUT_BIND_RESPONSE;
        String message = getMessage(msgID);
        throw new ClientException(LDAPResultCode.CLIENT_SIDE_SERVER_DOWN,
                                  msgID, message);
      }
      responseMessage = LDAPMessage.decode(responseElement.decodeAsSequence());
    }
    catch (IOException ioe)
@@ -3371,6 +3435,14 @@
      try
      {
        ASN1Element responseElement = reader.readElement();
        if (responseElement == null)
        {
          int msgID = MSGID_LDAPAUTH_CONNECTION_CLOSED_WITHOUT_BIND_RESPONSE;
          String message = getMessage(msgID);
          throw new ClientException(LDAPResultCode.CLIENT_SIDE_SERVER_DOWN,
                                    msgID, message);
        }
        responseMessage =
             LDAPMessage.decode(responseElement.decodeAsSequence());
      }
@@ -3549,6 +3621,15 @@
          try
          {
            ASN1Element responseElement = reader.readElement();
            if (responseElement == null)
            {
              int msgID =
                   MSGID_LDAPAUTH_CONNECTION_CLOSED_WITHOUT_BIND_RESPONSE;
              String message = getMessage(msgID);
              throw new ClientException(LDAPResultCode.CLIENT_SIDE_SERVER_DOWN,
                                        msgID, message);
            }
            responseMessage =
                 LDAPMessage.decode(responseElement.decodeAsSequence());
          }
@@ -3762,6 +3843,14 @@
    try
    {
      ASN1Element responseElement = reader.readElement();
      if (responseElement == null)
      {
        int    msgID   = MSGID_LDAPAUTH_CONNECTION_CLOSED_WITHOUT_BIND_RESPONSE;
        String message = getMessage(msgID);
        throw new ClientException(LDAPResultCode.CLIENT_SIDE_SERVER_DOWN,
                                  msgID, message);
      }
      responseMessage = LDAPMessage.decode(responseElement.decodeAsSequence());
    }
    catch (IOException ioe)