[jboss-cvs] JBoss Messaging SVN: r5799 - trunk/tests/src/org/jboss/messaging/tests/integration/security.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Feb 3 09:49:31 EST 2009


Author: jmesnil
Date: 2009-02-03 09:49:31 -0500 (Tue, 03 Feb 2009)
New Revision: 5799

Added:
   trunk/tests/src/org/jboss/messaging/tests/integration/security/MinaSecurityClientTest.java
   trunk/tests/src/org/jboss/messaging/tests/integration/security/NettySecurityClientTest.java
   trunk/tests/src/org/jboss/messaging/tests/integration/security/SecurityManagerClientTestBase.java
   trunk/tests/src/org/jboss/messaging/tests/integration/security/SimpleClient.java
Removed:
   trunk/tests/src/org/jboss/messaging/tests/integration/security/RestrictedSecurityClientTest.java
Log:
JBMESSAGING-806: Allow JBM client to run in a jnlp (or other) sandbox

* refactored the tests to run a simple client (producing/consuming a message) with and without security manager
* tests with a security manager are disabled until bugs are fixed in the network libraries (both MINA & Netty)

Added: trunk/tests/src/org/jboss/messaging/tests/integration/security/MinaSecurityClientTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/security/MinaSecurityClientTest.java	                        (rev 0)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/security/MinaSecurityClientTest.java	2009-02-03 14:49:31 UTC (rev 5799)
@@ -0,0 +1,68 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005-2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.messaging.tests.integration.security;
+
+import org.jboss.messaging.integration.transports.mina.MinaAcceptorFactory;
+import org.jboss.messaging.integration.transports.mina.MinaConnectorFactory;
+
+/**
+ * A MinaSecurityClientTest
+ *
+ * @author <a href="jmesnil at redhat.com">Jeff Mesnil</a>
+ */
+public class MinaSecurityClientTest extends SecurityManagerClientTestBase
+{
+
+   // Constants -----------------------------------------------------
+
+   // Attributes ----------------------------------------------------
+
+   // Static --------------------------------------------------------
+
+   // Constructors --------------------------------------------------
+
+   // Public --------------------------------------------------------
+
+   // SecurityManagerClientTestBase overrides -----------------------
+
+   @Override
+   protected String getAcceptorFactoryClassName()
+   {
+      return MinaAcceptorFactory.class.getName();
+   }
+
+   @Override
+   protected String getConnectorFactoryClassName()
+   {
+      return MinaConnectorFactory.class.getName();
+   }
+
+   // Package protected ---------------------------------------------
+
+   // Protected -----------------------------------------------------
+
+   // Private -------------------------------------------------------
+
+   // Inner classes -------------------------------------------------
+
+}

Added: trunk/tests/src/org/jboss/messaging/tests/integration/security/NettySecurityClientTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/security/NettySecurityClientTest.java	                        (rev 0)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/security/NettySecurityClientTest.java	2009-02-03 14:49:31 UTC (rev 5799)
@@ -0,0 +1,68 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005-2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.messaging.tests.integration.security;
+
+import org.jboss.messaging.integration.transports.netty.NettyAcceptorFactory;
+import org.jboss.messaging.integration.transports.netty.NettyConnectorFactory;
+
+/**
+ * A NettySecurityClientTest
+ *
+ * @author <a href="jmesnil at redhat.com">Jeff Mesnil</a>
+ */
+public class NettySecurityClientTest extends SecurityManagerClientTestBase
+{
+
+   // Constants -----------------------------------------------------
+
+   // Attributes ----------------------------------------------------
+
+   // Static --------------------------------------------------------
+
+   // Constructors --------------------------------------------------
+
+   // Public --------------------------------------------------------
+
+   // SecurityManagerClientTestBase overrides -----------------------
+
+   @Override
+   protected String getAcceptorFactoryClassName()
+   {
+      return NettyAcceptorFactory.class.getName();
+   }
+
+   @Override
+   protected String getConnectorFactoryClassName()
+   {
+      return NettyConnectorFactory.class.getName();
+   }
+
+   // Package protected ---------------------------------------------
+
+   // Protected -----------------------------------------------------
+
+   // Private -------------------------------------------------------
+
+   // Inner classes -------------------------------------------------
+
+}

