You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ch...@apache.org on 2012/08/29 13:10:08 UTC

svn commit: r1378503 - in /activemq/activemq-apollo/trunk/apollo-stomp/src: main/scala/org/apache/activemq/apollo/stomp/StompUdpProtocol.scala test/resources/apollo-stomp-secure.xml test/scala/org/apache/activemq/apollo/stomp/test/StompSecurityTest.scala

Author: chirino
Date: Wed Aug 29 11:10:07 2012
New Revision: 1378503

URL: http://svn.apache.org/viewvc?rev=1378503&view=rev
Log:
Test and Fix for APLO-253: Source IP not always retrieved by the UDP connector

Modified:
    activemq/activemq-apollo/trunk/apollo-stomp/src/main/scala/org/apache/activemq/apollo/stomp/StompUdpProtocol.scala
    activemq/activemq-apollo/trunk/apollo-stomp/src/test/resources/apollo-stomp-secure.xml
    activemq/activemq-apollo/trunk/apollo-stomp/src/test/scala/org/apache/activemq/apollo/stomp/test/StompSecurityTest.scala

Modified: activemq/activemq-apollo/trunk/apollo-stomp/src/main/scala/org/apache/activemq/apollo/stomp/StompUdpProtocol.scala
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-stomp/src/main/scala/org/apache/activemq/apollo/stomp/StompUdpProtocol.scala?rev=1378503&r1=1378502&r2=1378503&view=diff
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-stomp/src/main/scala/org/apache/activemq/apollo/stomp/StompUdpProtocol.scala (original)
+++ activemq/activemq-apollo/trunk/apollo-stomp/src/main/scala/org/apache/activemq/apollo/stomp/StompUdpProtocol.scala Wed Aug 29 11:10:07 2012
@@ -99,7 +99,6 @@ class StompUdpProtocol extends UdpProtoc
       sc.remote_address = udp.from
       sc.session_id = session_id
       if( login.isDefined || passcode.isDefined ) {
-        val sc = new SecurityContext
         for( value <- login ) {
           sc.user = value.toString
           headers = headers.filterNot( _._1 == LOGIN)

Modified: activemq/activemq-apollo/trunk/apollo-stomp/src/test/resources/apollo-stomp-secure.xml
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-stomp/src/test/resources/apollo-stomp-secure.xml?rev=1378503&r1=1378502&r2=1378503&view=diff
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-stomp/src/test/resources/apollo-stomp-secure.xml (original)
+++ activemq/activemq-apollo/trunk/apollo-stomp/src/test/resources/apollo-stomp-secure.xml Wed Aug 29 11:10:07 2012
@@ -26,10 +26,10 @@
   <access_rule allow="can_consume_queue"     kind="queue" action="consume"/>
   <access_rule allow="can_send_create_topic" kind="topic" action="send create"/>
   <access_rule allow="can_send_topic"        kind="topic" action="send"/>
-  <access_rule allow="can_recieve_topic"     kind="topic" action="receive"/>
+  <access_rule allow="can_recieve_topic"     kind="topic" action="receive create"/>
   <access_rule allow="can_consume_create_ds" kind="dsub"  action="consume create"/>
   <access_rule allow="can_consume_ds"        kind="dsub"  action="consume"/>
-  <access_rule allow="can_recieve_topic"     kind="dsub"  action="receive"/>
+  <access_rule allow="can_recieve_topic"     kind="dsub"  action="receive create"/>
 
   <access_rule allow="guest" action="connect"/>
   <access_rule allow="guest" action="create destroy send receive consume" kind="topic queue dsub" id_regex="test.*"/>
@@ -50,5 +50,10 @@
   </connector>
   <connector id="tcp2" bind="tcp://0.0.0.0:0">
   </connector>
+  <connector id="stomp-udp" bind="udp://0.0.0.0:0" protocol="stomp-udp">
+    <stomp>
+      <add_user_header kind="org.apache.activemq.apollo.broker.security.SourceAddressPrincipal">sender-ip</add_user_header>
+    </stomp>
+  </connector>
 
 </broker>
\ No newline at end of file

Modified: activemq/activemq-apollo/trunk/apollo-stomp/src/test/scala/org/apache/activemq/apollo/stomp/test/StompSecurityTest.scala
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-stomp/src/test/scala/org/apache/activemq/apollo/stomp/test/StompSecurityTest.scala?rev=1378503&r1=1378502&r2=1378503&view=diff
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-stomp/src/test/scala/org/apache/activemq/apollo/stomp/test/StompSecurityTest.scala (original)
+++ activemq/activemq-apollo/trunk/apollo-stomp/src/test/scala/org/apache/activemq/apollo/stomp/test/StompSecurityTest.scala Wed Aug 29 11:10:07 2012
@@ -17,6 +17,9 @@
 package org.apache.activemq.apollo.stomp.test
 
 import java.lang.String
+import java.nio.channels.DatagramChannel
+import java.net.InetSocketAddress
+import org.fusesource.hawtbuf.AsciiBuffer
 
 class StompSecurityTest extends StompTestSupport {
 
@@ -223,4 +226,31 @@ class StompSecurityTest extends StompTes
     frame should include("JMSXUserID:can_send_create_consume_queue\n")
     frame should include("sender-ip:127.0.0.1\n")
   }
+
+  test("STOMP UDP to STOMP interop /w Security") {
+
+    connect("1.1", headers=
+            "login:can_recieve_topic\n" +
+            "passcode:can_recieve_topic\n")
+    subscribe("0", "/topic/some-other-udp")
+
+    val udp_port: Int = connector_port("stomp-udp").get
+    val channel = DatagramChannel.open();
+    println("The UDP port is: "+udp_port)
+
+    val target = new InetSocketAddress("127.0.0.1", udp_port)
+    channel.send(new AsciiBuffer(
+      "SEND\n" +
+      "destination:/topic/some-other-udp\n" +
+      "login:can_send_topic\n" +
+      "passcode:can_send_topic\n" +
+      "\n" +
+      "Hello\u0000\n").toByteBuffer, target)
+
+    var frame = client.receive()
+    println(frame)
+    frame should startWith("MESSAGE\n")
+    frame should include regex("\nsender-ip:.+\n")
+    frame should endWith("\n\nHello")
+  }
 }