You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flume.apache.org by rg...@apache.org on 2022/03/31 02:29:19 UTC

[flume] branch trunk updated: FLUME-3416 - Improve input validation

This is an automated email from the ASF dual-hosted git repository.

rgoers pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/flume.git


The following commit(s) were added to refs/heads/trunk by this push:
     new dafb26c  FLUME-3416 - Improve input validation
dafb26c is described below

commit dafb26ccb172141c6e14e95447e1b6ae38e9a7d0
Author: Ralph Goers <rg...@apache.org>
AuthorDate: Wed Mar 30 19:29:06 2022 -0700

    FLUME-3416 - Improve input validation
---
 .../main/java/org/apache/flume/source/jms/JMSSource.java  | 15 +++++++++++++++
 .../java/org/apache/flume/source/jms/TestJMSSource.java   |  7 +++++++
 2 files changed, 22 insertions(+)

diff --git a/flume-ng-sources/flume-jms-source/src/main/java/org/apache/flume/source/jms/JMSSource.java b/flume-ng-sources/flume-jms-source/src/main/java/org/apache/flume/source/jms/JMSSource.java
index 938d5e2..502938a 100644
--- a/flume-ng-sources/flume-jms-source/src/main/java/org/apache/flume/source/jms/JMSSource.java
+++ b/flume-ng-sources/flume-jms-source/src/main/java/org/apache/flume/source/jms/JMSSource.java
@@ -19,6 +19,8 @@ package org.apache.flume.source.jms;
 
 import java.io.File;
 import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
 import java.util.List;
 import java.util.Locale;
 import java.util.Properties;
@@ -53,6 +55,7 @@ import com.google.common.io.Files;
 @InterfaceStability.Unstable
 public class JMSSource extends AbstractPollableSource implements BatchSizeSupported {
   private static final Logger logger = LoggerFactory.getLogger(JMSSource.class);
+  private static final String JAVA_SCHEME = "java";
 
   // setup by constructor
   private final InitialContextFactory initialContextFactory;
@@ -179,6 +182,14 @@ public class JMSSource extends AbstractPollableSource implements BatchSizeSuppor
     String connectionFactoryName = context.getString(
         JMSSourceConfiguration.CONNECTION_FACTORY,
         JMSSourceConfiguration.CONNECTION_FACTORY_DEFAULT).trim();
+    try {
+      URI uri = new URI(connectionFactoryName);
+      String scheme = uri.getScheme();
+      assertTrue(scheme == null || scheme.equals(JAVA_SCHEME),
+          "Unsupported JNDI URI: " + connectionFactoryName);
+    } catch (URISyntaxException ex) {
+      logger.warn("Invalid JNDI URI - {}", connectionFactoryName);
+    }
 
     assertNotEmpty(initialContextFactoryName, String.format(
         "Initial Context Factory is empty. This is specified by %s",
@@ -272,6 +283,10 @@ public class JMSSource extends AbstractPollableSource implements BatchSizeSuppor
     Preconditions.checkArgument(!arg.isEmpty(), msg);
   }
 
+  private void assertTrue(boolean arg, String msg) {
+    Preconditions.checkArgument(arg, msg);
+  }
+
   @Override
   protected synchronized Status doProcess() throws EventDeliveryException {
     boolean error = true;
diff --git a/flume-ng-sources/flume-jms-source/src/test/java/org/apache/flume/source/jms/TestJMSSource.java b/flume-ng-sources/flume-jms-source/src/test/java/org/apache/flume/source/jms/TestJMSSource.java
index ffb0de8..5a008af 100644
--- a/flume-ng-sources/flume-jms-source/src/test/java/org/apache/flume/source/jms/TestJMSSource.java
+++ b/flume-ng-sources/flume-jms-source/src/test/java/org/apache/flume/source/jms/TestJMSSource.java
@@ -125,6 +125,13 @@ public class TestJMSSource extends JMSMessageConsumerTestBase {
     source.configure(context);
   }
 
+  @Test(expected = IllegalArgumentException.class)
+  public void testConfigureWithConnectionFactory() throws Exception {
+    context.put(JMSSourceConfiguration.CONNECTION_FACTORY,
+        "ldap://localhost:319/connectionFactory");
+    source.configure(context);
+  }
+
   @Test(expected = FlumeException.class)
   public void testConfigureWithBadDestinationType() throws Exception {
     context.put(JMSSourceConfiguration.DESTINATION_TYPE, "DUMMY");