activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cepo...@apache.org
Subject git commit: Fix for https://issues.apache.org/jira/browse/AMQ-4695 where user could not subscribe anonymously even though authn and authz was set up for it
Date Tue, 03 Sep 2013 19:05:22 GMT
Updated Branches:
  refs/heads/trunk a3a22efb2 -> a63a8320e


Fix for https://issues.apache.org/jira/browse/AMQ-4695 where user could not subscribe anonymously
even though authn and authz was set up for it


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

Branch: refs/heads/trunk
Commit: a63a8320eabbe4e988b6d67eb6cf84aa0d294e0a
Parents: a3a22ef
Author: Christian Posta <christian.posta@gmail.com>
Authored: Tue Sep 3 12:03:02 2013 -0700
Committer: Christian Posta <christian.posta@gmail.com>
Committed: Tue Sep 3 12:05:00 2013 -0700

----------------------------------------------------------------------
 .../transport/mqtt/MQTTProtocolConverter.java   |  4 +-
 .../activemq/transport/mqtt/MQTTNioTest.java    | 49 ++++++++++++++++++++
 2 files changed, 51 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq/blob/a63a8320/activemq-mqtt/src/main/java/org/apache/activemq/transport/mqtt/MQTTProtocolConverter.java
----------------------------------------------------------------------
diff --git a/activemq-mqtt/src/main/java/org/apache/activemq/transport/mqtt/MQTTProtocolConverter.java
b/activemq-mqtt/src/main/java/org/apache/activemq/transport/mqtt/MQTTProtocolConverter.java
index 2abc741..ac598e7 100644
--- a/activemq-mqtt/src/main/java/org/apache/activemq/transport/mqtt/MQTTProtocolConverter.java
+++ b/activemq-mqtt/src/main/java/org/apache/activemq/transport/mqtt/MQTTProtocolConverter.java
@@ -209,11 +209,11 @@ public class MQTTProtocolConverter {
             clientId = connect.clientId().toString();
         }
 
-        String userName = "";
+        String userName = null;
         if (connect.userName() != null) {
             userName = connect.userName().toString();
         }
-        String passswd = "";
+        String passswd = null;
         if (connect.password() != null) {
             passswd = connect.password().toString();
         }

http://git-wip-us.apache.org/repos/asf/activemq/blob/a63a8320/activemq-mqtt/src/test/java/org/apache/activemq/transport/mqtt/MQTTNioTest.java
----------------------------------------------------------------------
diff --git a/activemq-mqtt/src/test/java/org/apache/activemq/transport/mqtt/MQTTNioTest.java
b/activemq-mqtt/src/test/java/org/apache/activemq/transport/mqtt/MQTTNioTest.java
index b0d5914..b64a84f 100644
--- a/activemq-mqtt/src/test/java/org/apache/activemq/transport/mqtt/MQTTNioTest.java
+++ b/activemq-mqtt/src/test/java/org/apache/activemq/transport/mqtt/MQTTNioTest.java
@@ -16,11 +16,18 @@
  */
 package org.apache.activemq.transport.mqtt;
 
+import org.apache.activemq.broker.BrokerPlugin;
+import org.apache.activemq.broker.BrokerService;
+import org.apache.activemq.command.ActiveMQTopic;
+import org.apache.activemq.filter.DestinationMapEntry;
+import org.apache.activemq.security.*;
 import org.apache.activemq.util.Wait;
 import org.fusesource.mqtt.client.BlockingConnection;
 import org.fusesource.mqtt.client.MQTT;
 import org.junit.Test;
 
+import java.util.LinkedList;
+
 import static org.junit.Assert.assertTrue;
 
 public class MQTTNioTest extends MQTTTest {
@@ -35,6 +42,7 @@ public class MQTTNioTest extends MQTTTest {
         addMQTTConnector("maxInactivityDuration=-1");
         brokerService.start();
         MQTT mqtt = createMQTTConnection();
+        mqtt.setClientId("test-mqtt");
         mqtt.setKeepAlive((short)2);
         final BlockingConnection connection = mqtt.blockingConnection();
         connection.connect();
@@ -49,4 +57,45 @@ public class MQTTNioTest extends MQTTTest {
         connection.disconnect();
     }
 
+    @Test
+    public void testAnonymousUserConnect() throws Exception {
+        addMQTTConnector();
+        configureAuthentication(brokerService);
+        brokerService.start();
+        brokerService.waitUntilStarted();
+        MQTT mqtt = createMQTTConnection();
+        mqtt.setCleanSession(true);
+        mqtt.setUserName((String)null);
+        mqtt.setPassword((String)null);
+        final BlockingConnection connection = mqtt.blockingConnection();
+        connection.connect();
+
+        System.out.println("Connected!");
+
+        connection.disconnect();
+
+    }
+
+    private void configureAuthentication(BrokerService brokerService) throws Exception {
+        LinkedList<AuthenticationUser> users = new LinkedList<AuthenticationUser>();
+        users.add(new AuthenticationUser("user1", "user1", "anonymous,user1group"));
+        final SimpleAuthenticationPlugin authenticationPlugin = new SimpleAuthenticationPlugin(users);
+
+        DefaultAuthorizationMap map = new DefaultAuthorizationMap();
+        LinkedList<DestinationMapEntry> authz = new LinkedList<DestinationMapEntry>();
+        AuthorizationEntry entry = new AuthorizationEntry();
+        entry.setDestination(new ActiveMQTopic(">"));
+        entry.setAdmin("admins");
+        entry.setRead("admins,anonymous");
+        entry.setWrite("admins");
+        authz.add(entry);
+        map.setAuthorizationEntries(authz);
+        AuthorizationPlugin authorizationPlugin = new AuthorizationPlugin(map);
+        authenticationPlugin.setAnonymousAccessAllowed(true);
+
+        brokerService.setPlugins(new BrokerPlugin[]{
+                authenticationPlugin, authorizationPlugin
+        });
+    }
+
 }


Mime
View raw message