diff --git a/activemq-core/src/main/java/org/apache/activemq/broker/region/Queue.java b/activemq-core/src/main/java/org/apache/activemq/broker/region/Queue.java index 31877108d0..e1c8dcca47 100755 --- a/activemq-core/src/main/java/org/apache/activemq/broker/region/Queue.java +++ b/activemq-core/src/main/java/org/apache/activemq/broker/region/Queue.java @@ -61,6 +61,7 @@ import org.apache.activemq.command.Response; import org.apache.activemq.filter.BooleanExpression; import org.apache.activemq.filter.MessageEvaluationContext; import org.apache.activemq.filter.NonCachedMessageEvaluationContext; +import org.apache.activemq.security.SecurityContext; import org.apache.activemq.selector.SelectorParser; import org.apache.activemq.store.MessageRecoveryListener; import org.apache.activemq.store.MessageStore; @@ -1262,6 +1263,7 @@ public class Queue extends BaseDestination implements Task, UsageListener { ConnectionContext answer = new ConnectionContext(new NonCachedMessageEvaluationContext()); answer.setBroker(this.broker); answer.getMessageEvaluationContext().setDestination(getActiveMQDestination()); + answer.setSecurityContext(SecurityContext.BROKER_SECURITY_CONTEXT); return answer; } diff --git a/activemq-core/src/test/java/org/apache/activemq/security/SecurityJMXTest.java b/activemq-core/src/test/java/org/apache/activemq/security/SecurityJMXTest.java index 2bc781d8aa..abe2b78bab 100644 --- a/activemq-core/src/test/java/org/apache/activemq/security/SecurityJMXTest.java +++ b/activemq-core/src/test/java/org/apache/activemq/security/SecurityJMXTest.java @@ -18,7 +18,13 @@ package org.apache.activemq.security; import java.net.URI; +import java.util.HashMap; +import java.util.concurrent.TimeUnit; +import javax.jms.Connection; +import javax.jms.DeliveryMode; +import javax.jms.QueueBrowser; +import javax.jms.Session; import javax.management.MBeanServerConnection; import javax.management.MBeanServerInvocationHandler; import javax.management.ObjectName; @@ -28,9 +34,11 @@ import javax.management.remote.JMXServiceURL; import junit.framework.TestCase; +import org.apache.activemq.ActiveMQConnectionFactory; import org.apache.activemq.broker.BrokerFactory; import org.apache.activemq.broker.BrokerService; import org.apache.activemq.broker.jmx.QueueViewMBean; +import org.apache.activemq.command.ActiveMQQueue; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -46,6 +54,7 @@ public class SecurityJMXTest extends TestCase { } public void tearDown() throws Exception { + broker.stop(); } public void testMoveMessages() throws Exception { @@ -58,6 +67,34 @@ public class SecurityJMXTest extends TestCase { String msgId = queueMbean.sendTextMessage("test", "system", "manager"); queueMbean.moveMessageTo(msgId, "TEST1.Q"); } + + + public void testBrowseExpiredMessages() throws Exception { + JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:1199/jmxrmi"); + JMXConnector connector = JMXConnectorFactory.connect(url, null); + connector.connect(); + MBeanServerConnection connection = connector.getMBeanServerConnection(); + ObjectName name = new ObjectName("org.apache.activemq:BrokerName=localhost,Type=Queue,Destination=TEST.Q"); + QueueViewMBean queueMbean = (QueueViewMBean) MBeanServerInvocationHandler.newProxyInstance(connection, name, QueueViewMBean.class, true); + HashMap headers = new HashMap(); + headers.put("JMSExpiration", Long.toString(System.currentTimeMillis() + 2000)); + headers.put("JMSDeliveryMode", Integer.toString(DeliveryMode.PERSISTENT)); + String msgId = queueMbean.sendTextMessage(headers, "test", "system", "manager"); + // allow message to expire on the queue + TimeUnit.SECONDS.sleep(3); + + Connection c = new ActiveMQConnectionFactory("vm://localhost").createConnection("system", "manager"); + c.start(); + + // browser consumer will force expriation check on addConsumer + QueueBrowser browser = c.createSession(false, Session.AUTO_ACKNOWLEDGE).createBrowser(new ActiveMQQueue("TEST.Q")); + assertTrue("no message in the q", !browser.getEnumeration().hasMoreElements()); + + // verify dlq got the message, no security exception as brokers context is now used + browser = c.createSession(false, Session.AUTO_ACKNOWLEDGE).createBrowser(new ActiveMQQueue("ActiveMQ.DLQ")); + assertTrue("one message in the dlq", browser.getEnumeration().hasMoreElements()); + } + protected BrokerService createBroker() throws Exception { return createBroker("org/apache/activemq/security/simple-auth-broker.xml");