From 1bdcce4d1f73ba57fd4c2a91e8833d943b193a6e Mon Sep 17 00:00:00 2001
From: matthew_swift <matthew_swift@localhost>
Date: Mon, 27 Apr 2009 18:19:56 +0000
Subject: [PATCH] Fix issue 3936: Allow intermediate CONNECT messages to be logged.

---
 opendj-sdk/opends/src/server/org/opends/server/loggers/TextAccessLogPublisher.java |   68 ++++++++++++++++++++++
 opendj-sdk/opends/src/server/org/opends/server/api/AccessLogPublisher.java         |   50 ++++++++++++++++
 opendj-sdk/opends/src/server/org/opends/server/loggers/AccessLogger.java           |   59 ++++++++++++++++++-
 3 files changed, 171 insertions(+), 6 deletions(-)

diff --git a/opendj-sdk/opends/src/server/org/opends/server/api/AccessLogPublisher.java b/opendj-sdk/opends/src/server/org/opends/server/api/AccessLogPublisher.java
index 1a259c7..421cd53 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/api/AccessLogPublisher.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/api/AccessLogPublisher.java
@@ -22,7 +22,7 @@
  * CDDL HEADER END
  *
  *
- *      Copyright 2008 Sun Microsystems, Inc.
+ *      Copyright 2008-2009 Sun Microsystems, Inc.
  */
 package org.opends.server.api;
 
@@ -133,6 +133,30 @@
 
 
   /**
+   * Writes a message to the access logger containing additional
+   * information associated with the provided client connection.
+   * <p>
+   * The default implementation is to not log anything.
+   *
+   * @param clientConnection
+   *          The client connection that has been established.
+   * @param category
+   *          The category of the intermediate message.
+   * @param content
+   *          The content of the intermediate message. This comprises
+   *          of one or more key/value pairs which form the content of
+   *          the intermediate message.
+   */
+  public void logConnectIntermediateMessage(
+      ClientConnection clientConnection, String category,
+      Map<String, String> content)
+  {
+    // Do nothing
+  }
+
+
+
+  /**
    * Writes a message to the access logger with information about the
    * termination of an existing client connection.
    * <p>
@@ -156,6 +180,30 @@
 
 
   /**
+   * Writes a message to the access logger containing additional
+   * information associated with the provided client disconnection.
+   * <p>
+   * The default implementation is to not log anything.
+   *
+   * @param clientConnection
+   *          The client connection that has been terminated.
+   * @param category
+   *          The category of the intermediate message.
+   * @param content
+   *          The content of the intermediate message. This comprises
+   *          of one or more key/value pairs which form the content of
+   *          the intermediate message.
+   */
+  public void logDisconnectIntermediateMessage(
+      ClientConnection clientConnection, String category,
+      Map<String, String> content)
+  {
+    // Do nothing
+  }
+
+
+
+  /**
    * Writes a message to the access logger with information about the
    * abandon request associated with the provided abandon operation.
    * <p>
diff --git a/opendj-sdk/opends/src/server/org/opends/server/loggers/AccessLogger.java b/opendj-sdk/opends/src/server/org/opends/server/loggers/AccessLogger.java
index 58c54d6..18fd8fb 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/loggers/AccessLogger.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/loggers/AccessLogger.java
@@ -22,7 +22,7 @@
  * CDDL HEADER END
  *
  *
- *      Copyright 2006-2008 Sun Microsystems, Inc.
+ *      Copyright 2006-2009 Sun Microsystems, Inc.
  */
 package org.opends.server.loggers;
 import org.opends.messages.Message;
@@ -73,11 +73,11 @@
 
   // The set of access loggers that have been registered with the server.  It
   // will initially be empty.
-  static CopyOnWriteArrayList<AccessLogPublisher<?>> accessPublishers =
+  private static CopyOnWriteArrayList<AccessLogPublisher<?>> accessPublishers =
       new CopyOnWriteArrayList<AccessLogPublisher<?>>();
 
   // The singleton instance of this class for configuration purposes.
-  static final AccessLogger instance = new AccessLogger();
+  private static final AccessLogger instance = new AccessLogger();
 
 
 
