Author: borges
Date: 2011-12-06 07:38:34 -0500 (Tue, 06 Dec 2011)
New Revision: 11856
Modified:
trunk/tests/integration-tests/src/test/java/org/hornetq/tests/integration/client/RoutingTest.java
trunk/tests/integration-tests/src/test/java/org/hornetq/tests/integration/client/SelfExpandingBufferTest.java
trunk/tests/integration-tests/src/test/java/org/hornetq/tests/integration/client/ServerLocatorConnectTest.java
trunk/tests/integration-tests/src/test/java/org/hornetq/tests/integration/scheduling/ScheduledMessageTest.java
trunk/tests/integration-tests/src/test/java/org/hornetq/tests/integration/security/SecurityTest.java
Log:
Delete more unnecessary tearDown() code
Modified:
trunk/tests/integration-tests/src/test/java/org/hornetq/tests/integration/client/RoutingTest.java
===================================================================
---
trunk/tests/integration-tests/src/test/java/org/hornetq/tests/integration/client/RoutingTest.java 2011-12-06
12:03:29 UTC (rev 11855)
+++
trunk/tests/integration-tests/src/test/java/org/hornetq/tests/integration/client/RoutingTest.java 2011-12-06
12:38:34 UTC (rev 11856)
@@ -15,7 +15,12 @@
import junit.framework.Assert;
import org.hornetq.api.core.SimpleString;
-import org.hornetq.api.core.client.*;
+import org.hornetq.api.core.client.ClientConsumer;
+import org.hornetq.api.core.client.ClientMessage;
+import org.hornetq.api.core.client.ClientProducer;
+import org.hornetq.api.core.client.ClientSession;
+import org.hornetq.api.core.client.ClientSessionFactory;
+import org.hornetq.api.core.client.ServerLocator;
import org.hornetq.core.server.HornetQServer;
import org.hornetq.tests.util.ServiceTestBase;
@@ -25,39 +30,27 @@
public class RoutingTest extends ServiceTestBase
{
public final SimpleString addressA = new SimpleString("addressA");
-
public final SimpleString queueA = new SimpleString("queueA");
-
public final SimpleString queueB = new SimpleString("queueB");
-
public final SimpleString queueC = new SimpleString("queueC");
private ServerLocator locator;
+ private HornetQServer server;
+ private ClientSessionFactory cf;
@Override
protected void setUp() throws Exception
{
super.setUp();
-
locator = createInVMNonHALocator();
- }
+ server = createServer(false);
- @Override
- protected void tearDown() throws Exception
- {
- locator.close();
-
- super.tearDown();
+ server.start();
+ cf = createSessionFactory(locator);
}
public void testRouteToMultipleQueues() throws Exception
{
- HornetQServer server = createServer(false);
-
- try
- {
- server.start();
- ClientSessionFactory cf = locator.createSessionFactory();
ClientSession sendSession = cf.createSession(false, true, true);
sendSession.createQueue(addressA, queueA, false);
sendSession.createQueue(addressA, queueB, false);
@@ -90,24 +83,10 @@
Assert.assertNull(c3.receiveImmediate());
sendSession.close();
session.close();
- }
- finally
- {
- if (server.isStarted())
- {
- server.stop();
- }
- }
}
public void testRouteToSingleNonDurableQueue() throws Exception
{
- HornetQServer server = createServer(false);
-
- try
- {
- server.start();
- ClientSessionFactory cf = locator.createSessionFactory();
ClientSession sendSession = cf.createSession(false, true, true);
sendSession.createQueue(addressA, queueA, false);
int numMessages = 300;
@@ -128,25 +107,11 @@
Assert.assertNull(c1.receiveImmediate());
sendSession.close();
session.close();
- }
- finally
- {
- if (server.isStarted())
- {
- server.stop();
- }
- }
}
public void testRouteToSingleDurableQueue() throws Exception
{
- HornetQServer server = createServer(false);
-
- try
- {
- server.start();
- ClientSessionFactory cf = locator.createSessionFactory();
- ClientSession sendSession = cf.createSession(false, true, true);
+ ClientSession sendSession = cf.createSession(false, true, true);
sendSession.createQueue(addressA, queueA, true);
int numMessages = 300;
ClientProducer p = sendSession.createProducer(addressA);
@@ -166,25 +131,11 @@
Assert.assertNull(c1.receiveImmediate());
sendSession.close();
session.close();
- }
- finally
- {
- if (server.isStarted())
- {
- server.stop();
- }
- }
}
public void testRouteToSingleQueueWithFilter() throws Exception
{
- HornetQServer server = createServer(false);
-
- try
- {
- server.start();
- ClientSessionFactory cf = locator.createSessionFactory();
- ClientSession sendSession = cf.createSession(false, true, true);
+ ClientSession sendSession = cf.createSession(false, true, true);
sendSession.createQueue(addressA, queueA, new SimpleString("foo =
'bar'"), false);
int numMessages = 300;
ClientProducer p = sendSession.createProducer(addressA);
@@ -206,25 +157,11 @@
Assert.assertNull(c1.receiveImmediate());
sendSession.close();
session.close();
- }
- finally
- {
- if (server.isStarted())
- {
- server.stop();
- }
- }
}
public void testRouteToMultipleQueueWithFilters() throws Exception
{
- HornetQServer server = createServer(false);
-
- try
- {
- server.start();
- ClientSessionFactory cf = locator.createSessionFactory();
- ClientSession sendSession = cf.createSession(false, true, true);
+ ClientSession sendSession = cf.createSession(false, true, true);
sendSession.createQueue(addressA, queueA, new SimpleString("foo =
'bar'"), false);
sendSession.createQueue(addressA, queueB, new SimpleString("x = 1"),
false);
sendSession.createQueue(addressA, queueC, new SimpleString("b =
false"), false);
@@ -269,25 +206,11 @@
Assert.assertNull(c3.receiveImmediate());
sendSession.close();
session.close();
- }
- finally
- {
- if (server.isStarted())
- {
- server.stop();
- }
- }
}
public void testRouteToSingleTemporaryQueue() throws Exception
{
- HornetQServer server = createServer(false);
-
- try
- {
- server.start();
- ClientSessionFactory cf = locator.createSessionFactory();
- ClientSession sendSession = cf.createSession(false, true, true);
+ ClientSession sendSession = cf.createSession(false, true, true);
sendSession.createTemporaryQueue(addressA, queueA);
int numMessages = 300;
ClientProducer p = sendSession.createProducer(addressA);
@@ -307,14 +230,5 @@
Assert.assertNull(c1.receiveImmediate());
sendSession.close();
session.close();
- }
- finally
- {
- if (server.isStarted())
- {
- server.stop();
- }
- }
}
-
}
Modified:
trunk/tests/integration-tests/src/test/java/org/hornetq/tests/integration/client/SelfExpandingBufferTest.java
===================================================================
---
trunk/tests/integration-tests/src/test/java/org/hornetq/tests/integration/client/SelfExpandingBufferTest.java 2011-12-06
12:03:29 UTC (rev 11855)
+++
trunk/tests/integration-tests/src/test/java/org/hornetq/tests/integration/client/SelfExpandingBufferTest.java 2011-12-06
12:38:34 UTC (rev 11856)
@@ -17,7 +17,12 @@
import org.hornetq.api.core.HornetQBuffer;
import org.hornetq.api.core.SimpleString;
-import org.hornetq.api.core.client.*;
+import org.hornetq.api.core.client.ClientConsumer;
+import org.hornetq.api.core.client.ClientMessage;
+import org.hornetq.api.core.client.ClientProducer;
+import org.hornetq.api.core.client.ClientSession;
+import org.hornetq.api.core.client.ClientSessionFactory;
+import org.hornetq.api.core.client.ServerLocator;
import org.hornetq.core.logging.Logger;
import org.hornetq.core.server.HornetQServer;
import org.hornetq.tests.util.RandomUtil;
@@ -28,7 +33,7 @@
* A SelfExpandingBufferTest
*
* @author <a href="mailto:clebert.suconic@jboss.org">Clebert
Suconic</a>
- *
+ *
* Created Feb 23, 2009 4:27:16 PM
*
*
@@ -80,7 +85,7 @@
ServerLocator locator = createFactory(netty);
- factory = locator.createSessionFactory();
+ factory = createSessionFactory(locator);
ClientSession session = factory.createSession(false, true, true);
@@ -118,9 +123,9 @@
byte[] receivedBytes = new byte[bytes.length];
// log.info("buffer start pos should be at " +
PacketImpl.PACKET_HEADERS_SIZE + DataConstants.SIZE_INT);
- //
+ //
// log.info("buffer pos at " + msg2.getBodyBuffer().readerIndex());
- //
+ //
// log.info("buffer length should be " +
msg2.getBodyBuffer().readInt(PacketImpl.PACKET_HEADERS_SIZE));
msg2.getBodyBuffer().readBytes(receivedBytes);
@@ -138,7 +143,6 @@
finally
{
session.close();
- locator.close();
}
}
@@ -151,22 +155,4 @@
service = createServer(persistent, createDefaultConfig(netty));
service.start();
}
-
- @Override
- protected void tearDown() throws Exception
- {
- if (service != null && service.isStarted())
- {
- service.stop();
- }
-
- service = null;
-
- super.tearDown();
- }
-
- // Private -------------------------------------------------------
-
- // Inner classes -------------------------------------------------
-
}
Modified:
trunk/tests/integration-tests/src/test/java/org/hornetq/tests/integration/client/ServerLocatorConnectTest.java
===================================================================
---
trunk/tests/integration-tests/src/test/java/org/hornetq/tests/integration/client/ServerLocatorConnectTest.java 2011-12-06
12:03:29 UTC (rev 11855)
+++
trunk/tests/integration-tests/src/test/java/org/hornetq/tests/integration/client/ServerLocatorConnectTest.java 2011-12-06
12:38:34 UTC (rev 11856)
@@ -13,6 +13,9 @@
package org.hornetq.tests.integration.client;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
import org.hornetq.api.core.HornetQException;
import org.hornetq.api.core.client.ClientSessionFactory;
import org.hornetq.api.core.client.HornetQClient;
@@ -23,9 +26,6 @@
import org.hornetq.core.server.HornetQServer;
import org.hornetq.tests.util.ServiceTestBase;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.TimeUnit;
-
/**
* User: andy
* Date: Sep 15, 2010
@@ -45,16 +45,8 @@
server.start();
}
- @Override
- protected void tearDown() throws Exception
- {
- server.stop();
- super.tearDown();
- }
-
public void testSingleConnectorSingleServer() throws Exception
{
-
ServerLocator locator =
HornetQClient.createServerLocatorWithoutHA(createTransportConfiguration(isNetty(), false,
generateParams(0, isNetty())));
ClientSessionFactory csf = locator.createSessionFactory();
csf.close();
@@ -64,7 +56,7 @@
public void testSingleConnectorSingleServerConnect() throws Exception
{
ServerLocatorInternal locator = (ServerLocatorInternal)
HornetQClient.createServerLocatorWithoutHA(createTransportConfiguration(isNetty(), false,
generateParams(0, isNetty())));
- ClientSessionFactoryInternal csf = (ClientSessionFactoryInternal)
locator.connect();
+ ClientSessionFactoryInternal csf = locator.connect();
assertNotNull(csf);
assertEquals(csf.numConnections(), 1);
locator.close();
@@ -79,7 +71,7 @@
createTransportConfiguration(isNetty(), false, generateParams(3,
isNetty())),
createTransportConfiguration(isNetty(), false, generateParams(4, isNetty()))
);
- ClientSessionFactoryInternal csf = (ClientSessionFactoryInternal)
locator.connect();
+ ClientSessionFactoryInternal csf = locator.connect();
assertNotNull(csf);
assertEquals(csf.numConnections(), 1);
locator.close();
@@ -95,7 +87,7 @@
createTransportConfiguration(isNetty(), false, generateParams(4, isNetty()))
);
locator.setReconnectAttempts(-1);
- ClientSessionFactoryInternal csf = (ClientSessionFactoryInternal)
locator.connect();
+ ClientSessionFactoryInternal csf = locator.connect();
assertNotNull(csf);
assertEquals(csf.numConnections(), 1);
locator.close();
@@ -113,7 +105,7 @@
ClientSessionFactoryInternal csf = null;
try
{
- csf = (ClientSessionFactoryInternal) locator.connect();
+ csf = locator.connect();
}
catch (Exception e)
{
@@ -134,7 +126,6 @@
createTransportConfiguration(isNetty(), false, generateParams(5, isNetty()))
);
locator.setReconnectAttempts(-1);
- ClientSessionFactoryInternal csf = null;
CountDownLatch countDownLatch = new CountDownLatch(1);
Connector target = new Connector(locator, countDownLatch);
Thread t = new Thread(target);
@@ -153,7 +144,7 @@
static class Connector implements Runnable
{
- private ServerLocatorInternal locator;
+ private final ServerLocatorInternal locator;
ClientSessionFactory csf = null;
CountDownLatch latch;
Exception e;
Modified:
trunk/tests/integration-tests/src/test/java/org/hornetq/tests/integration/scheduling/ScheduledMessageTest.java
===================================================================
---
trunk/tests/integration-tests/src/test/java/org/hornetq/tests/integration/scheduling/ScheduledMessageTest.java 2011-12-06
12:03:29 UTC (rev 11855)
+++
trunk/tests/integration-tests/src/test/java/org/hornetq/tests/integration/scheduling/ScheduledMessageTest.java 2011-12-06
12:38:34 UTC (rev 11856)
@@ -22,7 +22,12 @@
import org.hornetq.api.core.Message;
import org.hornetq.api.core.SimpleString;
-import org.hornetq.api.core.client.*;
+import org.hornetq.api.core.client.ClientConsumer;
+import org.hornetq.api.core.client.ClientMessage;
+import org.hornetq.api.core.client.ClientProducer;
+import org.hornetq.api.core.client.ClientSession;
+import org.hornetq.api.core.client.ClientSessionFactory;
+import org.hornetq.api.core.client.ServerLocator;
import org.hornetq.core.config.Configuration;
import org.hornetq.core.logging.Logger;
import org.hornetq.core.server.HornetQServer;
@@ -72,26 +77,6 @@
locator = createInVMNonHALocator();
}
- @Override
- protected void tearDown() throws Exception
- {
- locator.close();
-
- if (server != null)
- {
- try
- {
- server.stop();
- server = null;
- }
- catch (Exception e)
- {
- // ignore
- }
- }
- super.tearDown();
- }
-
public void testRecoveredMessageDeliveredCorrectly() throws Exception
{
testMessageDeliveredCorrectly(true);
@@ -145,7 +130,7 @@
public void testPagedMessageDeliveredCorrectly() throws Exception
{
// then we create a client as normal
- ClientSessionFactory sessionFactory = locator.createSessionFactory();
+ ClientSessionFactory sessionFactory = createSessionFactory(locator);
ClientSession session = sessionFactory.createSession(false, true, false);
session.createQueue(atestq, atestq, null, true);
ClientProducer producer = session.createProducer(atestq);
@@ -181,7 +166,7 @@
qs.setRedeliveryDelay(5000l);
server.getAddressSettingsRepository().addMatch(atestq.toString(), qs);
// then we create a client as normal
- ClientSessionFactory sessionFactory = locator.createSessionFactory();
+ ClientSessionFactory sessionFactory = createSessionFactory(locator);
ClientSession session = sessionFactory.createSession(false, true, false);
session.createQueue(atestq, atestq, null, true);
session.createQueue(atestq, atestq2, null, true);
@@ -230,7 +215,7 @@
qs.setRedeliveryDelay(5000l);
server.getAddressSettingsRepository().addMatch(atestq.toString(), qs);
// then we create a client as normal
- ClientSessionFactory sessionFactory = locator.createSessionFactory();
+ ClientSessionFactory sessionFactory = createSessionFactory(locator);
ClientSession session = sessionFactory.createSession(false, true, false);
session.createQueue(atestq, atestq, null, true);
session.createQueue(atestq, atestq2, null, true);
@@ -260,7 +245,7 @@
server = null;
server = createServer(true, configuration);
server.start();
- sessionFactory = locator.createSessionFactory();
+ sessionFactory = createSessionFactory(locator);
session = sessionFactory.createSession(false, true, true);
consumer = session.createConsumer(atestq);
consumer2 = session.createConsumer(atestq2);
@@ -289,7 +274,7 @@
{
// then we create a client as normal
- ClientSessionFactory sessionFactory = locator.createSessionFactory();
+ ClientSessionFactory sessionFactory = createSessionFactory(locator);
ClientSession session = sessionFactory.createSession(false, true, false);
session.createQueue(atestq, atestq, null, true);
ClientProducer producer = session.createProducer(atestq);
@@ -314,7 +299,7 @@
server = null;
server = createServer(true, configuration);
server.start();
- sessionFactory = locator.createSessionFactory();
+ sessionFactory = createSessionFactory(locator);
session = sessionFactory.createSession(false, true, true);
}
ClientConsumer consumer = session.createConsumer(atestq);
@@ -338,7 +323,7 @@
public void testScheduledMessagesDeliveredCorrectly(final boolean recover) throws
Exception
{
- ClientSessionFactory sessionFactory = locator.createSessionFactory();
+ ClientSessionFactory sessionFactory = createSessionFactory(locator);
ClientSession session = sessionFactory.createSession(false, true, false);
session.createQueue(atestq, atestq, null, true);
ClientProducer producer = session.createProducer(atestq);
@@ -373,7 +358,7 @@
server = createServer(true, configuration);
server.start();
- sessionFactory = locator.createSessionFactory();
+ sessionFactory = createSessionFactory(locator);
session = sessionFactory.createSession(false, true, true);
}
@@ -418,7 +403,7 @@
public void testScheduledMessagesDeliveredCorrectlyDifferentOrder(final boolean
recover) throws Exception
{
- ClientSessionFactory sessionFactory = locator.createSessionFactory();
+ ClientSessionFactory sessionFactory = createSessionFactory(locator);
ClientSession session = sessionFactory.createSession(false, true, false);
session.createQueue(atestq, atestq, null, true);
ClientProducer producer = session.createProducer(atestq);
@@ -454,7 +439,7 @@
server = createServer(true, configuration);
server.start();
- sessionFactory = locator.createSessionFactory();
+ sessionFactory = createSessionFactory(locator);
session = sessionFactory.createSession(false, true, true);
@@ -500,13 +485,13 @@
public void testManyMessagesSameTime() throws Exception
{
- ClientSessionFactory sessionFactory = locator.createSessionFactory();
+ ClientSessionFactory sessionFactory = createSessionFactory(locator);
ClientSession session = sessionFactory.createSession(false, false, false);
session.createQueue(atestq, atestq, null, true);
ClientProducer producer = session.createProducer(atestq);
long time = System.currentTimeMillis();
time += 1000;
-
+
for (int i = 0; i < 1000; i++)
{
ClientMessage message = session.createMessage(true);
@@ -514,22 +499,22 @@
message.putLongProperty(Message.HDR_SCHEDULED_DELIVERY_TIME, time);
producer.send(message);
}
-
+
session.commit();
-
-
+
+
session.start();
ClientConsumer consumer = session.createConsumer(atestq);
-
+
for (int i = 0 ; i < 1000; i++)
{
ClientMessage message = consumer.receive(15000);
assertNotNull(message);
message.acknowledge();
-
+
assertEquals(i, message.getIntProperty("value").intValue());
}
-
+
session.commit();
Assert.assertNull(consumer.receiveImmediate());
@@ -540,7 +525,7 @@
public void testScheduledAndNormalMessagesDeliveredCorrectly(final boolean recover)
throws Exception
{
- ClientSessionFactory sessionFactory = locator.createSessionFactory();
+ ClientSessionFactory sessionFactory = createSessionFactory(locator);
ClientSession session = sessionFactory.createSession(false, true, false);
session.createQueue(atestq, atestq, null, true);
ClientProducer producer = session.createProducer(atestq);
@@ -572,7 +557,7 @@
server = createServer(true, configuration);
server.start();
- sessionFactory = locator.createSessionFactory();
+ sessionFactory = createSessionFactory(locator);
session = sessionFactory.createSession(false, true, true);
}
@@ -614,7 +599,7 @@
Xid xid = new XidImpl("xa1".getBytes(), 1,
UUIDGenerator.getInstance().generateStringUUID().getBytes());
Xid xid2 = new XidImpl("xa2".getBytes(), 1,
UUIDGenerator.getInstance().generateStringUUID().getBytes());
- ClientSessionFactory sessionFactory = locator.createSessionFactory();
+ ClientSessionFactory sessionFactory = createSessionFactory(locator);
ClientSession session = sessionFactory.createSession(true, false, false);
session.createQueue(atestq, atestq, null, true);
session.start(xid, XAResource.TMNOFLAGS);
@@ -634,7 +619,7 @@
server = createServer(true, configuration);
server.start();
- sessionFactory = locator.createSessionFactory();
+ sessionFactory = createSessionFactory(locator);
session = sessionFactory.createSession(true, false, false);
}
@@ -660,19 +645,19 @@
Assert.assertNull(consumer.receiveImmediate());
session.close();
}
-
-
+
+
public void testPendingACKOnPrepared() throws Exception
{
-
+
int NUMBER_OF_MESSAGES = 100;
-
- ClientSessionFactory sessionFactory = locator.createSessionFactory();
+
+ ClientSessionFactory sessionFactory = createSessionFactory(locator);
ClientSession session = sessionFactory.createSession(true, false, false);
session.createQueue(atestq, atestq, null, true);
ClientProducer producer = session.createProducer(atestq);
-
+
long scheduled = System.currentTimeMillis() + 1000;
for (int i = 0 ; i < NUMBER_OF_MESSAGES; i++)
{
@@ -681,51 +666,51 @@
msg.putLongProperty(Message.HDR_SCHEDULED_DELIVERY_TIME, scheduled);
producer.send(msg);
}
-
+
session.close();
-
-
+
+
for (int i = 0 ; i < NUMBER_OF_MESSAGES; i++)
{
Xid xid = newXID();
session = sessionFactory.createSession(true, false, false);
-
+
ClientConsumer consumer = session.createConsumer(atestq);
-
+
session.start();
session.start(xid, XAResource.TMNOFLAGS);
-
+
ClientMessage msg = consumer.receive(5000);
assertNotNull(msg);
msg.acknowledge();
session.end(xid, XAResource.TMSUCCESS);
-
+
session.prepare(xid);
-
+
session.close();
}
-
+
sessionFactory.close();
locator.close();
-
+
server.stop();
-
+
startServer();
-
- sessionFactory = locator.createSessionFactory();
-
+
+ sessionFactory = createSessionFactory(locator);
+
session = sessionFactory.createSession(false, false);
-
+
ClientConsumer consumer = session.createConsumer(atestq);
-
+
session.start();
-
+
assertNull(consumer.receive(1000));
-
+
session.close();
-
+
sessionFactory.close();
}
@@ -746,7 +731,7 @@
qs.setRedeliveryDelay(5000l);
server.getAddressSettingsRepository().addMatch(atestq.toString(), qs);
- ClientSessionFactory sessionFactory = locator.createSessionFactory();
+ ClientSessionFactory sessionFactory = createSessionFactory(locator);
ClientSession session = sessionFactory.createSession(false, false, false);
session.createQueue(atestq, atestq, true);
@@ -801,11 +786,12 @@
final AtomicInteger count = new AtomicInteger(0);
Thread t = new Thread()
{
+ @Override
public void run()
{
try
{
- ClientSessionFactory sf = locator.createSessionFactory();
+ ClientSessionFactory sf = createSessionFactory(locator);
ClientSession session = sf.createSession(false, false);
session.start();
ClientConsumer cons = session.createConsumer(atestq);
@@ -831,7 +817,7 @@
t.start();
- sessionFactory = locator.createSessionFactory();
+ sessionFactory = createSessionFactory(locator);
session = sessionFactory.createSession(true, false, false);
@@ -858,7 +844,7 @@
Xid xid = new XidImpl("xa1".getBytes(), 1,
UUIDGenerator.getInstance().generateStringUUID().getBytes());
- ClientSessionFactory sessionFactory = locator.createSessionFactory();
+ ClientSessionFactory sessionFactory = createSessionFactory(locator);
ClientSession session = sessionFactory.createSession(tx, false, false);
session.createQueue(atestq, atestq, null, true);
ClientProducer producer = session.createProducer(atestq);
Modified:
trunk/tests/integration-tests/src/test/java/org/hornetq/tests/integration/security/SecurityTest.java
===================================================================
---
trunk/tests/integration-tests/src/test/java/org/hornetq/tests/integration/security/SecurityTest.java 2011-12-06
12:03:29 UTC (rev 11855)
+++
trunk/tests/integration-tests/src/test/java/org/hornetq/tests/integration/security/SecurityTest.java 2011-12-06
12:38:34 UTC (rev 11856)
@@ -65,6 +65,7 @@
private ServerLocator locator;
+ private Configuration configuration;
@Override
protected void setUp() throws Exception
@@ -74,669 +75,456 @@
locator = createInVMNonHALocator();
}
- @Override
- protected void tearDown() throws Exception
- {
- locator.close();
-
- super.tearDown();
- }
-
public void testCreateSessionWithNullUserPass() throws Exception
{
- Configuration configuration = createDefaultConfig(false);
- configuration.setSecurityEnabled(true);
- HornetQServer server = createServer(false, configuration);
+ HornetQServer server = createServer();
HornetQSecurityManager securityManager = server.getSecurityManager();
securityManager.addUser("guest", "guest");
securityManager.setDefaultUser("guest");
+ server.start();
+ ClientSessionFactory cf = locator.createSessionFactory();
+
try
{
- server.start();
- ClientSessionFactory cf = locator.createSessionFactory();
+ ClientSession session = cf.createSession(false, true, true);
- try
- {
- ClientSession session = cf.createSession(false, true, true);
-
- session.close();
- }
- catch (HornetQException e)
- {
- Assert.fail("should not throw exception");
- }
+ session.close();
}
- finally
+ catch (HornetQException e)
{
- if (server.isStarted())
- {
- server.stop();
- }
+ Assert.fail("should not throw exception");
}
}
- public void testCreateSessionWithNullUserPassNoGuest() throws Exception
+ /**
+ * @return
+ */
+ private HornetQServer createServer()
{
- Configuration configuration = createDefaultConfig(false);
+ configuration = createDefaultConfig(false);
configuration.setSecurityEnabled(true);
HornetQServer server = createServer(false, configuration);
+ return server;
+ }
+
+ public void testCreateSessionWithNullUserPassNoGuest() throws Exception
+ {
+ HornetQServer server = createServer();
+ server.start();
+ ClientSessionFactory cf = locator.createSessionFactory();
try
{
- server.start();
- ClientSessionFactory cf = locator.createSessionFactory();
- try
- {
- cf.createSession(false, true, true);
- Assert.fail("should throw exception");
- }
- catch (HornetQException e)
- {
- Assert.assertEquals(HornetQException.SECURITY_EXCEPTION, e.getCode());
- }
+ cf.createSession(false, true, true);
+ Assert.fail("should throw exception");
}
- finally
+ catch (HornetQException e)
{
- if (server.isStarted())
- {
- server.stop();
- }
+ Assert.assertEquals(HornetQException.SECURITY_EXCEPTION, e.getCode());
}
}
public void testCreateSessionWithCorrectUserWrongPass() throws Exception
{
- Configuration configuration = createDefaultConfig(false);
- configuration.setSecurityEnabled(true);
- HornetQServer server = createServer(false, configuration);
+ HornetQServer server = createServer();
HornetQSecurityManager securityManager = server.getSecurityManager();
securityManager.addUser("newuser", "apass");
+ server.start();
+ ClientSessionFactory cf = locator.createSessionFactory();
+
try
{
- server.start();
- ClientSessionFactory cf = locator.createSessionFactory();
-
- try
- {
- cf.createSession("newuser", "awrongpass", false, true,
true, false, -1);
- Assert.fail("should not throw exception");
- }
- catch (HornetQException e)
- {
- Assert.assertEquals(HornetQException.SECURITY_EXCEPTION, e.getCode());
- }
+ cf.createSession("newuser", "awrongpass", false, true, true,
false, -1);
+ Assert.fail("should not throw exception");
}
- finally
+ catch (HornetQException e)
{
- if (server.isStarted())
- {
- server.stop();
- }
+ Assert.assertEquals(HornetQException.SECURITY_EXCEPTION, e.getCode());
}
}
public void testCreateSessionWithCorrectUserCorrectPass() throws Exception
{
- Configuration configuration = createDefaultConfig(false);
- configuration.setSecurityEnabled(true);
- HornetQServer server = createServer(false, configuration);
+ HornetQServer server = createServer();
HornetQSecurityManager securityManager = server.getSecurityManager();
securityManager.addUser("newuser", "apass");
+ server.start();
+ ClientSessionFactory cf = locator.createSessionFactory();
+
try
{
- server.start();
- ClientSessionFactory cf = locator.createSessionFactory();
+ ClientSession session = cf.createSession("newuser", "apass",
false, true, true, false, -1);
- try
- {
- ClientSession session = cf.createSession("newuser",
"apass", false, true, true, false, -1);
-
- session.close();
- }
- catch (HornetQException e)
- {
- Assert.fail("should not throw exception");
- }
+ session.close();
}
- finally
+ catch (HornetQException e)
{
- if (server.isStarted())
- {
- server.stop();
- }
+ Assert.fail("should not throw exception");
}
}
public void testCreateDurableQueueWithRole() throws Exception
{
- Configuration configuration = createDefaultConfig(false);
- configuration.setSecurityEnabled(true);
- HornetQServer server = createServer(false, configuration);
-
- try
- {
- server.start();
- HierarchicalRepository<Set<Role>> securityRepository =
server.getSecurityRepository();
- HornetQSecurityManager securityManager = server.getSecurityManager();
- securityManager.addUser("auser", "pass");
- Role role = new Role("arole", false, false, true, false, false, false,
false);
- Set<Role> roles = new HashSet<Role>();
- roles.add(role);
- securityRepository.addMatch(SecurityTest.addressA, roles);
- securityManager.addRole("auser", "arole");
- ClientSessionFactory cf = locator.createSessionFactory();
- ClientSession session = cf.createSession("auser", "pass",
false, true, true, false, -1);
- session.createQueue(SecurityTest.addressA, SecurityTest.queueA, true);
- session.close();
- }
- finally
- {
- if (server.isStarted())
- {
- server.stop();
- }
- }
+ HornetQServer server = createServer();
+ server.start();
+ HierarchicalRepository<Set<Role>> securityRepository =
server.getSecurityRepository();
+ HornetQSecurityManager securityManager = server.getSecurityManager();
+ securityManager.addUser("auser", "pass");
+ Role role = new Role("arole", false, false, true, false, false, false,
false);
+ Set<Role> roles = new HashSet<Role>();
+ roles.add(role);
+ securityRepository.addMatch(SecurityTest.addressA, roles);
+ securityManager.addRole("auser", "arole");
+ ClientSessionFactory cf = locator.createSessionFactory();
+ ClientSession session = cf.createSession("auser", "pass",
false, true, true, false, -1);
+ session.createQueue(SecurityTest.addressA, SecurityTest.queueA, true);
+ session.close();
}
public void testCreateDurableQueueWithoutRole() throws Exception
{
- Configuration configuration = createDefaultConfig(false);
- configuration.setSecurityEnabled(true);
- HornetQServer server = createServer(false, configuration);
+ HornetQServer server = createServer();
+ server.start();
+ HierarchicalRepository<Set<Role>> securityRepository =
server.getSecurityRepository();
+ HornetQSecurityManager securityManager = server.getSecurityManager();
+ securityManager.addUser("auser", "pass");
+ Role role = new Role("arole", false, false, false, false, false, false,
false);
+ Set<Role> roles = new HashSet<Role>();
+ roles.add(role);
+ securityRepository.addMatch(SecurityTest.addressA, roles);
+ securityManager.addRole("auser", "arole");
+ ClientSessionFactory cf = locator.createSessionFactory();
+ ClientSession session = cf.createSession("auser", "pass",
false, true, true, false, -1);
try
{
- server.start();
- HierarchicalRepository<Set<Role>> securityRepository =
server.getSecurityRepository();
- HornetQSecurityManager securityManager = server.getSecurityManager();
- securityManager.addUser("auser", "pass");
- Role role = new Role("arole", false, false, false, false, false,
false, false);
- Set<Role> roles = new HashSet<Role>();
- roles.add(role);
- securityRepository.addMatch(SecurityTest.addressA, roles);
- securityManager.addRole("auser", "arole");
- ClientSessionFactory cf = locator.createSessionFactory();
- ClientSession session = cf.createSession("auser", "pass",
false, true, true, false, -1);
- try
- {
- session.createQueue(SecurityTest.addressA, SecurityTest.queueA, true);
- Assert.fail("should throw exception");
- }
- catch (HornetQException e)
- {
- Assert.assertEquals(HornetQException.SECURITY_EXCEPTION, e.getCode());
- }
- session.close();
+ session.createQueue(SecurityTest.addressA, SecurityTest.queueA, true);
+ Assert.fail("should throw exception");
}
- finally
+ catch (HornetQException e)
{
- if (server.isStarted())
- {
- server.stop();
- }
+ Assert.assertEquals(HornetQException.SECURITY_EXCEPTION, e.getCode());
}
+ session.close();
}
public void testDeleteDurableQueueWithRole() throws Exception
{
- Configuration configuration = createDefaultConfig(false);
- configuration.setSecurityEnabled(true);
- HornetQServer server = createServer(false, configuration);
-
- try
- {
- server.start();
- HierarchicalRepository<Set<Role>> securityRepository =
server.getSecurityRepository();
- HornetQSecurityManager securityManager = server.getSecurityManager();
- securityManager.addUser("auser", "pass");
- Role role = new Role("arole", false, false, true, true, false, false,
false);
- Set<Role> roles = new HashSet<Role>();
- roles.add(role);
- securityRepository.addMatch(SecurityTest.addressA, roles);
- securityManager.addRole("auser", "arole");
- ClientSessionFactory cf = locator.createSessionFactory();
- ClientSession session = cf.createSession("auser", "pass",
false, true, true, false, -1);
- session.createQueue(SecurityTest.addressA, SecurityTest.queueA, true);
- session.deleteQueue(SecurityTest.queueA);
- session.close();
- }
- finally
- {
- if (server.isStarted())
- {
- server.stop();
- }
- }
+ HornetQServer server = createServer();
+ server.start();
+ HierarchicalRepository<Set<Role>> securityRepository =
server.getSecurityRepository();
+ HornetQSecurityManager securityManager = server.getSecurityManager();
+ securityManager.addUser("auser", "pass");
+ Role role = new Role("arole", false, false, true, true, false, false,
false);
+ Set<Role> roles = new HashSet<Role>();
+ roles.add(role);
+ securityRepository.addMatch(SecurityTest.addressA, roles);
+ securityManager.addRole("auser", "arole");
+ ClientSessionFactory cf = locator.createSessionFactory();
+ ClientSession session = cf.createSession("auser", "pass",
false, true, true, false, -1);
+ session.createQueue(SecurityTest.addressA, SecurityTest.queueA, true);
+ session.deleteQueue(SecurityTest.queueA);
+ session.close();
}
public void testDeleteDurableQueueWithoutRole() throws Exception
{
- Configuration configuration = createDefaultConfig(false);
- configuration.setSecurityEnabled(true);
- HornetQServer server = createServer(false, configuration);
-
+ HornetQServer server = createServer();
+ server.start();
+ HierarchicalRepository<Set<Role>> securityRepository =
server.getSecurityRepository();
+ HornetQSecurityManager securityManager = server.getSecurityManager();
+ securityManager.addUser("auser", "pass");
+ Role role = new Role("arole", false, false, true, false, false, false,
false);
+ Set<Role> roles = new HashSet<Role>();
+ roles.add(role);
+ securityRepository.addMatch(SecurityTest.addressA, roles);
+ securityManager.addRole("auser", "arole");
+ ClientSessionFactory cf = locator.createSessionFactory();
+ ClientSession session = cf.createSession("auser", "pass",
false, true, true, false, -1);
+ session.createQueue(SecurityTest.addressA, SecurityTest.queueA, true);
try
{
- server.start();
- HierarchicalRepository<Set<Role>> securityRepository =
server.getSecurityRepository();
- HornetQSecurityManager securityManager = server.getSecurityManager();
- securityManager.addUser("auser", "pass");
- Role role = new Role("arole", false, false, true, false, false, false,
false);
- Set<Role> roles = new HashSet<Role>();
- roles.add(role);
- securityRepository.addMatch(SecurityTest.addressA, roles);
- securityManager.addRole("auser", "arole");
- ClientSessionFactory cf = locator.createSessionFactory();
- ClientSession session = cf.createSession("auser", "pass",
false, true, true, false, -1);
- session.createQueue(SecurityTest.addressA, SecurityTest.queueA, true);
- try
- {
- session.deleteQueue(SecurityTest.queueA);
- Assert.fail("should throw exception");
- }
- catch (HornetQException e)
- {
- Assert.assertEquals(HornetQException.SECURITY_EXCEPTION, e.getCode());
- }
- session.close();
+ session.deleteQueue(SecurityTest.queueA);
+ Assert.fail("should throw exception");
}
- finally
+ catch (HornetQException e)
{
- if (server.isStarted())
- {
- server.stop();
- }
+ Assert.assertEquals(HornetQException.SECURITY_EXCEPTION, e.getCode());
}
+ session.close();
}
public void testCreateTempQueueWithRole() throws Exception
{
- Configuration configuration = createDefaultConfig(false);
- configuration.setSecurityEnabled(true);
- HornetQServer server = createServer(false, configuration);
+ HornetQServer server = createServer();
- try
- {
- server.start();
- HierarchicalRepository<Set<Role>> securityRepository =
server.getSecurityRepository();
- HornetQSecurityManager securityManager = server.getSecurityManager();
- securityManager.addUser("auser", "pass");
- Role role = new Role("arole", false, false, false, false, true, false,
false);
- Set<Role> roles = new HashSet<Role>();
- roles.add(role);
- securityRepository.addMatch(SecurityTest.addressA, roles);
- securityManager.addRole("auser", "arole");
- ClientSessionFactory cf = locator.createSessionFactory();
- ClientSession session = cf.createSession("auser", "pass",
false, true, true, false, -1);
- session.createQueue(SecurityTest.addressA, SecurityTest.queueA, false);
- session.close();
- }
- finally
- {
- if (server.isStarted())
- {
- server.stop();
- }
- }
+ server.start();
+ HierarchicalRepository<Set<Role>> securityRepository =
server.getSecurityRepository();
+ HornetQSecurityManager securityManager = server.getSecurityManager();
+ securityManager.addUser("auser", "pass");
+ Role role = new Role("arole", false, false, false, false, true, false,
false);
+ Set<Role> roles = new HashSet<Role>();
+ roles.add(role);
+ securityRepository.addMatch(SecurityTest.addressA, roles);
+ securityManager.addRole("auser", "arole");
+ ClientSessionFactory cf = locator.createSessionFactory();
+ ClientSession session = cf.createSession("auser", "pass",
false, true, true, false, -1);
+ session.createQueue(SecurityTest.addressA, SecurityTest.queueA, false);
+ session.close();
}
public void testCreateTempQueueWithoutRole() throws Exception
{
- Configuration configuration = createDefaultConfig(false);
- configuration.setSecurityEnabled(true);
- HornetQServer server = createServer(false, configuration);
+ HornetQServer server = createServer();
+ server.start();
+ HierarchicalRepository<Set<Role>> securityRepository =
server.getSecurityRepository();
+ HornetQSecurityManager securityManager = server.getSecurityManager();
+ securityManager.addUser("auser", "pass");
+ Role role = new Role("arole", false, false, false, false, false, false,
false);
+ Set<Role> roles = new HashSet<Role>();
+ roles.add(role);
+ securityRepository.addMatch(SecurityTest.addressA, roles);
+ securityManager.addRole("auser", "arole");
+ ClientSessionFactory cf = locator.createSessionFactory();
+ ClientSession session = cf.createSession("auser", "pass",
false, true, true, false, -1);
try
{
- server.start();
- HierarchicalRepository<Set<Role>> securityRepository =
server.getSecurityRepository();
- HornetQSecurityManager securityManager = server.getSecurityManager();
- securityManager.addUser("auser", "pass");
- Role role = new Role("arole", false, false, false, false, false,
false, false);
- Set<Role> roles = new HashSet<Role>();
- roles.add(role);
- securityRepository.addMatch(SecurityTest.addressA, roles);
- securityManager.addRole("auser", "arole");
- ClientSessionFactory cf = locator.createSessionFactory();
- ClientSession session = cf.createSession("auser", "pass",
false, true, true, false, -1);
- try
- {
- session.createQueue(SecurityTest.addressA, SecurityTest.queueA, false);
- Assert.fail("should throw exception");
- }
- catch (HornetQException e)
- {
- Assert.assertEquals(HornetQException.SECURITY_EXCEPTION, e.getCode());
- }
- session.close();
+ session.createQueue(SecurityTest.addressA, SecurityTest.queueA, false);
+ Assert.fail("should throw exception");
}
- finally
+ catch (HornetQException e)
{
- if (server.isStarted())
- {
- server.stop();
- }
+ Assert.assertEquals(HornetQException.SECURITY_EXCEPTION, e.getCode());
}
+ session.close();
}
public void testDeleteTempQueueWithRole() throws Exception
{
- Configuration configuration = createDefaultConfig(false);
- configuration.setSecurityEnabled(true);
- HornetQServer server = createServer(false, configuration);
-
- try
- {
- server.start();
- HierarchicalRepository<Set<Role>> securityRepository =
server.getSecurityRepository();
- HornetQSecurityManager securityManager = server.getSecurityManager();
- securityManager.addUser("auser", "pass");
- Role role = new Role("arole", false, false, false, false, true, true,
false);
- Set<Role> roles = new HashSet<Role>();
- roles.add(role);
- securityRepository.addMatch(SecurityTest.addressA, roles);
- securityManager.addRole("auser", "arole");
- ClientSessionFactory cf = locator.createSessionFactory();
- ClientSession session = cf.createSession("auser", "pass",
false, true, true, false, -1);
- session.createQueue(SecurityTest.addressA, SecurityTest.queueA, false);
- session.deleteQueue(SecurityTest.queueA);
- session.close();
- }
- finally
- {
- if (server.isStarted())
- {
- server.stop();
- }
- }
+ HornetQServer server = createServer();
+ server.start();
+ HierarchicalRepository<Set<Role>> securityRepository =
server.getSecurityRepository();
+ HornetQSecurityManager securityManager = server.getSecurityManager();
+ securityManager.addUser("auser", "pass");
+ Role role = new Role("arole", false, false, false, false, true, true,
false);
+ Set<Role> roles = new HashSet<Role>();
+ roles.add(role);
+ securityRepository.addMatch(SecurityTest.addressA, roles);
+ securityManager.addRole("auser", "arole");
+ ClientSessionFactory cf = locator.createSessionFactory();
+ ClientSession session = cf.createSession("auser", "pass",
false, true, true, false, -1);
+ session.createQueue(SecurityTest.addressA, SecurityTest.queueA, false);
+ session.deleteQueue(SecurityTest.queueA);
+ session.close();
}
public void testDeleteTempQueueWithoutRole() throws Exception
{
- Configuration configuration = createDefaultConfig(false);
- configuration.setSecurityEnabled(true);
- HornetQServer server = createServer(false, configuration);
-
+ HornetQServer server = createServer();
+ server.start();
+ HierarchicalRepository<Set<Role>> securityRepository =
server.getSecurityRepository();
+ HornetQSecurityManager securityManager = server.getSecurityManager();
+ securityManager.addUser("auser", "pass");
+ Role role = new Role("arole", false, false, false, false, true, false,
false);
+ Set<Role> roles = new HashSet<Role>();
+ roles.add(role);
+ securityRepository.addMatch(SecurityTest.addressA, roles);
+ securityManager.addRole("auser", "arole");
+ ClientSessionFactory cf = locator.createSessionFactory();
+ ClientSession session = cf.createSession("auser", "pass",
false, true, true, false, -1);
+ session.createQueue(SecurityTest.addressA, SecurityTest.queueA, false);
try
{
- server.start();
- HierarchicalRepository<Set<Role>> securityRepository =
server.getSecurityRepository();
- HornetQSecurityManager securityManager = server.getSecurityManager();
- securityManager.addUser("auser", "pass");
- Role role = new Role("arole", false, false, false, false, true, false,
false);
- Set<Role> roles = new HashSet<Role>();
- roles.add(role);
- securityRepository.addMatch(SecurityTest.addressA, roles);
- securityManager.addRole("auser", "arole");
- ClientSessionFactory cf = locator.createSessionFactory();
- ClientSession session = cf.createSession("auser", "pass",
false, true, true, false, -1);
- session.createQueue(SecurityTest.addressA, SecurityTest.queueA, false);
- try
- {
- session.deleteQueue(SecurityTest.queueA);
- Assert.fail("should throw exception");
- }
- catch (HornetQException e)
- {
- Assert.assertEquals(HornetQException.SECURITY_EXCEPTION, e.getCode());
- }
- session.close();
+ session.deleteQueue(SecurityTest.queueA);
+ Assert.fail("should throw exception");
}
- finally
+ catch (HornetQException e)
{
- if (server.isStarted())
- {
- server.stop();
- }
+ Assert.assertEquals(HornetQException.SECURITY_EXCEPTION, e.getCode());
}
+ session.close();
}
public void testSendWithRole() throws Exception
{
- Configuration configuration = createDefaultConfig(false);
- configuration.setSecurityEnabled(true);
- HornetQServer server = createServer(false, configuration);
+ HornetQServer server = createServer();
- try
- {
- server.start();
+ server.start();
- HierarchicalRepository<Set<Role>> securityRepository =
server.getSecurityRepository();
+ HierarchicalRepository<Set<Role>> securityRepository =
server.getSecurityRepository();
- HornetQSecurityManager securityManager = server.getSecurityManager();
+ HornetQSecurityManager securityManager = server.getSecurityManager();
- securityManager.addUser("auser", "pass");
+ securityManager.addUser("auser", "pass");
- Role role = new Role("arole", true, true, true, false, false, false,
false);
+ Role role = new Role("arole", true, true, true, false, false, false,
false);
- Set<Role> roles = new HashSet<Role>();
+ Set<Role> roles = new HashSet<Role>();
- roles.add(role);
+ roles.add(role);
- securityRepository.addMatch(SecurityTest.addressA, roles);
+ securityRepository.addMatch(SecurityTest.addressA, roles);
- securityManager.addRole("auser", "arole");
+ securityManager.addRole("auser", "arole");
- locator.setBlockOnNonDurableSend(true);
+ locator.setBlockOnNonDurableSend(true);
- ClientSessionFactory cf = locator.createSessionFactory();
+ ClientSessionFactory cf = locator.createSessionFactory();
- ClientSession session = cf.createSession("auser", "pass",
false, true, true, false, -1);
+ ClientSession session = cf.createSession("auser", "pass",
false, true, true, false, -1);
- session.createQueue(SecurityTest.addressA, SecurityTest.queueA, true);
+ session.createQueue(SecurityTest.addressA, SecurityTest.queueA, true);
- ClientProducer cp = session.createProducer(SecurityTest.addressA);
+ ClientProducer cp = session.createProducer(SecurityTest.addressA);
- cp.send(session.createMessage(false));
+ cp.send(session.createMessage(false));
- session.start();
+ session.start();
- ClientConsumer cons = session.createConsumer(queueA);
+ ClientConsumer cons = session.createConsumer(queueA);
- ClientMessage receivedMessage = cons.receive(5000);
+ ClientMessage receivedMessage = cons.receive(5000);
- assertNotNull(receivedMessage);
+ assertNotNull(receivedMessage);
- receivedMessage.acknowledge();
+ receivedMessage.acknowledge();
- role = new Role("arole", false, false, true, false, false, false,
false);
+ role = new Role("arole", false, false, true, false, false, false,
false);
- roles = new HashSet<Role>();
+ roles = new HashSet<Role>();
- roles.add(role);
+ roles.add(role);
-
- // This was added to validate
https://issues.jboss.org/browse/SOA-3363
- securityRepository.addMatch(SecurityTest.addressA, roles);
- boolean failed = false;
- try
- {
- cp.send(session.createMessage(true));
- }
- catch (HornetQException e)
- {
- failed = true;
- }
- // This was added to validate
https://issues.jboss.org/browse/SOA-3363 ^^^^^
-
- assertTrue("Failure expected on send after removing the match",
failed);
-
-
- session.close();
-
+ // This was added to validate
https://issues.jboss.org/browse/SOA-3363
+ securityRepository.addMatch(SecurityTest.addressA, roles);
+ boolean failed = false;
+ try
+ {
+ cp.send(session.createMessage(true));
}
- finally
+ catch (HornetQException e)
{
- if (server.isStarted())
- {
- server.stop();
- }
+ failed = true;
}
+ // This was added to validate
https://issues.jboss.org/browse/SOA-3363 ^^^^^
+
+ assertTrue("Failure expected on send after removing the match", failed);
}
public void testSendWithoutRole() throws Exception
{
- Configuration configuration = createDefaultConfig(false);
- configuration.setSecurityEnabled(true);
- HornetQServer server = createServer(false, configuration);
+ HornetQServer server = createServer();
+ server.start();
+ HierarchicalRepository<Set<Role>> securityRepository =
server.getSecurityRepository();
+ HornetQSecurityManager securityManager = server.getSecurityManager();
+ securityManager.addUser("auser", "pass");
+ Role role = new Role("arole", false, false, true, false, false, false,
false);
+ Set<Role> roles = new HashSet<Role>();
+ roles.add(role);
+ securityRepository.addMatch(SecurityTest.addressA, roles);
+ securityManager.addRole("auser", "arole");
+ locator.setBlockOnNonDurableSend(true);
+ ClientSessionFactory cf = locator.createSessionFactory();
+ ClientSession session = cf.createSession("auser", "pass",
false, true, true, false, -1);
+ session.createQueue(SecurityTest.addressA, SecurityTest.queueA, true);
+ ClientProducer cp = session.createProducer(SecurityTest.addressA);
try
{
- server.start();
- HierarchicalRepository<Set<Role>> securityRepository =
server.getSecurityRepository();
- HornetQSecurityManager securityManager = server.getSecurityManager();
- securityManager.addUser("auser", "pass");
- Role role = new Role("arole", false, false, true, false, false, false,
false);
- Set<Role> roles = new HashSet<Role>();
- roles.add(role);
- securityRepository.addMatch(SecurityTest.addressA, roles);
- securityManager.addRole("auser", "arole");
- locator.setBlockOnNonDurableSend(true);
- ClientSessionFactory cf = locator.createSessionFactory();
- ClientSession session = cf.createSession("auser", "pass",
false, true, true, false, -1);
- session.createQueue(SecurityTest.addressA, SecurityTest.queueA, true);
- ClientProducer cp = session.createProducer(SecurityTest.addressA);
- try
- {
- cp.send(session.createMessage(false));
- }
- catch (HornetQException e)
- {
- Assert.assertEquals(HornetQException.SECURITY_EXCEPTION, e.getCode());
- }
- session.close();
+ cp.send(session.createMessage(false));
}
- finally
+ catch (HornetQException e)
{
- if (server.isStarted())
- {
- server.stop();
- }
+ Assert.assertEquals(HornetQException.SECURITY_EXCEPTION, e.getCode());
}
+ session.close();
}
public void testNonBlockSendWithoutRole() throws Exception
{
- Configuration configuration = createDefaultConfig(false);
- configuration.setSecurityEnabled(true);
- HornetQServer server = createServer(false, configuration);
+ HornetQServer server = createServer();
- try
- {
- server.start();
- HierarchicalRepository<Set<Role>> securityRepository =
server.getSecurityRepository();
- HornetQSecurityManager securityManager = server.getSecurityManager();
- securityManager.addUser("auser", "pass");
- Role role = new Role("arole", false, false, true, false, false, false,
false);
- Set<Role> roles = new HashSet<Role>();
- roles.add(role);
- securityRepository.addMatch(SecurityTest.addressA, roles);
- securityManager.addRole("auser", "arole");
- ClientSessionFactory cf = locator.createSessionFactory();
- ClientSession session = cf.createSession("auser", "pass",
false, true, true, false, -1);
- session.createQueue(SecurityTest.addressA, SecurityTest.queueA, true);
- ClientProducer cp = session.createProducer(SecurityTest.addressA);
- cp.send(session.createMessage(false));
- session.close();
+ server.start();
+ HierarchicalRepository<Set<Role>> securityRepository =
server.getSecurityRepository();
+ HornetQSecurityManager securityManager = server.getSecurityManager();
+ securityManager.addUser("auser", "pass");
+ Role role = new Role("arole", false, false, true, false, false, false,
false);
+ Set<Role> roles = new HashSet<Role>();
+ roles.add(role);
+ securityRepository.addMatch(SecurityTest.addressA, roles);
+ securityManager.addRole("auser", "arole");
+ ClientSessionFactory cf = locator.createSessionFactory();
+ ClientSession session = cf.createSession("auser", "pass",
false, true, true, false, -1);
+ session.createQueue(SecurityTest.addressA, SecurityTest.queueA, true);
+ ClientProducer cp = session.createProducer(SecurityTest.addressA);
+ cp.send(session.createMessage(false));
+ session.close();
- Queue binding = (Queue)server.getPostOffice().getBinding(new
SimpleString(SecurityTest.queueA)).getBindable();
- Assert.assertEquals(0, binding.getMessageCount());
- }
- finally
- {
- if (server.isStarted())
- {
- server.stop();
- }
- }
+ Queue binding = (Queue)server.getPostOffice().getBinding(new
SimpleString(SecurityTest.queueA)).getBindable();
+ Assert.assertEquals(0, binding.getMessageCount());
}
public void testCreateConsumerWithRole() throws Exception
{
- Configuration configuration = createDefaultConfig(false);
- configuration.setSecurityEnabled(true);
- HornetQServer server = createServer(false, configuration);
-
- try
- {
- server.start();
- HierarchicalRepository<Set<Role>> securityRepository =
server.getSecurityRepository();
- HornetQSecurityManager securityManager = server.getSecurityManager();
- securityManager.addUser("auser", "pass");
- securityManager.addUser("guest", "guest");
- securityManager.addRole("guest", "guest");
- securityManager.setDefaultUser("guest");
- Role role = new Role("arole", false, true, false, false, false, false,
false);
- Role sendRole = new Role("guest", true, false, true, false, false,
false, false);
- Set<Role> roles = new HashSet<Role>();
- roles.add(sendRole);
- roles.add(role);
- securityRepository.addMatch(SecurityTest.addressA, roles);
- securityManager.addRole("auser", "arole");
- ClientSessionFactory cf = locator.createSessionFactory();
- ClientSession senSession = cf.createSession(false, true, true);
- ClientSession session = cf.createSession("auser", "pass",
false, true, true, false, -1);
- senSession.createQueue(SecurityTest.addressA, SecurityTest.queueA, true);
- ClientProducer cp = senSession.createProducer(SecurityTest.addressA);
- cp.send(session.createMessage(false));
- session.createConsumer(SecurityTest.queueA);
- session.close();
- senSession.close();
- }
- finally
- {
- if (server.isStarted())
- {
- server.stop();
- }
- }
+ HornetQServer server = createServer();
+ server.start();
+ HierarchicalRepository<Set<Role>> securityRepository =
server.getSecurityRepository();
+ HornetQSecurityManager securityManager = server.getSecurityManager();
+ securityManager.addUser("auser", "pass");
+ securityManager.addUser("guest", "guest");
+ securityManager.addRole("guest", "guest");
+ securityManager.setDefaultUser("guest");
+ Role role = new Role("arole", false, true, false, false, false, false,
false);
+ Role sendRole = new Role("guest", true, false, true, false, false, false,
false);
+ Set<Role> roles = new HashSet<Role>();
+ roles.add(sendRole);
+ roles.add(role);
+ securityRepository.addMatch(SecurityTest.addressA, roles);
+ securityManager.addRole("auser", "arole");
+ ClientSessionFactory cf = locator.createSessionFactory();
+ ClientSession senSession = cf.createSession(false, true, true);
+ ClientSession session = cf.createSession("auser", "pass",
false, true, true, false, -1);
+ senSession.createQueue(SecurityTest.addressA, SecurityTest.queueA, true);
+ ClientProducer cp = senSession.createProducer(SecurityTest.addressA);
+ cp.send(session.createMessage(false));
+ session.createConsumer(SecurityTest.queueA);
+ session.close();
+ senSession.close();
}
public void testCreateConsumerWithoutRole() throws Exception
{
- Configuration configuration = createDefaultConfig(false);
- configuration.setSecurityEnabled(true);
- HornetQServer server = createServer(false, configuration);
-
+ HornetQServer server = createServer();
+ server.start();
+ HierarchicalRepository<Set<Role>> securityRepository =
server.getSecurityRepository();
+ HornetQSecurityManager securityManager = server.getSecurityManager();
+ securityManager.addUser("auser", "pass");
+ securityManager.addUser("guest", "guest");
+ securityManager.addRole("guest", "guest");
+ securityManager.setDefaultUser("guest");
+ Role role = new Role("arole", false, false, false, false, false, false,
false);
+ Role sendRole = new Role("guest", true, false, true, false, false, false,
false);
+ Set<Role> roles = new HashSet<Role>();
+ roles.add(sendRole);
+ roles.add(role);
+ securityRepository.addMatch(SecurityTest.addressA, roles);
+ securityManager.addRole("auser", "arole");
+ ClientSessionFactory cf = locator.createSessionFactory();
+ ClientSession senSession = cf.createSession(false, true, true);
+ ClientSession session = cf.createSession("auser", "pass",
false, true, true, false, -1);
+ senSession.createQueue(SecurityTest.addressA, SecurityTest.queueA, true);
+ ClientProducer cp = senSession.createProducer(SecurityTest.addressA);
+ cp.send(session.createMessage(false));
try
{
- server.start();
- HierarchicalRepository<Set<Role>> securityRepository =
server.getSecurityRepository();
- HornetQSecurityManager securityManager = server.getSecurityManager();
- securityManager.addUser("auser", "pass");
- securityManager.addUser("guest", "guest");
- securityManager.addRole("guest", "guest");
- securityManager.setDefaultUser("guest");
- Role role = new Role("arole", false, false, false, false, false,
false, false);
- Role sendRole = new Role("guest", true, false, true, false, false,
false, false);
- Set<Role> roles = new HashSet<Role>();
- roles.add(sendRole);
- roles.add(role);
- securityRepository.addMatch(SecurityTest.addressA, roles);
- securityManager.addRole("auser", "arole");
- ClientSessionFactory cf = locator.createSessionFactory();
- ClientSession senSession = cf.createSession(false, true, true);
- ClientSession session = cf.createSession("auser", "pass",
false, true, true, false, -1);
- senSession.createQueue(SecurityTest.addressA, SecurityTest.queueA, true);
- ClientProducer cp = senSession.createProducer(SecurityTest.addressA);
- cp.send(session.createMessage(false));
- try
- {
- session.createConsumer(SecurityTest.queueA);
- }
- catch (HornetQException e)
- {
- Assert.assertEquals(HornetQException.SECURITY_EXCEPTION, e.getCode());
- }
- session.close();
- senSession.close();
+ session.createConsumer(SecurityTest.queueA);
}
- finally
+ catch (HornetQException e)
{
- if (server.isStarted())
- {
- server.stop();
- }
+ Assert.assertEquals(HornetQException.SECURITY_EXCEPTION, e.getCode());
}
+ session.close();
+ senSession.close();
}
public void testSendMessageUpdateRoleCached() throws Exception
@@ -745,60 +533,49 @@
configuration.setSecurityEnabled(true);
configuration.setSecurityInvalidationInterval(10000);
HornetQServer server = createServer(false, configuration);
-
+ server.start();
+ HierarchicalRepository<Set<Role>> securityRepository =
server.getSecurityRepository();
+ HornetQSecurityManager securityManager = server.getSecurityManager();
+ securityManager.addUser("auser", "pass");
+ securityManager.addUser("guest", "guest");
+ securityManager.addRole("guest", "guest");
+ securityManager.setDefaultUser("guest");
+ Role role = new Role("arole", false, false, false, false, false, false,
false);
+ Role sendRole = new Role("guest", true, false, true, false, false, false,
false);
+ Role receiveRole = new Role("receiver", false, true, false, false, false,
false, false);
+ Set<Role> roles = new HashSet<Role>();
+ roles.add(sendRole);
+ roles.add(role);
+ roles.add(receiveRole);
+ securityRepository.addMatch(SecurityTest.addressA, roles);
+ securityManager.addRole("auser", "arole");
+ ClientSessionFactory cf = locator.createSessionFactory();
+ ClientSession senSession = cf.createSession(false, true, true);
+ ClientSession session = cf.createSession("auser", "pass",
false, true, true, false, -1);
+ senSession.createQueue(SecurityTest.addressA, SecurityTest.queueA, true);
+ ClientProducer cp = senSession.createProducer(SecurityTest.addressA);
+ cp.send(session.createMessage(false));
try
{
- server.start();
- HierarchicalRepository<Set<Role>> securityRepository =
server.getSecurityRepository();
- HornetQSecurityManager securityManager = server.getSecurityManager();
- securityManager.addUser("auser", "pass");
- securityManager.addUser("guest", "guest");
- securityManager.addRole("guest", "guest");
- securityManager.setDefaultUser("guest");
- Role role = new Role("arole", false, false, false, false, false,
false, false);
- Role sendRole = new Role("guest", true, false, true, false, false,
false, false);
- Role receiveRole = new Role("receiver", false, true, false, false,
false, false, false);
- Set<Role> roles = new HashSet<Role>();
- roles.add(sendRole);
- roles.add(role);
- roles.add(receiveRole);
- securityRepository.addMatch(SecurityTest.addressA, roles);
- securityManager.addRole("auser", "arole");
- ClientSessionFactory cf = locator.createSessionFactory();
- ClientSession senSession = cf.createSession(false, true, true);
- ClientSession session = cf.createSession("auser", "pass",
false, true, true, false, -1);
- senSession.createQueue(SecurityTest.addressA, SecurityTest.queueA, true);
- ClientProducer cp = senSession.createProducer(SecurityTest.addressA);
- cp.send(session.createMessage(false));
- try
- {
- session.createConsumer(SecurityTest.queueA);
- }
- catch (HornetQException e)
- {
- Assert.assertEquals(HornetQException.SECURITY_EXCEPTION, e.getCode());
- }
+ session.createConsumer(SecurityTest.queueA);
+ }
+ catch (HornetQException e)
+ {
+ Assert.assertEquals(HornetQException.SECURITY_EXCEPTION, e.getCode());
+ }
- securityManager.addRole("auser", "receiver");
+ securityManager.addRole("auser", "receiver");
- session.createConsumer(SecurityTest.queueA);
+ session.createConsumer(SecurityTest.queueA);
- // Removing the Role... the check should be cached, so the next createConsumer
shouldn't fail
- securityManager.removeRole("auser", "receiver");
+ // Removing the Role... the check should be cached, so the next createConsumer
shouldn't fail
+ securityManager.removeRole("auser", "receiver");
- session.createConsumer(SecurityTest.queueA);
+ session.createConsumer(SecurityTest.queueA);
- session.close();
+ session.close();
- senSession.close();
- }
- finally
- {
- if (server.isStarted())
- {
- server.stop();
- }
- }
+ senSession.close();
}
public void testSendMessageUpdateRoleCached2() throws Exception
@@ -808,67 +585,58 @@
configuration.setSecurityInvalidationInterval(0);
HornetQServer server = createServer(false, configuration);
+ server.start();
+ HierarchicalRepository<Set<Role>> securityRepository =
server.getSecurityRepository();
+ HornetQSecurityManager securityManager = server.getSecurityManager();
+ securityManager.addUser("auser", "pass");
+ securityManager.addUser("guest", "guest");
+ securityManager.addRole("guest", "guest");
+ securityManager.setDefaultUser("guest");
+ Role role = new Role("arole", false, false, false, false, false, false,
false);
+ Role sendRole = new Role("guest", true, false, true, false, false, false,
false);
+ Role receiveRole = new Role("receiver", false, true, false, false, false,
false, false);
+ Set<Role> roles = new HashSet<Role>();
+ roles.add(sendRole);
+ roles.add(role);
+ roles.add(receiveRole);
+ securityRepository.addMatch(SecurityTest.addressA, roles);
+ securityManager.addRole("auser", "arole");
+ ClientSessionFactory cf = locator.createSessionFactory();
+ ClientSession senSession = cf.createSession(false, true, true);
+ ClientSession session = cf.createSession("auser", "pass",
false, true, true, false, -1);
+ senSession.createQueue(SecurityTest.addressA, SecurityTest.queueA, true);
+ ClientProducer cp = senSession.createProducer(SecurityTest.addressA);
+ cp.send(session.createMessage(false));
try
{
- server.start();
- HierarchicalRepository<Set<Role>> securityRepository =
server.getSecurityRepository();
- HornetQSecurityManager securityManager = server.getSecurityManager();
- securityManager.addUser("auser", "pass");
- securityManager.addUser("guest", "guest");
- securityManager.addRole("guest", "guest");
- securityManager.setDefaultUser("guest");
- Role role = new Role("arole", false, false, false, false, false,
false, false);
- Role sendRole = new Role("guest", true, false, true, false, false,
false, false);
- Role receiveRole = new Role("receiver", false, true, false, false,
false, false, false);
- Set<Role> roles = new HashSet<Role>();
- roles.add(sendRole);
- roles.add(role);
- roles.add(receiveRole);
- securityRepository.addMatch(SecurityTest.addressA, roles);
- securityManager.addRole("auser", "arole");
- ClientSessionFactory cf = locator.createSessionFactory();
- ClientSession senSession = cf.createSession(false, true, true);
- ClientSession session = cf.createSession("auser", "pass",
false, true, true, false, -1);
- senSession.createQueue(SecurityTest.addressA, SecurityTest.queueA, true);
- ClientProducer cp = senSession.createProducer(SecurityTest.addressA);
- cp.send(session.createMessage(false));
- try
- {
- session.createConsumer(SecurityTest.queueA);
- }
- catch (HornetQException e)
- {
- Assert.assertEquals(HornetQException.SECURITY_EXCEPTION, e.getCode());
- }
-
- securityManager.addRole("auser", "receiver");
-
session.createConsumer(SecurityTest.queueA);
+ }
+ catch (HornetQException e)
+ {
+ Assert.assertEquals(HornetQException.SECURITY_EXCEPTION, e.getCode());
+ }
- // Removing the Role... the check should be cached... but we used
setSecurityInvalidationInterval(0), so the
- // next createConsumer should fail
- securityManager.removeRole("auser", "receiver");
+ securityManager.addRole("auser", "receiver");
- try
- {
- session.createConsumer(SecurityTest.queueA);
- }
- catch (HornetQException e)
- {
- Assert.assertEquals(HornetQException.SECURITY_EXCEPTION, e.getCode());
- }
+ session.createConsumer(SecurityTest.queueA);
- session.close();
+ // Removing the Role... the check should be cached... but we used
+ // setSecurityInvalidationInterval(0), so the
+ // next createConsumer should fail
+ securityManager.removeRole("auser", "receiver");
- senSession.close();
+ try
+ {
+ session.createConsumer(SecurityTest.queueA);
}
- finally
+ catch (HornetQException e)
{
- if (server.isStarted())
- {
- server.stop();
- }
+ Assert.assertEquals(HornetQException.SECURITY_EXCEPTION, e.getCode());
}
+
+ session.close();
+
+ senSession.close();
}
public void testSendMessageUpdateSender() throws Exception
@@ -877,220 +645,176 @@
configuration.setSecurityEnabled(true);
configuration.setSecurityInvalidationInterval(-1);
HornetQServer server = createServer(false, configuration);
+ server.start();
+ HierarchicalRepository<Set<Role>> securityRepository =
server.getSecurityRepository();
+ HornetQSecurityManager securityManager = server.getSecurityManager();
+ securityManager.addUser("auser", "pass");
+ securityManager.addUser("guest", "guest");
+ securityManager.addRole("guest", "guest");
+ securityManager.setDefaultUser("guest");
+ Role role = new Role("arole", false, false, false, false, false, false,
false);
+ System.out.println("guest:" + role);
+ Role sendRole = new Role("guest", true, false, true, false, false, false,
false);
+ System.out.println("guest:" + sendRole);
+ Role receiveRole = new Role("receiver", false, true, false, false, false,
false, false);
+ System.out.println("guest:" + receiveRole);
+ Set<Role> roles = new HashSet<Role>();
+ roles.add(sendRole);
+ roles.add(role);
+ roles.add(receiveRole);
+ securityRepository.addMatch(SecurityTest.addressA, roles);
+ securityManager.addRole("auser", "arole");
+ ClientSessionFactory cf = locator.createSessionFactory();
+ ClientSession senSession = cf.createSession(false, true, true);
+ ClientSession session = cf.createSession("auser", "pass",
false, true, true, false, -1);
+ senSession.createQueue(SecurityTest.addressA, SecurityTest.queueA, true);
+ ClientProducer cp = senSession.createProducer(SecurityTest.addressA);
+ cp.send(session.createMessage(false));
try
{
- server.start();
- HierarchicalRepository<Set<Role>> securityRepository =
server.getSecurityRepository();
- HornetQSecurityManager securityManager = server.getSecurityManager();
- securityManager.addUser("auser", "pass");
- securityManager.addUser("guest", "guest");
- securityManager.addRole("guest", "guest");
- securityManager.setDefaultUser("guest");
- Role role = new Role("arole", false, false, false, false, false,
false, false);
- System.out.println("guest:" + role);
- Role sendRole = new Role("guest", true, false, true, false, false,
false, false);
- System.out.println("guest:" + sendRole);
- Role receiveRole = new Role("receiver", false, true, false, false,
false, false, false);
- System.out.println("guest:" + receiveRole);
- Set<Role> roles = new HashSet<Role>();
- roles.add(sendRole);
- roles.add(role);
- roles.add(receiveRole);
- securityRepository.addMatch(SecurityTest.addressA, roles);
- securityManager.addRole("auser", "arole");
- ClientSessionFactory cf = locator.createSessionFactory();
-
- ClientSession senSession = cf.createSession(false, true, true);
- ClientSession session = cf.createSession("auser", "pass",
false, true, true, false, -1);
- senSession.createQueue(SecurityTest.addressA, SecurityTest.queueA, true);
- ClientProducer cp = senSession.createProducer(SecurityTest.addressA);
- cp.send(session.createMessage(false));
- try
- {
- session.createConsumer(SecurityTest.queueA);
- }
- catch (HornetQException e)
- {
- Assert.assertEquals(HornetQException.SECURITY_EXCEPTION, e.getCode());
- }
-
- securityManager.addRole("auser", "receiver");
-
session.createConsumer(SecurityTest.queueA);
+ }
+ catch (HornetQException e)
+ {
+ Assert.assertEquals(HornetQException.SECURITY_EXCEPTION, e.getCode());
+ }
- // Removing the Role... the check should be cached... but we used
setSecurityInvalidationInterval(0), so the
- // next createConsumer should fail
- securityManager.removeRole("auser", "guest");
+ securityManager.addRole("auser", "receiver");
- ClientSession sendingSession = cf.createSession("auser",
"pass", false, false, false, false, 0);
- ClientProducer prod = sendingSession.createProducer(SecurityTest.addressA);
- prod.send(CreateMessage.createTextMessage(sendingSession, "Test",
true));
- prod.send(CreateMessage.createTextMessage(sendingSession, "Test",
true));
- try
- {
- sendingSession.commit();
- Assert.fail("Expected exception");
- }
- catch (HornetQException e)
- {
- // I would expect the commit to fail, since there were failures registered
- }
+ session.createConsumer(SecurityTest.queueA);
- sendingSession.close();
+ // Removing the Role... the check should be cached... but we used
+ // setSecurityInvalidationInterval(0), so the
+ // next createConsumer should fail
+ securityManager.removeRole("auser", "guest");
- Xid xid = newXID();
+ ClientSession sendingSession = cf.createSession("auser",
"pass", false, false, false, false, 0);
+ ClientProducer prod = sendingSession.createProducer(SecurityTest.addressA);
+ prod.send(CreateMessage.createTextMessage(sendingSession, "Test",
true));
+ prod.send(CreateMessage.createTextMessage(sendingSession, "Test",
true));
+ try
+ {
+ sendingSession.commit();
+ Assert.fail("Expected exception");
+ }
+ catch (HornetQException e)
+ {
+ // I would expect the commit to fail, since there were failures registered
+ }
- sendingSession = cf.createSession("auser", "pass", true,
false, false, false, 0);
- sendingSession.start(xid, XAResource.TMNOFLAGS);
+ sendingSession.close();
- prod = sendingSession.createProducer(SecurityTest.addressA);
- prod.send(CreateMessage.createTextMessage(sendingSession, "Test",
true));
- prod.send(CreateMessage.createTextMessage(sendingSession, "Test",
true));
- sendingSession.end(xid, XAResource.TMSUCCESS);
+ Xid xid = newXID();
- try
- {
- sendingSession.prepare(xid);
- Assert.fail("Exception was expected");
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
+ sendingSession = cf.createSession("auser", "pass", true, false,
false, false, 0);
+ sendingSession.start(xid, XAResource.TMNOFLAGS);
- // A prepare shouldn't mark any recoverable resources
- Xid[] xids = sendingSession.recover(XAResource.TMSTARTRSCAN);
- Assert.assertEquals(0, xids.length);
+ prod = sendingSession.createProducer(SecurityTest.addressA);
+ prod.send(CreateMessage.createTextMessage(sendingSession, "Test",
true));
+ prod.send(CreateMessage.createTextMessage(sendingSession, "Test",
true));
+ sendingSession.end(xid, XAResource.TMSUCCESS);
- session.close();
-
- senSession.close();
-
- sendingSession.close();
+ try
+ {
+ sendingSession.prepare(xid);
+ Assert.fail("Exception was expected");
}
- finally
+ catch (Exception e)
{
- if (server.isStarted())
- {
- server.stop();
- }
+ e.printStackTrace();
}
+
+ // A prepare shouldn't mark any recoverable resources
+ Xid[] xids = sendingSession.recover(XAResource.TMSTARTRSCAN);
+ Assert.assertEquals(0, xids.length);
+
+ session.close();
+
+ senSession.close();
+
+ sendingSession.close();
}
public void testSendManagementWithRole() throws Exception
{
- Configuration configuration = createDefaultConfig(false);
- configuration.setSecurityEnabled(true);
- HornetQServer server = createServer(false, configuration);
+ HornetQServer server = createServer();
- try
- {
- server.start();
- HierarchicalRepository<Set<Role>> securityRepository =
server.getSecurityRepository();
- HornetQSecurityManager securityManager = server.getSecurityManager();
- securityManager.addUser("auser", "pass");
- Role role = new Role("arole", false, false, false, false, false,
false, true);
- Set<Role> roles = new HashSet<Role>();
- roles.add(role);
- securityRepository.addMatch(configuration.getManagementAddress().toString(),
roles);
- securityManager.addRole("auser", "arole");
- locator.setBlockOnNonDurableSend(true);
- ClientSessionFactory cf = locator.createSessionFactory();
- ClientSession session = cf.createSession("auser", "pass",
false, true, true, false, -1);
- ClientProducer cp =
session.createProducer(configuration.getManagementAddress());
- cp.send(session.createMessage(false));
- session.close();
- }
- finally
- {
- if (server.isStarted())
- {
- server.stop();
- }
- }
+ server.start();
+ HierarchicalRepository<Set<Role>> securityRepository =
server.getSecurityRepository();
+ HornetQSecurityManager securityManager = server.getSecurityManager();
+ securityManager.addUser("auser", "pass");
+ Role role = new Role("arole", false, false, false, false, false, false,
true);
+ Set<Role> roles = new HashSet<Role>();
+ roles.add(role);
+ securityRepository.addMatch(configuration.getManagementAddress().toString(),
roles);
+ securityManager.addRole("auser", "arole");
+ locator.setBlockOnNonDurableSend(true);
+ ClientSessionFactory cf = locator.createSessionFactory();
+ ClientSession session = cf.createSession("auser", "pass",
false, true, true, false, -1);
+ ClientProducer cp = session.createProducer(configuration.getManagementAddress());
+ cp.send(session.createMessage(false));
+ session.close();
}
public void testSendManagementWithoutRole() throws Exception
{
- Configuration configuration = createDefaultConfig(false);
- configuration.setSecurityEnabled(true);
- HornetQServer server = createServer(false, configuration);
+ HornetQServer server = createServer();
+ server.start();
+ HierarchicalRepository<Set<Role>> securityRepository =
server.getSecurityRepository();
+ HornetQSecurityManager securityManager = server.getSecurityManager();
+ securityManager.addUser("auser", "pass");
+ Role role = new Role("arole", false, false, true, false, false, false,
false);
+ Set<Role> roles = new HashSet<Role>();
+ roles.add(role);
+ securityRepository.addMatch(configuration.getManagementAddress().toString(),
roles);
+ securityManager.addRole("auser", "arole");
+ ClientSessionFactory cf = locator.createSessionFactory();
+ ClientSession session = cf.createSession("auser", "pass",
false, true, true, false, -1);
+ session.createQueue(configuration.getManagementAddress().toString(),
SecurityTest.queueA, true);
+ ClientProducer cp = session.createProducer(configuration.getManagementAddress());
+ cp.send(session.createMessage(false));
try
{
- server.start();
- HierarchicalRepository<Set<Role>> securityRepository =
server.getSecurityRepository();
- HornetQSecurityManager securityManager = server.getSecurityManager();
- securityManager.addUser("auser", "pass");
- Role role = new Role("arole", false, false, true, false, false, false,
false);
- Set<Role> roles = new HashSet<Role>();
- roles.add(role);
- securityRepository.addMatch(configuration.getManagementAddress().toString(),
roles);
- securityManager.addRole("auser", "arole");
- ClientSessionFactory cf = locator.createSessionFactory();
- ClientSession session = cf.createSession("auser", "pass",
false, true, true, false, -1);
- session.createQueue(configuration.getManagementAddress().toString(),
SecurityTest.queueA, true);
- ClientProducer cp =
session.createProducer(configuration.getManagementAddress());
cp.send(session.createMessage(false));
- try
- {
- cp.send(session.createMessage(false));
- }
- catch (HornetQException e)
- {
- Assert.assertEquals(HornetQException.SECURITY_EXCEPTION, e.getCode());
- }
- session.close();
}
- finally
+ catch (HornetQException e)
{
- if (server.isStarted())
- {
- server.stop();
- }
+ Assert.assertEquals(HornetQException.SECURITY_EXCEPTION, e.getCode());
}
+ session.close();
+
}
public void testNonBlockSendManagementWithoutRole() throws Exception
{
- Configuration configuration = createDefaultConfig(false);
- configuration.setSecurityEnabled(true);
- HornetQServer server = createServer(false, configuration);
+ HornetQServer server = createServer();
- try
- {
- server.start();
- HierarchicalRepository<Set<Role>> securityRepository =
server.getSecurityRepository();
- HornetQSecurityManager securityManager = server.getSecurityManager();
- securityManager.addUser("auser", "pass");
- Role role = new Role("arole", false, false, true, false, false, false,
false);
- Set<Role> roles = new HashSet<Role>();
- roles.add(role);
- securityRepository.addMatch(configuration.getManagementAddress().toString(),
roles);
- securityManager.addRole("auser", "arole");
- ClientSessionFactory cf = locator.createSessionFactory();
- ClientSession session = cf.createSession("auser", "pass",
false, true, true, false, -1);
- session.createQueue(configuration.getManagementAddress().toString(),
SecurityTest.queueA, true);
- ClientProducer cp =
session.createProducer(configuration.getManagementAddress());
- cp.send(session.createMessage(false));
- session.close();
+ server.start();
+ HierarchicalRepository<Set<Role>> securityRepository =
server.getSecurityRepository();
+ HornetQSecurityManager securityManager = server.getSecurityManager();
+ securityManager.addUser("auser", "pass");
+ Role role = new Role("arole", false, false, true, false, false, false,
false);
+ Set<Role> roles = new HashSet<Role>();
+ roles.add(role);
+ securityRepository.addMatch(configuration.getManagementAddress().toString(),
roles);
+ securityManager.addRole("auser", "arole");
+ ClientSessionFactory cf = locator.createSessionFactory();
+ ClientSession session = cf.createSession("auser", "pass",
false, true, true, false, -1);
+ session.createQueue(configuration.getManagementAddress().toString(),
SecurityTest.queueA, true);
+ ClientProducer cp = session.createProducer(configuration.getManagementAddress());
+ cp.send(session.createMessage(false));
+ session.close();
- Queue binding = (Queue)server.getPostOffice().getBinding(new
SimpleString(SecurityTest.queueA)).getBindable();
- Assert.assertEquals(0, binding.getMessageCount());
- }
- finally
- {
- if (server.isStarted())
- {
- server.stop();
- }
- }
+ Queue binding = (Queue)server.getPostOffice().getBinding(new
SimpleString(SecurityTest.queueA)).getBindable();
+ Assert.assertEquals(0, binding.getMessageCount());
+
}
/*
- * basic JAAS tests
- * */
+ * basic JAAS tests
+ */
public void testJaasCreateSessionSucceeds() throws Exception
{
@@ -1111,29 +835,20 @@
Map<String, Object> options = new HashMap<String, Object>();
options.put("authenticated", Boolean.TRUE);
securityManager.setConfiguration(new SimpleConfiguration(domainName, options));
+ server.start();
+ ClientSessionFactory cf = locator.createSessionFactory();
+
try
{
- server.start();
- ClientSessionFactory cf = locator.createSessionFactory();
+ ClientSession session = cf.createSession(false, true, true);
- try
- {
- ClientSession session = cf.createSession(false, true, true);
-
- session.close();
- }
- catch (HornetQException e)
- {
- Assert.fail("should not throw exception");
- }
+ session.close();
}
- finally
+ catch (HornetQException e)
{
- if (server.isStarted())
- {
- server.stop();
- }
+ Assert.fail("should not throw exception");
}
+
}
public void testJaasCreateSessionFails() throws Exception
@@ -1155,9 +870,7 @@
Map<String, Object> options = new HashMap<String, Object>();
options.put("authenticated", Boolean.FALSE);
securityManager.setConfiguration(new SimpleConfiguration(domainName, options));
- try
- {
- server.start();
+ server.start();
ClientSessionFactory cf = locator.createSessionFactory();
try
@@ -1169,24 +882,13 @@
{
Assert.assertEquals(HornetQException.SECURITY_EXCEPTION, e.getCode());
}
- }
- finally
- {
- if (server.isStarted())
- {
- server.stop();
- }
- }
+
}
public void testComplexRoles() throws Exception
{
- Configuration configuration = createDefaultConfig(false);
- configuration.setSecurityEnabled(true);
- HornetQServer server = createServer(false, configuration);
- try
- {
- server.start();
+ HornetQServer server = createServer();
+ server.start();
HornetQSecurityManager securityManager = server.getSecurityManager();
securityManager.addUser("all", "all");
securityManager.addUser("bill", "hornetq");
@@ -1274,16 +976,20 @@
checkUserSendAndReceive(genericQueueName, frankConnection);
checkUserSendAndReceive(genericQueueName, samConnection);
- // Step 11. Check permissions on news.europe.europeTopic for bill: can't
send and can't receive
+ // Step 11. Check permissions on news.europe.europeTopic for bill: can't
send and can't
+ // receive
checkUserNoSendNoReceive(eurQueueName, billConnection, adminSession);
- // Step 12. Check permissions on news.europe.europeTopic for andrew: can send
but can't receive
+ // Step 12. Check permissions on news.europe.europeTopic for andrew: can send
but can't
+ // receive
checkUserSendNoReceive(eurQueueName, andrewConnection);
- // Step 13. Check permissions on news.europe.europeTopic for frank: can't
send but can receive
+ // Step 13. Check permissions on news.europe.europeTopic for frank: can't
send but can
+ // receive
checkUserReceiveNoSend(eurQueueName, frankConnection, adminSession);
- // Step 14. Check permissions on news.europe.europeTopic for sam: can't send
but can receive
+ // Step 14. Check permissions on news.europe.europeTopic for sam: can't send
but can
+ // receive
checkUserReceiveNoSend(eurQueueName, samConnection, adminSession);
// Step 15. Check permissions on news.us.usTopic for bill: can't send and
can't receive
@@ -1307,24 +1013,13 @@
samConnection.close();
adminSession.close();
- }
- finally
- {
- if (server.isStarted())
- {
- server.stop();
- }
- }
+
}
public void _testComplexRoles2() throws Exception
{
- Configuration configuration = createDefaultConfig(false);
- configuration.setSecurityEnabled(true);
- HornetQServer server = createServer(false, configuration);
- try
- {
- server.start();
+ HornetQServer server = createServer();
+ server.start();
HornetQSecurityManager securityManager = server.getSecurityManager();
securityManager.addUser("all", "all");
securityManager.addUser("bill", "hornetq");
@@ -1412,16 +1107,20 @@
checkUserSendAndReceive(genericQueueName, frankConnection);
checkUserSendAndReceive(genericQueueName, samConnection);
- // Step 11. Check permissions on news.europe.europeTopic for bill: can't
send and can't receive
+ // Step 11. Check permissions on news.europe.europeTopic for bill: can't
send and can't
+ // receive
checkUserNoSendNoReceive(eurQueueName, billConnection, adminSession);
- // Step 12. Check permissions on news.europe.europeTopic for andrew: can send
but can't receive
+ // Step 12. Check permissions on news.europe.europeTopic for andrew: can send
but can't
+ // receive
checkUserSendNoReceive(eurQueueName, andrewConnection);
- // Step 13. Check permissions on news.europe.europeTopic for frank: can't
send but can receive
+ // Step 13. Check permissions on news.europe.europeTopic for frank: can't
send but can
+ // receive
checkUserReceiveNoSend(eurQueueName, frankConnection, adminSession);
- // Step 14. Check permissions on news.europe.europeTopic for sam: can't send
but can receive
+ // Step 14. Check permissions on news.europe.europeTopic for sam: can't send
but can
+ // receive
checkUserReceiveNoSend(eurQueueName, samConnection, adminSession);
// Step 15. Check permissions on news.us.usTopic for bill: can't send and
can't receive
@@ -1435,14 +1134,7 @@
// Step 18. Check permissions on news.us.usTopic for same: can't send but
can receive
checkUserReceiveNoSend(usQueueName, samConnection, adminSession);
- }
- finally
- {
- if (server.isStarted())
- {
- server.stop();
- }
- }
+
}
// Check the user connection has both send and receive permissions on the queue
@@ -1466,8 +1158,7 @@
}
// Check the user can receive message but cannot send message.
- private void checkUserReceiveNoSend(final String queue,
- final ClientSession connection,
+ private void checkUserReceiveNoSend(final String queue, final ClientSession
connection,
final ClientSession sendingConn) throws Exception
{
connection.start();
@@ -1498,8 +1189,7 @@
}
}
- private void checkUserNoSendNoReceive(final String queue,
- final ClientSession connection,
+ private void checkUserNoSendNoReceive(final String queue, final ClientSession
connection,
final ClientSession sendingConn) throws
Exception
{
connection.start();
@@ -1574,10 +1264,8 @@
return true;
}
- public void initialize(final Subject subject,
- final CallbackHandler callbackHandler,
- final Map<String, ?> sharedState,
- final Map<String, ?> options)
+ public void initialize(final Subject subject, final CallbackHandler
callbackHandler,
+ final Map<String, ?> sharedState, final Map<String,
?> options)
{
this.subject = subject;
this.options = options;
@@ -1622,9 +1310,9 @@
@Override
public AppConfigurationEntry[] getAppConfigurationEntry(final String name)
{
- AppConfigurationEntry entry = new AppConfigurationEntry(loginModuleName,
-
AppConfigurationEntry.LoginModuleControlFlag.REQUIRED,
- options);
+ AppConfigurationEntry entry =
+ new AppConfigurationEntry(loginModuleName,
AppConfigurationEntry.LoginModuleControlFlag.REQUIRED,
+ options);
return new AppConfigurationEntry[] { entry };
}