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

Jean-Noel Rouvignac
19.11.2013 bc247971096268630f67130974fccbb3a6e23be5
OPENDJ-808 Implement a simple commons REST based HTTP connection handler

TLSCapableConnection.java:
Renamed isTLSAvailable() to isStartTLSAvailable() to better explicit the purpose of this method.

StartTLSExtendedOperation.java:
Consequence of the change to TLSCapableConnection.

LDAPClientConnection.java:
Consequence of the change to TLSCapableConnection.
Used StaticUtils.close() methods.
Removed one useless parameter from ConnectionFinalizerJob constructor.

StaticUtils.java:
Added close(Selector...).
4 files modified
82 ■■■■ changed files
opends/src/server/org/opends/server/extensions/StartTLSExtendedOperation.java 7 ●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/extensions/TLSCapableConnection.java 3 ●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/protocols/ldap/LDAPClientConnection.java 45 ●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/util/StaticUtils.java 27 ●●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/extensions/StartTLSExtendedOperation.java
@@ -23,6 +23,7 @@
 *
 *
 *      Copyright 2006-2009 Sun Microsystems, Inc.
 *      Portions Copyright 2013 ForgeRock AS
 */
package org.opends.server.extensions;
@@ -132,8 +133,6 @@
    if (clientConnection == null)
    {
      operation.setResultCode(ResultCode.UNAVAILABLE);
      operation.appendErrorMessage(ERR_STARTTLS_NO_CLIENT_CONNECTION.get());
      return;
    }
@@ -149,14 +148,12 @@
    else
    {
      operation.setResultCode(ResultCode.UNAVAILABLE);
      operation.appendErrorMessage(ERR_STARTTLS_NOT_TLS_CAPABLE.get());
      return;
    }
    MessageBuilder unavailableReason = new MessageBuilder();
    if (! tlsCapableConnection.isTLSAvailable(unavailableReason))
    if (! tlsCapableConnection.isStartTLSAvailable(unavailableReason))
    {
      operation.setResultCode(ResultCode.UNAVAILABLE);
      operation.setErrorMessage(unavailableReason);
opends/src/server/org/opends/server/extensions/TLSCapableConnection.java
@@ -23,6 +23,7 @@
 *
 *
 *      Copyright 2006-2009 Sun Microsystems, Inc.
 *      Portions Copyright 2013 ForgeRock AS
 */
package org.opends.server.extensions;
import org.opends.messages.MessageBuilder;
@@ -51,6 +52,6 @@
   * @return  <CODE>true</CODE> if TLS is available on the underlying client
   *          connection, or <CODE>false</CODE> if it is not.
   */
  public boolean isTLSAvailable(MessageBuilder unavailableReason);
  public boolean isStartTLSAvailable(MessageBuilder unavailableReason);
}
opends/src/server/org/opends/server/protocols/ldap/LDAPClientConnection.java
@@ -34,12 +34,10 @@
import static org.opends.server.core.DirectoryServer.getMaxInternalBufferSize;
import static org.opends.server.loggers.AccessLogger.logDisconnect;
import static org.opends.server.loggers.ErrorLogger.logError;
import static org.opends.server.loggers.debug.DebugLogger.debugEnabled;
import static org.opends.server.loggers.debug.DebugLogger.getTracer;
import static org.opends.server.loggers.debug.DebugLogger.*;
import static org.opends.server.protocols.ldap.LDAPConstants.*;
import static org.opends.server.util.ServerConstants.OID_START_TLS_REQUEST;
import static org.opends.server.util.StaticUtils.getExceptionMessage;
import static org.opends.server.util.StaticUtils.stackTraceToSingleLineString;
import static org.opends.server.util.StaticUtils.*;
import java.io.IOException;
import java.net.InetAddress;
@@ -92,15 +90,15 @@
   */
  private static final class ConnectionFinalizerJob implements Runnable
  {
    // The client connection ASN1 reader.
    /** The client connection ASN1 reader. */
    private final ASN1Reader asn1Reader;
    // The client connection socket channel.
    /** The client connection socket channel. */
    private final SocketChannel socketChannel;
    // Creates a new connection finalizer job.
    private ConnectionFinalizerJob(long connectionID,
        ASN1Reader asn1Reader, SocketChannel socketChannel)
    /** Creates a new connection finalizer job. */
    private ConnectionFinalizerJob(ASN1Reader asn1Reader,
        SocketChannel socketChannel)
    {
      this.asn1Reader = asn1Reader;
      this.socketChannel = socketChannel;
@@ -996,16 +994,9 @@
    finally
    {
      // Clear and reset all of the internal buffers ready for the next usage.
      try
      {
        // The ASN1Writer is based on a ByteStringBuilder so closing will cause
        // the internal buffers to be resized if needed.
        holder.writer.close();
      }
      catch (IOException ignored)
      {
        // Unreachable.
      }
      // The ASN1Writer is based on a ByteStringBuilder so closing will cause
      // the internal buffers to be resized if needed.
      close(holder.writer);
    }
 }
@@ -1078,16 +1069,7 @@
    // If there is a write selector for this connection, then close it.
    Selector selector = writeSelector.get();
    if (selector != null)
    {
      try
      {
        selector.close();
      }
      catch (Exception e)
      {
      }
    }
    close(selector);
    // See if we should send a notification to the client. If so, then
    // construct and send a notice of disconnection unsolicited
@@ -1152,8 +1134,7 @@
    }
    // Enqueue the connection channels for closing by the finalizer.
    Runnable r =
      new ConnectionFinalizerJob(connectionID, asn1Reader, clientChannel);
    Runnable r = new ConnectionFinalizerJob(asn1Reader, clientChannel);
    connectionHandler.registerConnectionFinalizer(r);
    // NYI -- Deregister the client connection from any server components that
@@ -2526,7 +2507,7 @@
   * @return <CODE>true</CODE> if TLS is available on the underlying
   *         client connection, or <CODE>false</CODE> if it is not.
   */
  public boolean isTLSAvailable(MessageBuilder unavailableReason)
  public boolean isStartTLSAvailable(MessageBuilder unavailableReason)
  {
    if (isSecure() && activeProvider.getName().equals("TLS"))
    {
opends/src/server/org/opends/server/util/StaticUtils.java
@@ -4639,6 +4639,33 @@
  }
  /**
   * Closes the provided {@link Selector}'s ignoring any errors which occurred.
   * <p>
   * With java 7 we will be able to use {@link StaticUtils#close(Closeable...)}
   * </p>
   *
   * @param selectors
   *          The selectors to be closed, which may be <code>null</code>.
   */
  public static void close(Selector... selectors)
  {
    for (Selector selector : selectors)
    {
      if (selector != null)
      {
        try
        {
          selector.close();
        }
        catch (IOException ignored)
        {
          // Ignore.
        }
      }
    }
  }
  /**
   * Returns an {@link Iterable} returning the passed in {@link Iterator}. THis
   * allows using methods returning Iterators with foreach statements.
   * <p>