You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by gg...@apache.org on 2017/06/26 02:22:22 UTC

logging-log4j2 git commit: [LOG4J2-1956] JMS Appender broker password should be a char[], not a String.

Repository: logging-log4j2
Updated Branches:
  refs/heads/master 19b20c0e7 -> 07248cdbb


[LOG4J2-1956] JMS Appender broker password should be a char[], not a
String.

Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/07248cdb
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/07248cdb
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/07248cdb

Branch: refs/heads/master
Commit: 07248cdbbdcbb44905d448d51c986c3bbd8995dc
Parents: 19b20c0
Author: Gary Gregory <gg...@apache.org>
Authored: Sun Jun 25 19:22:20 2017 -0700
Committer: Gary Gregory <gg...@apache.org>
Committed: Sun Jun 25 19:22:20 2017 -0700

----------------------------------------------------------------------
 .../log4j/core/appender/mom/JmsAppender.java    | 13 +++-
 .../log4j/core/appender/mom/JmsManager.java     | 71 +++++++++++++++-----
 src/changes/changes.xml                         |  3 +
 3 files changed, 67 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/07248cdb/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/mom/JmsAppender.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/mom/JmsAppender.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/mom/JmsAppender.java
index f9b7494..84b88fa 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/mom/JmsAppender.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/mom/JmsAppender.java
@@ -85,7 +85,7 @@ public class JmsAppender extends AbstractAppender {
         private String userName;
 
         @PluginBuilderAttribute(sensitive = true)
-        private String password;
+        private char[] password;
 
         @PluginElement("Layout")
         private Layout<? extends Serializable> layout = SerializedLayout.createLayout();
@@ -172,11 +172,20 @@ public class JmsAppender extends AbstractAppender {
             return this;
         }
 
-        public Builder setPassword(final String password) {
+        public Builder setPassword(final char[] password) {
             this.password = password;
             return this;
         }
 
+        /**
+         * @deprecated Use setPassword(char[])
+         */
+        @Deprecated
+        public Builder setPassword(final String password) {
+            this.password = password == null ? null : password.toCharArray();
+            return this;
+        }
+
         public Builder setProviderUrl(final String providerUrl) {
             this.providerUrl = providerUrl;
             return this;

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/07248cdb/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/mom/JmsManager.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/mom/JmsManager.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/mom/JmsManager.java
index b6ad13c..a985980 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/mom/JmsManager.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/mom/JmsManager.java
@@ -49,10 +49,10 @@ public class JmsManager extends AbstractManager {
         private final String connectionFactoryName;
         private final String destinationName;
         private final String userName;
-        private final String password;
+        private final char[] password;
 
-        JmsManagerConfiguration(final JndiManager jndiManager, final String connectionFactoryName, final String destinationName,
-                                 final String userName, final String password) {
+        JmsManagerConfiguration(final JndiManager jndiManager, final String connectionFactoryName,
+                final String destinationName, final String userName, final char[] password) {
             this.jndiManager = jndiManager;
             this.connectionFactoryName = connectionFactoryName;
             this.destinationName = destinationName;
@@ -85,29 +85,63 @@ public class JmsManager extends AbstractManager {
 
     private static final Logger LOGGER = StatusLogger.getLogger();
     static final JmsManagerFactory FACTORY = new JmsManagerFactory();
+
     /**
      * Gets a JmsManager using the specified configuration parameters.
      *
-     * @param name                  The name to use for this JmsManager.
-     * @param jndiManager           The JndiManager to look up JMS information through.
-     * @param connectionFactoryName The binding name for the {@link javax.jms.ConnectionFactory}.
-     * @param destinationName       The binding name for the {@link javax.jms.Destination}.
-     * @param userName              The userName to connect with or {@code null} for no authentication.
-     * @param password              The password to use with the given userName or {@code null} for no authentication.
+     * @param name
+     *            The name to use for this JmsManager.
+     * @param jndiManager
+     *            The JndiManager to look up JMS information through.
+     * @param connectionFactoryName
+     *            The binding name for the {@link javax.jms.ConnectionFactory}.
+     * @param destinationName
+     *            The binding name for the {@link javax.jms.Destination}.
+     * @param userName
+     *            The userName to connect with or {@code null} for no authentication.
+     * @param password
+     *            The password to use with the given userName or {@code null} for no authentication.
      * @return The JmsManager as configured.
+     * @deprecated Use the other getJmsManager() method
      */
+    @Deprecated
     public static JmsManager getJmsManager(final String name, final JndiManager jndiManager,
-                                           final String connectionFactoryName, final String destinationName,
-                                           final String userName, final String password) {
-        final JmsManagerConfiguration configuration = new JmsManagerConfiguration(jndiManager, connectionFactoryName, destinationName,
-            userName, password);
+            final String connectionFactoryName, final String destinationName, final String userName,
+            final String password) {
+        final JmsManagerConfiguration configuration = new JmsManagerConfiguration(jndiManager, connectionFactoryName,
+                destinationName, userName, password == null ? null : password.toCharArray());
         return getManager(name, FACTORY, configuration);
     }
+
+    /**
+     * Gets a JmsManager using the specified configuration parameters.
+     *
+     * @param name
+     *            The name to use for this JmsManager.
+     * @param jndiManager
+     *            The JndiManager to look up JMS information through.
+     * @param connectionFactoryName
+     *            The binding name for the {@link javax.jms.ConnectionFactory}.
+     * @param destinationName
+     *            The binding name for the {@link javax.jms.Destination}.
+     * @param userName
+     *            The userName to connect with or {@code null} for no authentication.
+     * @param password
+     *            The password to use with the given userName or {@code null} for no authentication.
+     * @return The JmsManager as configured.
+     */
+    public static JmsManager getJmsManager(final String name, final JndiManager jndiManager,
+            final String connectionFactoryName, final String destinationName, final String userName,
+            final char[] password) {
+        final JmsManagerConfiguration configuration = new JmsManagerConfiguration(jndiManager, connectionFactoryName,
+                destinationName, userName, password);
+        return getManager(name, FACTORY, configuration);
+    }
+
     private final JndiManager jndiManager;
     private final Connection connection;
     private final Session session;
 
-
     private final Destination destination;
 
     private final JmsManagerConfiguration configuration;
@@ -115,13 +149,14 @@ public class JmsManager extends AbstractManager {
     private final MessageProducer producer;
 
     private JmsManager(final String name, final JmsManagerConfiguration configuration)
-        throws NamingException, JMSException {
+            throws NamingException, JMSException {
         super(null, name);
         this.configuration = configuration;
         this.jndiManager = configuration.jndiManager;
         final ConnectionFactory connectionFactory = this.jndiManager.lookup(configuration.connectionFactoryName);
         if (configuration.userName != null && configuration.password != null) {
-            this.connection = connectionFactory.createConnection(configuration.userName, configuration.password);
+            this.connection = connectionFactory.createConnection(configuration.userName,
+                    configuration.password == null ? null : String.valueOf(configuration.password));
         } else {
             this.connection = connectionFactory.createConnection();
         }
@@ -171,7 +206,6 @@ public class JmsManager extends AbstractManager {
         return this.session.createConsumer(this.destination);
     }
 
-
     /**
      * Creates a MessageProducer on this Destination using the current Session.
      *
@@ -186,7 +220,8 @@ public class JmsManager extends AbstractManager {
         return configuration;
     }
 
-    private MapMessage map(final org.apache.logging.log4j.message.MapMessage<?, ?> log4jMapMessage, final MapMessage jmsMapMessage) {
+    private MapMessage map(final org.apache.logging.log4j.message.MapMessage<?, ?> log4jMapMessage,
+            final MapMessage jmsMapMessage) {
         // Map without calling rg.apache.logging.log4j.message.MapMessage#getData() which makes a copy of the map.
         log4jMapMessage.forEach(new BiConsumer<String, Object>() {
             @Override

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/07248cdb/src/changes/changes.xml
----------------------------------------------------------------------
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index ebd9311..9cb450b 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -52,6 +52,9 @@
       <action issue="LOG4J2-1934" dev="ggregory" type="add">
         JMS Appender does not know how to recover from a broken connection.
       </action>
+      <action issue="LOG4J2-1956" dev="ggregory" type="update">
+        JMS Appender broker password should be a char[], not a String.
+      </action>
       <action issue="LOG4J2-1874" dev="rpopma" type="add" due-to="Roman Leventov">
         Added methods ::writeBytes(ByteBuffer) and ::writeBytes(byte[], int, int) to ByteBufferDestination interface and use these methods in TextEncoderHelper where possible to prepare for future enhancements to reduce lock contention.
       </action>