Fix for AMQ-4717: populateJMSXUserID is not setting the JMSXUserID property on the JMS message in JMX

This commit is contained in:
Hiram Chirino 2013-09-10 10:16:54 -04:00
parent 272de3a146
commit 9c75fe7b61
3 changed files with 35 additions and 0 deletions

View File

@ -24,6 +24,7 @@ public interface CompositeDataConstants {
String PROPERTIES = "PropertiesText"; String PROPERTIES = "PropertiesText";
String JMSXGROUP_SEQ = "JMSXGroupSeq"; String JMSXGROUP_SEQ = "JMSXGroupSeq";
String JMSXGROUP_ID = "JMSXGroupID"; String JMSXGROUP_ID = "JMSXGroupID";
String JMSXUSER_ID = "JMSXUserID";
String BROKER_PATH = "BrokerPath"; String BROKER_PATH = "BrokerPath";
String BODY_LENGTH = "BodyLength"; String BODY_LENGTH = "BodyLength";
String BODY_PREVIEW = "BodyPreview"; String BODY_PREVIEW = "BodyPreview";

View File

@ -130,6 +130,7 @@ public final class OpenTypeSupport {
addItem("JMSTimestamp", "JMSTimestamp", SimpleType.DATE); addItem("JMSTimestamp", "JMSTimestamp", SimpleType.DATE);
addItem(CompositeDataConstants.JMSXGROUP_ID, "Message Group ID", SimpleType.STRING); addItem(CompositeDataConstants.JMSXGROUP_ID, "Message Group ID", SimpleType.STRING);
addItem(CompositeDataConstants.JMSXGROUP_SEQ, "Message Group Sequence Number", SimpleType.INTEGER); addItem(CompositeDataConstants.JMSXGROUP_SEQ, "Message Group Sequence Number", SimpleType.INTEGER);
addItem(CompositeDataConstants.JMSXUSER_ID, "The user that sent the message", SimpleType.STRING);
addItem(CompositeDataConstants.BROKER_PATH, "Brokers traversed", SimpleType.STRING); addItem(CompositeDataConstants.BROKER_PATH, "Brokers traversed", SimpleType.STRING);
addItem(CompositeDataConstants.ORIGINAL_DESTINATION, "Original Destination Before Senting To DLQ", SimpleType.STRING); addItem(CompositeDataConstants.ORIGINAL_DESTINATION, "Original Destination Before Senting To DLQ", SimpleType.STRING);
addItem(CompositeDataConstants.PROPERTIES, "User Properties Text", SimpleType.STRING); addItem(CompositeDataConstants.PROPERTIES, "User Properties Text", SimpleType.STRING);
@ -170,6 +171,7 @@ public final class OpenTypeSupport {
rc.put("JMSTimestamp", new Date(m.getJMSTimestamp())); rc.put("JMSTimestamp", new Date(m.getJMSTimestamp()));
rc.put(CompositeDataConstants.JMSXGROUP_ID, m.getGroupID()); rc.put(CompositeDataConstants.JMSXGROUP_ID, m.getGroupID());
rc.put(CompositeDataConstants.JMSXGROUP_SEQ, m.getGroupSequence()); rc.put(CompositeDataConstants.JMSXGROUP_SEQ, m.getGroupSequence());
rc.put(CompositeDataConstants.JMSXUSER_ID, m.getUserID());
rc.put(CompositeDataConstants.BROKER_PATH, Arrays.toString(m.getBrokerPath())); rc.put(CompositeDataConstants.BROKER_PATH, Arrays.toString(m.getBrokerPath()));
rc.put(CompositeDataConstants.ORIGINAL_DESTINATION, toString(m.getOriginalDestination())); rc.put(CompositeDataConstants.ORIGINAL_DESTINATION, toString(m.getOriginalDestination()));
try { try {

View File

@ -16,6 +16,7 @@
*/ */
package org.apache.activemq.security; package org.apache.activemq.security;
import java.lang.management.ManagementFactory;
import java.net.URL; import java.net.URL;
import java.security.Principal; import java.security.Principal;
import java.util.Arrays; import java.util.Arrays;
@ -36,6 +37,12 @@ import org.apache.activemq.jaas.GroupPrincipal;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import javax.jms.*;
import javax.management.MBeanServer;
import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;
import javax.management.openmbean.CompositeData;
/** /**
* Tests that the broker allows/fails access to destinations based on the * Tests that the broker allows/fails access to destinations based on the
* security policy installed on the broker. * security policy installed on the broker.
@ -80,6 +87,29 @@ public class SimpleSecurityBrokerSystemTest extends SecurityTestSupport {
junit.textui.TestRunner.run(suite()); junit.textui.TestRunner.run(suite());
} }
/**
* @throws javax.jms.JMSException
*/
public void testPopulateJMSXUserID() throws Exception {
destination = new ActiveMQQueue("TEST");
Connection connection = factory.createConnection("system", "manager");
connections.add(connection);
connection.start();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
sendMessages(session, destination, 1);
// make sure that the JMSXUserID is exposed over JMX
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
CompositeData[] browse = (CompositeData[]) mbs.invoke(new ObjectName("org.apache.activemq:type=Broker,brokerName=localhost,destinationType=Queue,destinationName=TEST"), "browse", null, null);
assertEquals("system", browse[0].get("JMSXUserID"));
// And also via JMS.
MessageConsumer consumer = session.createConsumer(destination);
Message m = consumer.receive(1000);
assertEquals("system", m.getStringProperty("JMSXUserID"));
}
public static AuthorizationMap createAuthorizationMap() { public static AuthorizationMap createAuthorizationMap() {
DestinationMap readAccess = new DefaultAuthorizationMap(); DestinationMap readAccess = new DefaultAuthorizationMap();
readAccess.put(new ActiveMQQueue(">"), ADMINS); readAccess.put(new ActiveMQQueue(">"), ADMINS);
@ -146,6 +176,8 @@ public class SimpleSecurityBrokerSystemTest extends SecurityTestSupport {
protected BrokerService createBroker() throws Exception { protected BrokerService createBroker() throws Exception {
BrokerService broker = super.createBroker(); BrokerService broker = super.createBroker();
broker.setPopulateJMSXUserID(true);
broker.setUseAuthenticatedPrincipalForJMSXUserID(true);
broker.setPlugins(new BrokerPlugin[] {authorizationPlugin, authenticationPlugin}); broker.setPlugins(new BrokerPlugin[] {authorizationPlugin, authenticationPlugin});
broker.setPersistent(false); broker.setPersistent(false);
return broker; return broker;