activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chir...@apache.org
Subject git commit: Fix for AMQ-4717: populateJMSXUserID is not setting the JMSXUserID property on the JMS message in JMX
Date Tue, 10 Sep 2013 14:46:08 GMT
Updated Branches:
  refs/heads/trunk 272de3a14 -> 9c75fe7b6


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


Project: http://git-wip-us.apache.org/repos/asf/activemq/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq/commit/9c75fe7b
Tree: http://git-wip-us.apache.org/repos/asf/activemq/tree/9c75fe7b
Diff: http://git-wip-us.apache.org/repos/asf/activemq/diff/9c75fe7b

Branch: refs/heads/trunk
Commit: 9c75fe7b61f4b6aac639eb692c0989372ab07594
Parents: 272de3a
Author: Hiram Chirino <hiram@hiramchirino.com>
Authored: Tue Sep 10 10:16:54 2013 -0400
Committer: Hiram Chirino <hiram@hiramchirino.com>
Committed: Tue Sep 10 10:45:52 2013 -0400

----------------------------------------------------------------------
 .../broker/jmx/CompositeDataConstants.java      |  1 +
 .../activemq/broker/jmx/OpenTypeSupport.java    |  2 ++
 .../SimpleSecurityBrokerSystemTest.java         | 32 ++++++++++++++++++++
 3 files changed, 35 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq/blob/9c75fe7b/activemq-broker/src/main/java/org/apache/activemq/broker/jmx/CompositeDataConstants.java
----------------------------------------------------------------------
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 f627c07..0613910 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";

http://git-wip-us.apache.org/repos/asf/activemq/blob/9c75fe7b/activemq-broker/src/main/java/org/apache/activemq/broker/jmx/OpenTypeSupport.java
----------------------------------------------------------------------
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 cb35f76..d542d36 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 {

http://git-wip-us.apache.org/repos/asf/activemq/blob/9c75fe7b/activemq-unit-tests/src/test/java/org/apache/activemq/security/SimpleSecurityBrokerSystemTest.java
----------------------------------------------------------------------
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 cc32b50..af370c8 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;


Mime
View raw message