activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dej...@apache.org
Subject git commit: https://issues.apache.org/jira/browse/AMQ-5160 - test for retained messages wildcard security issue
Date Tue, 06 May 2014 09:44:36 GMT
Repository: activemq
Updated Branches:
  refs/heads/trunk 541ed8cf0 -> 64baf092f


https://issues.apache.org/jira/browse/AMQ-5160 - test for retained messages wildcard security
issue


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

Branch: refs/heads/trunk
Commit: 64baf092f073f8c2256a2f2ed704f708562d65a5
Parents: 541ed8c
Author: Dejan Bosanac <dejan@nighttale.net>
Authored: Tue May 6 11:44:07 2014 +0200
Committer: Dejan Bosanac <dejan@nighttale.net>
Committed: Tue May 6 11:44:28 2014 +0200

----------------------------------------------------------------------
 .../activemq/transport/mqtt/MQTTTest.java       | 64 +++++++++++++++++---
 1 file changed, 55 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq/blob/64baf092/activemq-mqtt/src/test/java/org/apache/activemq/transport/mqtt/MQTTTest.java
----------------------------------------------------------------------
diff --git a/activemq-mqtt/src/test/java/org/apache/activemq/transport/mqtt/MQTTTest.java
b/activemq-mqtt/src/test/java/org/apache/activemq/transport/mqtt/MQTTTest.java
index 17ad1e4..3143cfc 100644
--- a/activemq-mqtt/src/test/java/org/apache/activemq/transport/mqtt/MQTTTest.java
+++ b/activemq-mqtt/src/test/java/org/apache/activemq/transport/mqtt/MQTTTest.java
@@ -20,11 +20,7 @@ import static org.junit.Assert.assertArrayEquals;
 import static org.junit.Assert.assertNotEquals;
 
 import java.net.ProtocolException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Map;
-import java.util.Random;
+import java.util.*;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.TimeUnit;
@@ -44,11 +40,9 @@ import org.apache.activemq.broker.BrokerPlugin;
 import org.apache.activemq.broker.TransportConnector;
 import org.apache.activemq.command.ActiveMQMessage;
 import org.apache.activemq.command.ActiveMQTopic;
+import org.apache.activemq.filter.DestinationMapEntry;
 import org.apache.activemq.jaas.GroupPrincipal;
-import org.apache.activemq.security.AuthorizationPlugin;
-import org.apache.activemq.security.DefaultAuthorizationMap;
-import org.apache.activemq.security.SimpleAuthenticationPlugin;
-import org.apache.activemq.security.SimpleAuthorizationMap;
+import org.apache.activemq.security.*;
 import org.apache.activemq.util.ByteSequence;
 import org.apache.activemq.util.Wait;
 import org.fusesource.mqtt.client.BlockingConnection;
@@ -1294,6 +1288,58 @@ public class MQTTTest extends AbstractMQTTTest {
         connection.disconnect();
     }
 
+    @Test(timeout = 60 * 1000)
+    public void testWildcardRetainedSubscription() throws Exception {
+        addMQTTConnector();
+
+        LinkedList<AuthenticationUser> users = new LinkedList<AuthenticationUser>();
+        users.add(new AuthenticationUser("user", "user", "users"));
+        users.add(new AuthenticationUser("admin", "admin", "admins"));
+        final SimpleAuthenticationPlugin authenticationPlugin = new SimpleAuthenticationPlugin(users);
+
+
+        DefaultAuthorizationMap map = new DefaultAuthorizationMap();
+        LinkedList<DestinationMapEntry> authz = new LinkedList<DestinationMapEntry>();
+
+        AuthorizationEntry entryOne = new AuthorizationEntry();
+        entryOne.setDestination(new ActiveMQTopic("one"));
+        entryOne.setAdmin("admins");
+        entryOne.setRead("admins");
+        entryOne.setWrite("admins");
+        authz.add(entryOne);
+
+        AuthorizationEntry entryTwo = new AuthorizationEntry();
+        entryTwo.setDestination(new ActiveMQTopic("two"));
+        entryTwo.setAdmin("users");
+        entryTwo.setRead("users");
+        entryTwo.setWrite("users");
+        authz.add(entryTwo);
+
+        map.setAuthorizationEntries(authz);
+        AuthorizationPlugin authorizationPlugin = new AuthorizationPlugin(map);
+
+        brokerService.setPlugins(new BrokerPlugin[] { authorizationPlugin, authenticationPlugin
});
+
+        brokerService.start();
+
+        MQTT mqttPub = createMQTTConnection("pub", true);
+        mqttPub.setUserName("admin");
+        mqttPub.setPassword("admin");
+
+        BlockingConnection connectionPub = mqttPub.blockingConnection();
+        connectionPub.connect();
+        connectionPub.publish("one", "test".getBytes(), QoS.AT_LEAST_ONCE, true);
+
+        MQTT mqttSub = createMQTTConnection("sub", true);
+        mqttSub.setUserName("user");
+        mqttSub.setPassword("user");
+        BlockingConnection connectionSub = mqttSub.blockingConnection();
+        connectionSub.connect();
+        connectionSub.subscribe(new Topic[]{new Topic("#", QoS.AT_LEAST_ONCE)});
+        Message msg = connectionSub.receive(1, TimeUnit.SECONDS);
+        assertNull("Shouldn't receive the message", msg);
+    }
+
     @Override
     protected String getProtocolScheme() {
         return "mqtt";


Mime
View raw message