Deleted: trunk/tests/src/org/jboss/messaging/tests/integration/security/RestrictedSecurityClientTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/security/RestrictedSecurityClientTest.java	2009-02-03 13:38:56 UTC (rev 5798)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/security/RestrictedSecurityClientTest.java	2009-02-03 14:49:31 UTC (rev 5799)
@@ -1,141 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005-2008, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */ 
-
-package org.jboss.messaging.tests.integration.security;
-
-import static org.jboss.messaging.tests.util.RandomUtil.randomSimpleString;
-import static org.jboss.messaging.tests.util.RandomUtil.randomString;
-
-import java.net.URL;
-
-import junit.framework.Test;
-import junit.framework.TestCase;
-
-import org.jboss.messaging.core.client.ClientConsumer;
-import org.jboss.messaging.core.client.ClientSession;
-import org.jboss.messaging.core.client.ClientSessionFactory;
-import org.jboss.messaging.core.client.impl.ClientSessionFactoryImpl;
-import org.jboss.messaging.core.config.TransportConfiguration;
-import org.jboss.messaging.core.config.impl.ConfigurationImpl;
-import org.jboss.messaging.core.logging.Logger;
-import org.jboss.messaging.core.message.Message;
-import org.jboss.messaging.core.server.Messaging;
-import org.jboss.messaging.core.server.MessagingService;
-import org.jboss.messaging.integration.transports.netty.NettyAcceptorFactory;
-import org.jboss.messaging.integration.transports.netty.NettyConnectorFactory;
-import org.jboss.messaging.tests.integration.clientcrash.GracefulClient;
-import org.jboss.messaging.tests.util.SpawnedVMSupport;
-import org.jboss.messaging.util.SimpleString;
-
-/**
- * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>
- */
-public class RestrictedSecurityClientTest extends TestCase
-{
-   // Constants ------------------------------------------------------------------------------------
-
-   private static final String MESSAGE_TEXT = randomString();
-   
-   private static final SimpleString QUEUE = randomSimpleString();
-      
-   // Static ---------------------------------------------------------------------------------------
-
-   private static final Logger log = Logger.getLogger(RestrictedSecurityClientTest.class);
-
-   // Attributes -----------------------------------------------------------------------------------
-
-   private MessagingService messagingService;
-
-   private ClientSession session;
-
-   private ClientConsumer consumer;   
-
-   // Constructors ---------------------------------------------------------------------------------
-
-   // Public ---------------------------------------------------------------------------------------
-
-   public void testDummy() throws Exception
-   {
-      
-   }
-   
-//   public void testRestrictedSecurityClient() throws Exception
-//   {
-//      String policyFile = "restricted-security-client.policy";
-//      URL policyFileURL = Thread.currentThread().getContextClassLoader().getResource(policyFile);
-//      assertNotNull(policyFileURL);
-//      // spawn a JVM that creates a client with a restrictive security manager which sends a test message
-//      Process p = SpawnedVMSupport.spawnVM(GracefulClient.class.getName(), 
-//                                           new String[] {"-Djava.security.manager", 
-//                                                         "-Djava.security.policy==" + policyFileURL.getPath()},
-//                                           new String[] {QUEUE.toString(), MESSAGE_TEXT});
-//
-//      // read the message from the queue
-//      Message message = consumer.receive(15000);
-//
-//      assertNotNull("did not receive message from the spawned client", message);
-//      assertEquals(MESSAGE_TEXT, message.getBody().getString());
-//
-//      // the client VM should exit by itself. If it doesn't, that means we have a problem
-//      // and the test will timeout
-//      log.debug("waiting for the client VM to exit ...");
-//      p.waitFor();
-//
-//      assertEquals(0, p.exitValue());
-//   }
-
-   // Package protected ----------------------------------------------------------------------------
-
-   @Override
-   protected void setUp() throws Exception
-   {
-      ConfigurationImpl config = new ConfigurationImpl();
-      config.setSecurityEnabled(false);
-      config.getAcceptorConfigurations().add(new TransportConfiguration(NettyAcceptorFactory.class.getName()));
-      messagingService = Messaging.newNullStorageMessagingService(config);
-      messagingService.start();
-
-      ClientSessionFactory sf = new ClientSessionFactoryImpl(new TransportConfiguration(NettyConnectorFactory.class.getName()));
-      session = sf.createSession(false, true, true);
-      session.createQueue(QUEUE, QUEUE, null, false, false);
-      consumer = session.createConsumer(QUEUE);
-      session.start();
-   }
-
-   @Override
-   protected void tearDown() throws Exception
-   {
-      consumer.close();
-      session.close();
-
-      messagingService.stop();
-
-      super.tearDown();
-   }
-   
-   // Protected ------------------------------------------------------------------------------------
-
-   // Private --------------------------------------------------------------------------------------
-
-   // Inner classes --------------------------------------------------------------------------------
-
-}

