mirror of https://github.com/apache/activemq.git
resolve https://issues.apache.org/activemq/browse/AMQ-2516 - broker send to dlq now uses broker security context so it will bypass the authentication plugin when configured
git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@884778 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
13f9ec8555
commit
adb7fccda0
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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<String, String> headers = new HashMap<String, String>();
|
||||
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");
|
||||
|
|
Loading…
Reference in New Issue