activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From clebertsuco...@apache.org
Subject [1/2] activemq-artemis git commit: NO-JIRA: added unit test for setting the user and password in the uri for tcp transport, used in JNDI
Date Tue, 13 Dec 2016 14:21:48 GMT
Repository: activemq-artemis
Updated Branches:
  refs/heads/master 52e4fc4a5 -> 2f70007e8


NO-JIRA: added unit test for setting the user and password in the uri for tcp transport, used
in JNDI


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

Branch: refs/heads/master
Commit: c38c5a91aa1cd169bfdd75c3d84acd8604cfb3e7
Parents: 52e4fc4
Author: Pat Fox <pfox@redhat.com>
Authored: Wed Dec 7 14:22:20 2016 +0100
Committer: Clebert Suconic <clebertsuconic@apache.org>
Committed: Tue Dec 13 09:20:29 2016 -0500

----------------------------------------------------------------------
 .../integration/jms/SimpleJNDIClientTest.java   | 64 +++++++++++++++++++-
 1 file changed, 63 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/c38c5a91/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/jms/SimpleJNDIClientTest.java
----------------------------------------------------------------------
diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/jms/SimpleJNDIClientTest.java
b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/jms/SimpleJNDIClientTest.java
index 7865e13..fa75356 100644
--- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/jms/SimpleJNDIClientTest.java
+++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/jms/SimpleJNDIClientTest.java
@@ -16,19 +16,26 @@
  */
 package org.apache.activemq.artemis.tests.integration.jms;
 
+import javax.jms.Connection;
 import javax.jms.ConnectionFactory;
 import javax.jms.Destination;
 import javax.jms.JMSException;
+import javax.jms.JMSSecurityException;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageProducer;
 import javax.jms.Queue;
+import javax.jms.Session;
 import javax.jms.Topic;
 import javax.naming.Context;
 import javax.naming.InitialContext;
 import javax.naming.NamingException;
 import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.Hashtable;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 
 import org.apache.activemq.artemis.api.config.ActiveMQDefaultConfiguration;
 import org.apache.activemq.artemis.api.core.BroadcastEndpoint;
@@ -43,10 +50,12 @@ import org.apache.activemq.artemis.api.jms.JMSFactoryType;
 import org.apache.activemq.artemis.core.config.Configuration;
 import org.apache.activemq.artemis.core.config.ha.SharedStoreMasterPolicyConfiguration;
 import org.apache.activemq.artemis.core.remoting.impl.netty.TransportConstants;
+import org.apache.activemq.artemis.core.security.Role;
 import org.apache.activemq.artemis.core.server.ActiveMQServer;
 import org.apache.activemq.artemis.core.server.ActiveMQServers;
 import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory;
 import org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory;
+import org.apache.activemq.artemis.spi.core.security.ActiveMQJAASSecurityManager;
 import org.apache.activemq.artemis.tests.util.ActiveMQTestBase;
 import org.junit.Assert;
 import org.junit.Before;
@@ -401,7 +410,7 @@ public class SimpleJNDIClientTest extends ActiveMQTestBase {
       Map<String, Object> params = new HashMap<>();
       params.put(org.apache.activemq.artemis.core.remoting.impl.invm.TransportConstants.SERVER_ID_PROP_NAME,
1);
 
-      Configuration liveConf = createBasicConfig().addAcceptorConfiguration(new TransportConfiguration(INVM_ACCEPTOR_FACTORY)).addAcceptorConfiguration(new
TransportConfiguration(INVM_ACCEPTOR_FACTORY, params)).addAcceptorConfiguration(new TransportConfiguration(NETTY_ACCEPTOR_FACTORY)).setConnectorConfigurations(connectors).setHAPolicyConfiguration(new
SharedStoreMasterPolicyConfiguration());
+      Configuration liveConf = createBasicConfig().addAcceptorConfiguration(new TransportConfiguration(INVM_ACCEPTOR_FACTORY)).addAcceptorConfiguration(new
TransportConfiguration(INVM_ACCEPTOR_FACTORY, params)).addAcceptorConfiguration(new TransportConfiguration(NETTY_ACCEPTOR_FACTORY)).setConnectorConfigurations(connectors).setHAPolicyConfiguration(new
SharedStoreMasterPolicyConfiguration()).setSecurityEnabled(true);
 
       final long broadcastPeriod = 250;
 
@@ -416,6 +425,8 @@ public class SimpleJNDIClientTest extends ActiveMQTestBase {
       liveConf.setBroadcastGroupConfigurations(bcConfigs1);
 
       liveService = addServer(ActiveMQServers.newActiveMQServer(liveConf, false));
+      ((ActiveMQJAASSecurityManager) liveService.getSecurityManager()).getConfiguration().addUser("guest",
"guest");
+      ((ActiveMQJAASSecurityManager) liveService.getSecurityManager()).getConfiguration().setDefaultUser("guest");
       liveService.start();
    }
 
@@ -468,4 +479,55 @@ public class SimpleJNDIClientTest extends ActiveMQTestBase {
       Destination destination = (Destination) ctx.lookup("dynamicTopics/myTopic");
       Assert.assertTrue(destination instanceof Topic);
    }
+
+   @Test
+   public void testRemoteCFWithTCPUserPassword() throws Exception {
+
+
+      //setup user and role on broker
+      ((ActiveMQJAASSecurityManager) liveService.getSecurityManager()).getConfiguration().addUser("myUser",
"myPassword");
+      ((ActiveMQJAASSecurityManager) liveService.getSecurityManager()).getConfiguration().addRole("myUser",
"consumeCreateRole");
+      Role consumeCreateRole = new Role("consumeCreateRole", false, true, true, true, true,
true, true, true);
+      Set<Role> consumerCreateRoles = new HashSet<>();
+      consumerCreateRoles.add(consumeCreateRole);
+      liveService.getSecurityRepository().addMatch("test.queue", consumerCreateRoles);
+
+      Hashtable<String, String> props = new Hashtable<>();
+      props.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory");
+
+      //user and password set on URL
+      props.put("connectionFactory.myConnectionFactory", "tcp://127.0.0.1:61616?user=myUser&password=myPassword");
+      Context ctx = new InitialContext(props);
+
+
+      //create a connection factory
+      ActiveMQConnectionFactory connectionFactory = (ActiveMQConnectionFactory) ctx.lookup("myConnectionFactory");
+      Assert.assertEquals("ensure user is set","myUser", connectionFactory.getUser());
+      Assert.assertEquals("ensure password is set", "myPassword",connectionFactory.getPassword());
+
+
+      //Connect to broker to verify credentials are used with connection
+      Connection connection = connectionFactory.createConnection();
+      connection.start();
+      Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+      javax.jms.Queue queue = session.createQueue("test.queue");
+
+      try {
+
+         try {
+            MessageProducer producer = session.createProducer(queue);
+            producer.send(session.createTextMessage("test Msg"));
+            Assert.fail("Sending message should throw a JMSSecurityException");
+         }catch (JMSSecurityException e) {
+          //expected
+         }
+
+         MessageConsumer consumer = session.createConsumer(queue);
+
+      } finally {
+        connection.close();
+     }
+
+   }
 }


Mime
View raw message