Copied: trunk/tests/src/org/jboss/messaging/tests/integration/security/SecurityManagerClientTestBase.java (from rev 5775, trunk/tests/src/org/jboss/messaging/tests/integration/security/RestrictedSecurityClientTest.java)
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/security/SecurityManagerClientTestBase.java	                        (rev 0)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/security/SecurityManagerClientTestBase.java	2009-02-03 14:49:31 UTC (rev 5799)
@@ -0,0 +1,119 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005-2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.messaging.tests.integration.security;
+
+import junit.framework.TestCase;
+
+import org.jboss.messaging.core.config.TransportConfiguration;
+import org.jboss.messaging.core.config.impl.ConfigurationImpl;
+import org.jboss.messaging.core.logging.Logger;
+import org.jboss.messaging.core.server.Messaging;
+import org.jboss.messaging.core.server.MessagingService;
+import org.jboss.messaging.tests.util.SpawnedVMSupport;
+
+/**
+ * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>
+ */
+public abstract class SecurityManagerClientTestBase extends TestCase
+{
+   // Constants ------------------------------------------------------------------------------------
+
+   private static final Logger log = Logger.getLogger(SecurityManagerClientTestBase.class);
+
+   // Static ---------------------------------------------------------------------------------------
+
+   // Attributes -----------------------------------------------------------------------------------
+
+   private MessagingService messagingService;
+
+   // Constructors ---------------------------------------------------------------------------------
+
+   // Public ---------------------------------------------------------------------------------------
+
+   public void testProducerConsumerClientWithoutSecurityManager() throws Exception
+   {
+      doTestProducerConsumerClient(false);
+   }
+
+   // disabled tests waiting for fixes on network libraries:
+   // https://jira.jboss.org/jira/browse/NETTY-115 -> fixed in netty 3.1.0.alpha4
+   // https://issues.apache.org/jira/browse/DIRMINA-659
+   public void _testProducerConsumerClientWithSecurityManager() throws Exception
+   {
+      doTestProducerConsumerClient(true);
+   }
+
+   // Package protected ----------------------------------------------------------------------------
+
+   @Override
+   protected void setUp() throws Exception
+   {
+      super.setUp();
+
+      ConfigurationImpl config = new ConfigurationImpl();
+      config.setSecurityEnabled(false);
+      config.getAcceptorConfigurations().add(new TransportConfiguration(getAcceptorFactoryClassName()));
+      messagingService = Messaging.newNullStorageMessagingService(config);
+      messagingService.start();
+   }
+
+   @Override
+   protected void tearDown() throws Exception
+   {
+      messagingService.stop();
+
+      super.tearDown();
+   }
+
+   // Protected ------------------------------------------------------------------------------------
+
+   protected abstract String getAcceptorFactoryClassName();
+
+   protected abstract String getConnectorFactoryClassName();
+
+   // Private --------------------------------------------------------------------------------------
+
+   private void doTestProducerConsumerClient(boolean withSecurityManager) throws Exception
+   {
+      String[] vmargs = new String[0];
+      if (withSecurityManager)
+      {
+         vmargs = new String[] { "-Djava.security.manager" };
+      }
+
+      // spawn a JVM that creates a client withor without a security manager which sends and receives a test message
+      Process p = SpawnedVMSupport.spawnVM(SimpleClient.class.getName(),
+                                           vmargs,
+                                           new String[] { getConnectorFactoryClassName() });
+
+      // the client VM should exit by itself. If it doesn't, that means we have a problem
+      // and the test will timeout
+      log.debug("waiting for the client VM to exit ...");
+      p.waitFor();
+
+      assertEquals("client VM did not exit cleanly", 0, p.exitValue());
+   }
+
+   // Inner classes --------------------------------------------------------------------------------
+
+}


