You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ac...@apache.org on 2017/08/07 08:42:45 UTC

[2/3] camel git commit: CAMEL-11642 - Broker Credentials should be set from endpoint

CAMEL-11642 - Broker Credentials should be set from endpoint


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/9c7a8f30
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/9c7a8f30
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/9c7a8f30

Branch: refs/heads/master
Commit: 9c7a8f308ce845aab89b0e08cce3ab7babf08cfa
Parents: fe79516
Author: Fabrizio Spataro <fa...@bizmate.it>
Authored: Mon Aug 7 10:07:27 2017 +0200
Committer: Andrea Cosentino <an...@gmail.com>
Committed: Mon Aug 7 10:27:40 2017 +0200

----------------------------------------------------------------------
 .../src/main/docs/paho-component.adoc           |  4 +--
 .../camel/component/paho/PahoComponent.java     |  2 +-
 .../camel/component/paho/PahoEndpoint.java      | 34 ++++++++++++++++++++
 .../camel/component/paho/PahoComponentTest.java | 12 +++++++
 4 files changed, 49 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/9c7a8f30/components/camel-paho/src/main/docs/paho-component.adoc
----------------------------------------------------------------------
diff --git a/components/camel-paho/src/main/docs/paho-component.adoc b/components/camel-paho/src/main/docs/paho-component.adoc
index 2c20f19..84083ee 100644
--- a/components/camel-paho/src/main/docs/paho-component.adoc
+++ b/components/camel-paho/src/main/docs/paho-component.adoc
@@ -127,13 +127,13 @@ The Paho component supports 4 options which are listed below.
 | **brokerUrl** (common) | The URL of the MQTT broker. |  | String
 | **clientId** (common) | MQTT client identifier. |  | String
 | **connectOptions** (advanced) | Client connection options |  | MqttConnectOptions
+| **userName** (common) | UserName used for authentication again the MQTT broker. |  | String
+| **password** (common) | Password used for authentication again the MQTT broker. |  | String
 | **resolveProperty Placeholders** (advanced) | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | boolean
 |=======================================================================
 // component options: END
 
 
-
-
 // endpoint options: START
 The Paho endpoint is configured using URI syntax:
 

http://git-wip-us.apache.org/repos/asf/camel/blob/9c7a8f30/components/camel-paho/src/main/java/org/apache/camel/component/paho/PahoComponent.java
----------------------------------------------------------------------
diff --git a/components/camel-paho/src/main/java/org/apache/camel/component/paho/PahoComponent.java b/components/camel-paho/src/main/java/org/apache/camel/component/paho/PahoComponent.java
index 1a8e4a5..47cb4fe 100644
--- a/components/camel-paho/src/main/java/org/apache/camel/component/paho/PahoComponent.java
+++ b/components/camel-paho/src/main/java/org/apache/camel/component/paho/PahoComponent.java
@@ -32,7 +32,7 @@ public class PahoComponent extends UriEndpointComponent {
     private String clientId;
     @Metadata(label = "advanced")
     private MqttConnectOptions connectOptions;
-
+    
     public PahoComponent() {
         super(PahoEndpoint.class);
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/9c7a8f30/components/camel-paho/src/main/java/org/apache/camel/component/paho/PahoEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-paho/src/main/java/org/apache/camel/component/paho/PahoEndpoint.java b/components/camel-paho/src/main/java/org/apache/camel/component/paho/PahoEndpoint.java
index 16af7d1..3416ea8 100644
--- a/components/camel-paho/src/main/java/org/apache/camel/component/paho/PahoEndpoint.java
+++ b/components/camel-paho/src/main/java/org/apache/camel/component/paho/PahoEndpoint.java
@@ -63,6 +63,11 @@ public class PahoEndpoint extends DefaultEndpoint {
     private String filePersistenceDirectory;
     @UriParam(defaultValue = "true")
     private boolean autoReconnect = true; 
+    @UriParam @Metadata(secret = true)
+    private String userName; 
+    @UriParam @Metadata(secret = true)
+    private String password; 
+    
 
     // Collaboration members
     @UriParam
@@ -140,6 +145,11 @@ public class PahoEndpoint extends DefaultEndpoint {
         
         MqttConnectOptions options = new MqttConnectOptions();
         options.setAutomaticReconnect(autoReconnect);
+        
+        if(!"".equals(userName) && !"".equals(password)) {
+            options.setUserName(userName);
+            options.setPassword(password.toCharArray());
+        }
         return options;
     }
 
@@ -271,4 +281,28 @@ public class PahoEndpoint extends DefaultEndpoint {
         this.autoReconnect = autoReconnect;
     }
 
+    public String getUserName() {
+        return userName;
+    }
+
+    /**
+     * Username to be used for authentication against the MQTT broker
+     * @param userName
+     */
+    public void setUserName(String userName) {
+        this.userName = userName;
+    }
+
+    public String getPassword() {
+        return password;
+    }
+
+    /**
+     * Password to be used for authentication against the MQTT broker
+     * @param password
+     */
+    public void setPassword(String password) {
+        this.password = password;
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/9c7a8f30/components/camel-paho/src/test/java/org/apache/camel/component/paho/PahoComponentTest.java
----------------------------------------------------------------------
diff --git a/components/camel-paho/src/test/java/org/apache/camel/component/paho/PahoComponentTest.java b/components/camel-paho/src/test/java/org/apache/camel/component/paho/PahoComponentTest.java
index 27f0ed8..f7de2c7 100644
--- a/components/camel-paho/src/test/java/org/apache/camel/component/paho/PahoComponentTest.java
+++ b/components/camel-paho/src/test/java/org/apache/camel/component/paho/PahoComponentTest.java
@@ -211,4 +211,16 @@ public class PahoComponentTest extends CamelTestSupport {
         testCustomizedPahoMock.assertIsSatisfied();
     }
 
+    @Test
+    public void shouldNotSendMessageAuthIsNotValid() throws InterruptedException {
+        // Given
+        mock.expectedMessageCount(0);
+
+        // When
+        template.sendBody("paho:someRandomQueue?brokerUrl=tcp://localhost:" + mqttPort+"&userName=test&password=test", "msg");
+
+        // Then
+        mock.assertIsSatisfied();
+    }
+    
 }