@@ -448,6 +448,32 @@
 
 
   /**
+   * Writes a message to the access logger containing additional
+   * information associated with the provided client connection.
+   *
+   * @param clientConnection
+   *          The client connection that has been established.
+   * @param category
+   *          The category of the intermediate message.
+   * @param content
+   *          The content of the intermediate message. This comprises of
+   *          one or more key/value pairs which form the content of the
+   *          intermediate message.
+   */
+  public static void logConnectIntermediateMessage(
+      ClientConnection clientConnection, String category,
+      Map<String, String> content)
+  {
+    for (AccessLogPublisher<?> publisher : accessPublishers)
+    {
+      publisher.logConnectIntermediateMessage(clientConnection,
+          category, content);
+    }
+  }
+
+
+
+  /**
    * Writes a message to the access logger with information about the
    * termination of an existing client connection.
    *
@@ -468,6 +494,33 @@
   }
 
 
+
+  /**
+   * Writes a message to the access logger containing additional
+   * information associated with the provided client disconnection.
+   *
+   * @param clientConnection
+   *          The client connection that has been terminated.
+   * @param category
+   *          The category of the intermediate message.
+   * @param content
+   *          The content of the intermediate message. This comprises of
+   *          one or more key/value pairs which form the content of the
+   *          intermediate message.
+   */
+  public static void logDisconnectIntermediateMessage(
+      ClientConnection clientConnection, String category,
+      Map<String, String> content)
+  {
+    for (AccessLogPublisher<?> publisher : accessPublishers)
+    {
+      publisher.logDisconnectIntermediateMessage(clientConnection,
+          category, content);
+    }
+  }
+
+
+
   /**
    * Writes a message to the access logger with information about the abandon
    * request associated with the provided abandon operation.
diff --git a/opendj-sdk/opends/src/server/org/opends/server/loggers/TextAccessLogPublisher.java b/opendj-sdk/opends/src/server/org/opends/server/loggers/TextAccessLogPublisher.java
index 5bb6688..5f6d8e0 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/loggers/TextAccessLogPublisher.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/loggers/TextAccessLogPublisher.java
@@ -854,6 +854,20 @@
    * {@inheritDoc}
    */
   @Override
+  public void logConnectIntermediateMessage(
+      ClientConnection clientConnection, String category,
+      Map<String, String> content)
+  {
+    logIntermediateMessage(clientConnection, "CONNECT", category,
+        content);
+  }
+
+
+
+  /**
+   * {@inheritDoc}
+   */
+  @Override
   public void logDeleteIntermediateMessage(DeleteOperation deleteOperation,
       String category, Map<String, String> content)
   {
@@ -997,6 +1011,20 @@
    * {@inheritDoc}
    */
   @Override
+  public void logDisconnectIntermediateMessage(
+      ClientConnection clientConnection, String category,
+      Map<String, String> content)
+  {
+    logIntermediateMessage(clientConnection, "DISCONNECT", category,
+        content);
+  }
+
+
+
+  /**
+   * {@inheritDoc}
+   */
+  @Override
   public void logExtendedIntermediateMessage(
       ExtendedOperation extendedOperation, String category,
       Map<String, String> content)
@@ -1461,11 +1489,11 @@
   private void appendHeader(Operation operation, String opType,
       String category, StringBuilder buffer)
   {
-    buffer.append("[");
+    buffer.append('[');
     buffer.append(TimeThread.getLocalTime());
     buffer.append("] ");
     buffer.append(opType);
-    buffer.append(" ");
+    buffer.append(' ');
     buffer.append(category);
     buffer.append(" conn=");
     buffer.append(operation.getConnectionID());
@@ -1526,4 +1554,40 @@
 
     writer.writeRecord(buffer.toString());
   }
+
+
+
+  //Writes an intermediate message to the log.
+  private void logIntermediateMessage(
+      ClientConnection clientConnection, String type, String category,
+      Map<String, String> content)
+  {
+    long connectionID = clientConnection.getConnectionID();
+
+    if (connectionID < 0 && suppressInternalOperations)
+    {
+      return;
+    }
+
+    StringBuilder buffer = new StringBuilder(100);
+
+    buffer.append('[');
+    buffer.append(TimeThread.getLocalTime());
+    buffer.append("] ");
+    buffer.append(type);
+    buffer.append(' ');
+    buffer.append(category);
+    buffer.append(" conn=");
+    buffer.append(connectionID);
+
+    for (Map.Entry<String, String> entry : content.entrySet())
+    {
+      buffer.append(' ');
+      buffer.append(entry.getKey());
+      buffer.append('=');
+      buffer.append(entry.getValue());
+    }
+
+    writer.writeRecord(buffer.toString());
+  }
 }

--
Gitblit v1.10.0