Property changes on: trunk/tests/src/org/jboss/messaging/tests/integration/security/SecurityManagerClientTestBase.java
___________________________________________________________________
Name: svn:mergeinfo
   + 

Added: trunk/tests/src/org/jboss/messaging/tests/integration/security/SimpleClient.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/security/SimpleClient.java	                        (rev 0)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/security/SimpleClient.java	2009-02-03 14:49:31 UTC (rev 5799)
@@ -0,0 +1,120 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005-2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.messaging.tests.integration.security;
+
+import static org.jboss.messaging.tests.util.RandomUtil.randomString;
+
+import org.jboss.messaging.core.client.ClientConsumer;
+import org.jboss.messaging.core.client.ClientMessage;
+import org.jboss.messaging.core.client.ClientProducer;
+import org.jboss.messaging.core.client.ClientSession;
+import org.jboss.messaging.core.client.ClientSessionFactory;
+import org.jboss.messaging.core.client.impl.ClientSessionFactoryImpl;
+import org.jboss.messaging.core.config.TransportConfiguration;
+import org.jboss.messaging.core.logging.Logger;
+import org.jboss.messaging.jms.client.JBossTextMessage;
+
+/**
+ * Code to be run in an external VM, via main().
+ *
+ * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>
+ *
+ */
+public class SimpleClient
+{
+   // Constants ------------------------------------------------------------------------------------
+
+   private static final Logger log = Logger.getLogger(SimpleClient.class);
+
+   // Static ---------------------------------------------------------------------------------------
+
+   public static void main(String[] args) throws Exception
+   {
+      try
+      {
+
+         if (args.length != 1)
+         {
+            throw new Exception("require 1 argument: connector factory class name");
+         }
+         String connectorFactoryClassName = args[0];
+
+         String queueName = randomString();
+         String messageText = randomString();
+
+         ClientSessionFactory sf = new ClientSessionFactoryImpl(new TransportConfiguration(connectorFactoryClassName));
+         ClientSession session = sf.createSession(false, true, true);
+         
+         session.createQueue(queueName, queueName, null, false, false);
+         ClientProducer producer = session.createProducer(queueName);
+         ClientConsumer consumer = session.createConsumer(queueName);
+
+         ClientMessage message = session.createClientMessage(JBossTextMessage.TYPE,
+                                                             false,
+                                                             0,
+                                                             System.currentTimeMillis(),
+                                                             (byte)1);
+         message.getBody().putString(messageText);
+         producer.send(message);
+
+         session.start();
+
+         ClientMessage receivedMsg = consumer.receive(5000);
+         if (receivedMsg == null)
+         {
+            throw new Exception("did not receive the message");
+         }
+         
+         String text = receivedMsg.getBody().getString();
+         if (text == null || !text.equals(messageText))
+         {
+            throw new Exception("received " + text + ", was expecting " + messageText);
+         }
+
+         // clean all resources to exit cleanly
+         consumer.close();
+         session.deleteQueue(queueName);         
+         session.close();
+      }
+      catch (Throwable t)
+      {
+         log.error(t.getMessage(), t);
+         System.exit(1);
+      }
+   }
+
+   // Attributes -----------------------------------------------------------------------------------
+
+   // Constructors ---------------------------------------------------------------------------------
+
+   // Public ---------------------------------------------------------------------------------------
+
+   // Package protected ----------------------------------------------------------------------------
+
+   // Protected ------------------------------------------------------------------------------------
+
+   // Private --------------------------------------------------------------------------------------
+
+   // Inner classes --------------------------------------------------------------------------------
+
+}




More information about the jboss-cvs-commits mailing list