logging-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nickwilli...@apache.org
Subject svn commit: r1514958 - in /logging/log4j/log4j2/trunk: core/src/main/java/org/apache/logging/log4j/core/appender/db/nosql/mongo/ src/changes/
Date Sat, 17 Aug 2013 08:16:14 GMT
Author: nickwilliams
Date: Sat Aug 17 08:16:14 2013
New Revision: 1514958

URL: http://svn.apache.org/r1514958
Log:
[LOG4J2-358] NoSQLAppender using MongoDB provider ignores username and password attributes

Added missing code to MongoDBProvider to actually use the username and password attributes.

Modified:
    logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/db/nosql/mongo/MongoDBConnection.java
    logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/db/nosql/mongo/MongoDBProvider.java
    logging/log4j/log4j2/trunk/src/changes/changes.xml

Modified: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/db/nosql/mongo/MongoDBConnection.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/db/nosql/mongo/MongoDBConnection.java?rev=1514958&r1=1514957&r2=1514958&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/db/nosql/mongo/MongoDBConnection.java
(original)
+++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/db/nosql/mongo/MongoDBConnection.java
Sat Aug 17 08:16:14 2013
@@ -17,9 +17,11 @@
 package org.apache.logging.log4j.core.appender.db.nosql.mongo;
 
 import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.Logger;
 import org.apache.logging.log4j.core.appender.AppenderLoggingException;
 import org.apache.logging.log4j.core.appender.db.nosql.NoSQLConnection;
 import org.apache.logging.log4j.core.appender.db.nosql.NoSQLObject;
+import org.apache.logging.log4j.status.StatusLogger;
 import org.bson.BSON;
 import org.bson.Transformer;
 
@@ -36,6 +38,8 @@ import com.mongodb.WriteResult;
  */
 public final class MongoDBConnection implements NoSQLConnection<BasicDBObject, MongoDBObject>
{
 
+    private static final Logger LOGGER = StatusLogger.getLogger();
+
     static {
         BSON.addDecodingHook(Level.class, new Transformer() {
             @Override
@@ -91,4 +95,29 @@ public final class MongoDBConnection imp
     public boolean isClosed() {
         return !this.mongo.getConnector().isOpen();
     }
+
+    /**
+     * To prevent class loading issues during plugin discovery, this code cannot live within
MongoDBProvider. This
+     * is because of how Java treats references to Exception classes different from references
to other classes. When
+     * Java loads a class, it normally won't load that class's dependent classes until and
unless A) they are used, B)
+     * the class being loaded extends or implements those classes, or C) those classes are
the types of static members
+     * in the class. However, exceptions that a class uses are always loaded when the class
is loaded, even before
+     * they are actually used.
+     *
+     * @param database The database to authenticate
+     * @param username The username to authenticate with
+     * @param password The password to authenticate with
+     */
+    static void authenticate(final DB database, final String username, final String password)
{
+        try {
+            if (!database.authenticate(username, password.toCharArray())) {
+                LOGGER.error("Failed to authenticate against MongoDB server. Unknown error.");
+            }
+        } catch (final MongoException e) {
+            LOGGER.error("Failed to authenticate against MongoDB: " + e.getMessage(), e);
+        } catch (final IllegalStateException e) {
+            LOGGER.error("Factory-supplied MongoDB database connection already authenticated
with different" +
+                    "credentials but lost connection.");
+        }
+    }
 }

Modified: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/db/nosql/mongo/MongoDBProvider.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/db/nosql/mongo/MongoDBProvider.java?rev=1514958&r1=1514957&r2=1514958&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/db/nosql/mongo/MongoDBProvider.java
(original)
+++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/db/nosql/mongo/MongoDBProvider.java
Sat Aug 17 08:16:14 2013
@@ -180,6 +180,7 @@ public final class MongoDBProvider imple
             if (username != null && username.length() > 0 && password
!= null && password.length() > 0) {
                 description += ", username=" + username + ", passwordHash="
                         + NameUtil.md5(password + MongoDBProvider.class.getName());
+                MongoDBConnection.authenticate(database, username, password);
             } else {
                 LOGGER.error("The database is not already authenticated so you must supply
a username and password "
                         + "for the MongoDB provider.");

Modified: logging/log4j/log4j2/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/src/changes/changes.xml?rev=1514958&r1=1514957&r2=1514958&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/src/changes/changes.xml (original)
+++ logging/log4j/log4j2/trunk/src/changes/changes.xml Sat Aug 17 08:16:14 2013
@@ -21,6 +21,9 @@
   </properties>
   <body>
     <release version="2.0-beta9" date="soon, very soon" description="Bug fixes and enhancements">
+      <action issue="LOG4J2-358" dev="nickwilliams" type="fix">
+        NoSQLAppender using MongoDB provider ignores username and password attributes
+      </action>
       <action issue="LOG4J2-356" dev="ggregory" type="add">
         Create a JSON Layout.
       </action>



Mime
View raw message