activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dej...@apache.org
Subject svn commit: r962512 - in /activemq/trunk/activemq-core/src: main/java/org/apache/activemq/transport/stomp/FrameTranslator.java main/java/org/apache/activemq/transport/stomp/Stomp.java test/java/org/apache/activemq/transport/stomp/StompTest.java
Date Fri, 09 Jul 2010 12:55:21 GMT
Author: dejanb
Date: Fri Jul  9 12:55:21 2010
New Revision: 962512

URL: http://svn.apache.org/viewvc?rev=962512&view=rev
Log:
 https://issues.apache.org/activemq/browse/AMQ-2817 - sanitize stomp headers

Modified:
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/stomp/FrameTranslator.java
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/stomp/Stomp.java
    activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/stomp/StompTest.java

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/stomp/FrameTranslator.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/stomp/FrameTranslator.java?rev=962512&r1=962511&r2=962512&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/stomp/FrameTranslator.java
(original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/stomp/FrameTranslator.java
Fri Jul  9 12:55:21 2010
@@ -121,8 +121,17 @@ public interface FrameTranslator {
             }
 
             // Stomp specific headers
-            o = headers.remove(Stomp.Headers.RECEIPT_REQUESTED);
-            
+            headers.remove(Stomp.Headers.RECEIPT_REQUESTED);
+
+            // Since we take the rest of the header and put them in properties which could
then
+            // be sent back to a STOMP consumer we need to sanitize anything which could
be in
+            // Stomp.Headers.Message and might get passed through to the consumer
+            headers.remove(Stomp.Headers.Message.MESSAGE_ID);
+            headers.remove(Stomp.Headers.Message.TIMESTAMP);
+            headers.remove(Stomp.Headers.Message.REDELIVERED);
+            headers.remove(Stomp.Headers.Message.SUBSCRIPTION);
+            headers.remove(Stomp.Headers.Message.USERID);
+
             // now the general headers
             msg.setProperties(headers);
         }

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/stomp/Stomp.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/stomp/Stomp.java?rev=962512&r1=962511&r2=962512&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/stomp/Stomp.java
(original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/stomp/Stomp.java
Fri Jul  9 12:55:21 2010
@@ -62,7 +62,7 @@ public interface Stomp {
             String EXPIRATION_TIME = "expires";
             String PRIORITY = "priority";
             String TYPE = "type";
-            Object PERSISTENT = "persistent";
+            String PERSISTENT = "persistent";
         }
 
         public interface Message {

Modified: activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/stomp/StompTest.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/stomp/StompTest.java?rev=962512&r1=962511&r2=962512&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/stomp/StompTest.java
(original)
+++ activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/stomp/StompTest.java
Fri Jul  9 12:55:21 2010
@@ -23,6 +23,7 @@ import java.net.URI;
 import java.net.URISyntaxException;
 import java.net.UnknownHostException;
 import java.util.HashMap;
+import java.util.Map;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 import javax.jms.BytesMessage;
@@ -1320,6 +1321,36 @@ public class StompTest extends Combinati
         assertEquals("system", message.getHeaders().get(Stomp.Headers.Message.USERID));
     }
 
+    public void testClientSetMessageIdIsIgnored() throws Exception {
+        HashMap<String, String> headers = new HashMap<String, String>();
+        headers.put(Stomp.Headers.Message.MESSAGE_ID, "Thisisnotallowed");
+        headers.put(Stomp.Headers.Message.TIMESTAMP, "1234");
+        headers.put(Stomp.Headers.Message.REDELIVERED, "true");
+        headers.put(Stomp.Headers.Message.SUBSCRIPTION, "Thisisnotallowed");
+        headers.put(Stomp.Headers.Message.USERID, "Thisisnotallowed");
+
+
+        stompConnection.connect("system", "manager");
+
+
+        stompConnection.send("/queue/" + getQueueName(), "msg", null, headers);
+
+        stompConnection.subscribe("/queue/" + getQueueName());
+        StompFrame stompMessage = stompConnection.receive();
+
+        Map<String, String> mess_headers = new HashMap<String, String>();
+        mess_headers = stompMessage.getHeaders();
+
+        assertFalse("Thisisnotallowed".equals(mess_headers.get(Stomp.Headers.Message.MESSAGE_ID)
+                ));
+        assertFalse("1234".equals(mess_headers.get(Stomp.Headers.Message.TIMESTAMP)));
+        assertNull(mess_headers.get(Stomp.Headers.Message.REDELIVERED));
+        assertNull(mess_headers.get(Stomp.Headers.Message.SUBSCRIPTION));
+        assertEquals("system", mess_headers.get(Stomp.Headers.Message.USERID));
+
+    }
+
+
     protected void assertClients(int expected) throws Exception {
         org.apache.activemq.broker.Connection[] clients = broker.getBroker().getClients();
         int actual = clients.length;



Mime
View raw message