diff --git a/activemq-broker/src/main/java/org/apache/activemq/broker/jmx/CompositeDataConstants.java b/activemq-broker/src/main/java/org/apache/activemq/broker/jmx/CompositeDataConstants.java index f627c078be..0613910788 100644 --- a/activemq-broker/src/main/java/org/apache/activemq/broker/jmx/CompositeDataConstants.java +++ b/activemq-broker/src/main/java/org/apache/activemq/broker/jmx/CompositeDataConstants.java @@ -24,6 +24,7 @@ public interface CompositeDataConstants { String PROPERTIES = "PropertiesText"; String JMSXGROUP_SEQ = "JMSXGroupSeq"; String JMSXGROUP_ID = "JMSXGroupID"; + String JMSXUSER_ID = "JMSXUserID"; String BROKER_PATH = "BrokerPath"; String BODY_LENGTH = "BodyLength"; String BODY_PREVIEW = "BodyPreview"; diff --git a/activemq-broker/src/main/java/org/apache/activemq/broker/jmx/OpenTypeSupport.java b/activemq-broker/src/main/java/org/apache/activemq/broker/jmx/OpenTypeSupport.java index cb35f76524..d542d36d7a 100644 --- a/activemq-broker/src/main/java/org/apache/activemq/broker/jmx/OpenTypeSupport.java +++ b/activemq-broker/src/main/java/org/apache/activemq/broker/jmx/OpenTypeSupport.java @@ -130,6 +130,7 @@ public final class OpenTypeSupport { addItem("JMSTimestamp", "JMSTimestamp", SimpleType.DATE); addItem(CompositeDataConstants.JMSXGROUP_ID, "Message Group ID", SimpleType.STRING); 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.ORIGINAL_DESTINATION, "Original Destination Before Senting To DLQ", 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(CompositeDataConstants.JMSXGROUP_ID, m.getGroupID()); 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.ORIGINAL_DESTINATION, toString(m.getOriginalDestination())); try { diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/security/SimpleSecurityBrokerSystemTest.java b/activemq-unit-tests/src/test/java/org/apache/activemq/security/SimpleSecurityBrokerSystemTest.java index cc32b50c11..af370c878f 100644 --- a/activemq-unit-tests/src/test/java/org/apache/activemq/security/SimpleSecurityBrokerSystemTest.java +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/security/SimpleSecurityBrokerSystemTest.java @@ -16,6 +16,7 @@ */ package org.apache.activemq.security; +import java.lang.management.ManagementFactory; import java.net.URL; import java.security.Principal; import java.util.Arrays; @@ -36,6 +37,12 @@ import org.apache.activemq.jaas.GroupPrincipal; import org.slf4j.Logger; 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 * security policy installed on the broker. @@ -80,6 +87,29 @@ public class SimpleSecurityBrokerSystemTest extends SecurityTestSupport { 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() { DestinationMap readAccess = new DefaultAuthorizationMap(); readAccess.put(new ActiveMQQueue(">"), ADMINS); @@ -146,6 +176,8 @@ public class SimpleSecurityBrokerSystemTest extends SecurityTestSupport { protected BrokerService createBroker() throws Exception { BrokerService broker = super.createBroker(); + broker.setPopulateJMSXUserID(true); + broker.setUseAuthenticatedPrincipalForJMSXUserID(true); broker.setPlugins(new BrokerPlugin[] {authorizationPlugin, authenticationPlugin}); broker.setPersistent(false); return broker;