activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r1487018 - in /activemq/trunk: activemq-client/src/main/java/org/apache/activemq/filter/PropertyExpression.java activemq-unit-tests/src/test/java/org/apache/activemq/test/JmsTopicSendReceiveWithEmbeddedBrokerAndUserIDTest.java
Date Tue, 28 May 2013 17:43:07 GMT
Author: tabish
Date: Tue May 28 17:43:07 2013
New Revision: 1487018

URL: http://svn.apache.org/r1487018
Log:
fix and test for: https://issues.apache.org/jira/browse/AMQ-4542

Modified:
    activemq/trunk/activemq-client/src/main/java/org/apache/activemq/filter/PropertyExpression.java
    activemq/trunk/activemq-unit-tests/src/test/java/org/apache/activemq/test/JmsTopicSendReceiveWithEmbeddedBrokerAndUserIDTest.java

Modified: activemq/trunk/activemq-client/src/main/java/org/apache/activemq/filter/PropertyExpression.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-client/src/main/java/org/apache/activemq/filter/PropertyExpression.java?rev=1487018&r1=1487017&r2=1487018&view=diff
==============================================================================
--- activemq/trunk/activemq-client/src/main/java/org/apache/activemq/filter/PropertyExpression.java
(original)
+++ activemq/trunk/activemq-client/src/main/java/org/apache/activemq/filter/PropertyExpression.java
Tue May 28 17:43:07 2013
@@ -138,6 +138,13 @@ public class PropertyExpression implemen
                 return message.getGroupID();
             }
         });
+        JMS_PROPERTY_EXPRESSIONS.put("JMSXUserID", new SubExpression() {
+
+            @Override
+            public Object evaluate(Message message) {
+                return message.getUserID();
+            }
+        });
         JMS_PROPERTY_EXPRESSIONS.put("JMSXGroupSeq", new SubExpression() {
 
             @Override

Modified: activemq/trunk/activemq-unit-tests/src/test/java/org/apache/activemq/test/JmsTopicSendReceiveWithEmbeddedBrokerAndUserIDTest.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-unit-tests/src/test/java/org/apache/activemq/test/JmsTopicSendReceiveWithEmbeddedBrokerAndUserIDTest.java?rev=1487018&r1=1487017&r2=1487018&view=diff
==============================================================================
--- activemq/trunk/activemq-unit-tests/src/test/java/org/apache/activemq/test/JmsTopicSendReceiveWithEmbeddedBrokerAndUserIDTest.java
(original)
+++ activemq/trunk/activemq-unit-tests/src/test/java/org/apache/activemq/test/JmsTopicSendReceiveWithEmbeddedBrokerAndUserIDTest.java
Tue May 28 17:43:07 2013
@@ -16,7 +16,6 @@
  */
 package org.apache.activemq.test;
 
-import java.util.Iterator;
 import java.util.List;
 
 import javax.jms.JMSException;
@@ -24,39 +23,54 @@ import javax.jms.Message;
 
 import org.apache.activemq.ActiveMQConnectionFactory;
 import org.apache.activemq.broker.BrokerService;
-import org.apache.activemq.security.SimpleSecurityBrokerSystemTest;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /**
- * 
+ *
  */
 public class JmsTopicSendReceiveWithEmbeddedBrokerAndUserIDTest extends JmsTopicSendReceiveWithTwoConnectionsAndEmbeddedBrokerTest
{
     private static final Logger LOG = LoggerFactory.getLogger(JmsTopicSendReceiveWithEmbeddedBrokerAndUserIDTest.class);
 
     protected String userName = "James";
 
+    @Override
     protected ActiveMQConnectionFactory createConnectionFactory() throws Exception {
         ActiveMQConnectionFactory answer = super.createConnectionFactory();
         answer.setUserName(userName);
         return answer;
     }
 
+    @Override
     protected void configureBroker(BrokerService answer) throws Exception {
         answer.setPopulateJMSXUserID(true);
         super.configureBroker(answer);
     }
 
-    protected void assertMessagesReceivedAreValid(List receivedMessages) throws JMSException
{
+    @Override
+    protected void assertMessagesReceivedAreValid(List<Message> receivedMessages) throws
JMSException {
         super.assertMessagesReceivedAreValid(receivedMessages);
 
         // lets assert that the user ID is set
-        for (Iterator iter = receivedMessages.iterator(); iter.hasNext();) {
-            Message message = (Message)iter.next();
+        for (Message message : receivedMessages) {
             String userID = message.getStringProperty("JMSXUserID");
-
             LOG.info("Received message with userID: " + userID);
+            assertEquals("JMSXUserID header", userName, userID);
+        }
+    }
 
+    protected void assertMessagesAreReceived2() throws JMSException {
+        waitForMessagesToBeDelivered();
+        assertMessagesReceivedAreValid2(messages);
+    }
+
+    protected void assertMessagesReceivedAreValid2(List<Message> receivedMessages)
throws JMSException {
+        super.assertMessagesReceivedAreValid(receivedMessages);
+
+        // lets assert that the user ID is set
+        for (Message message : receivedMessages) {
+            String userID = (String) message.getObjectProperty("JMSXUserID");
+            LOG.info("Received message with userID: " + userID);
             assertEquals("JMSXUserID header", userName, userID);
         }
     }
@@ -77,4 +91,21 @@ public class JmsTopicSendReceiveWithEmbe
         assertMessagesAreReceived();
         LOG.info("" + data.length + " messages(s) received, closing down connections");
     }
+
+    public void testSpoofedJMSXUserIdIsIgnoredAsObjectProperty() throws Exception {
+        Thread.sleep(1000);
+        messages.clear();
+
+        for (int i = 0; i < data.length; i++) {
+            Message message = createMessage(i);
+            configureMessage(message);
+            message.setStringProperty("JMSXUserID", "spoofedId");
+            if (verbose) {
+                LOG.info("About to send a message: " + message + " with text: " + data[i]);
+            }
+            sendMessage(i, message);
+        }
+        assertMessagesAreReceived2();
+        LOG.info("" + data.length + " messages(s) received, closing down connections");
+    }
 }



Mime
View raw message