activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chir...@apache.org
Subject git commit: Implements APLO-213: Support an option to set the JMSXUserID openwire header based on the authenticated user.
Date Mon, 03 Feb 2014 16:19:02 GMT
Updated Branches:
  refs/heads/trunk 2937141bb -> 989384b37


Implements APLO-213: Support an option to set the JMSXUserID openwire header based on the
authenticated user.

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

Branch: refs/heads/trunk
Commit: 989384b37a232f22256279208c7c841a6b3e4308
Parents: 2937141
Author: Hiram Chirino <hiram@hiramchirino.com>
Authored: Mon Feb 3 11:18:55 2014 -0500
Committer: Hiram Chirino <hiram@hiramchirino.com>
Committed: Mon Feb 3 11:18:55 2014 -0500

----------------------------------------------------------------------
 .../openwire/OpenwireProtocolHandler.scala      | 12 ++++++++++
 .../apollo/openwire/command/Message.java        |  1 +
 .../apollo/openwire/dto/OpenwireDTO.java        | 17 +++++++++----
 .../test/resources/apollo-openwire-leveldb.xml  |  2 +-
 .../apollo/openwire/test/SecurityTest.scala     | 25 ++++++++++++++++++++
 .../src/documentation/openwire-manual.md        |  1 +
 6 files changed, 52 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq-apollo/blob/989384b3/apollo-openwire/src/main/scala/org/apache/activemq/apollo/openwire/OpenwireProtocolHandler.scala
----------------------------------------------------------------------
diff --git a/apollo-openwire/src/main/scala/org/apache/activemq/apollo/openwire/OpenwireProtocolHandler.scala
b/apollo-openwire/src/main/scala/org/apache/activemq/apollo/openwire/OpenwireProtocolHandler.scala
index 97aa182..fa2bc13 100644
--- a/apollo-openwire/src/main/scala/org/apache/activemq/apollo/openwire/OpenwireProtocolHandler.scala
+++ b/apollo-openwire/src/main/scala/org/apache/activemq/apollo/openwire/OpenwireProtocolHandler.scala
@@ -714,6 +714,18 @@ class OpenwireProtocolHandler extends ProtocolHandler {
   def send_via_route(route:OpenwireDeliveryProducerRoute, message:ActiveMQMessage, uow:StoreUOW)
= {
     // We may need to add some headers..
     val delivery = new Delivery
+
+    if( host.authenticator!=null ) {
+      if( OptionSupport(config.add_jmsxuserid).getOrElse(true) ) {
+        for( name <- host.authenticator.user_name(security_context) ) {
+          var userid = utf8(name)
+          if( userid != message.getUserID ) {
+            message.setUserID(userid)
+          }
+        }
+      }
+    }
+
     delivery.message = new OpenwireMessage(message)
     delivery.expiration = message.getExpiration
     delivery.persistent = message.isPersistent

http://git-wip-us.apache.org/repos/asf/activemq-apollo/blob/989384b3/apollo-openwire/src/main/scala/org/apache/activemq/apollo/openwire/command/Message.java
----------------------------------------------------------------------
diff --git a/apollo-openwire/src/main/scala/org/apache/activemq/apollo/openwire/command/Message.java
b/apollo-openwire/src/main/scala/org/apache/activemq/apollo/openwire/command/Message.java
index 02cddcb..dc60578 100644
--- a/apollo-openwire/src/main/scala/org/apache/activemq/apollo/openwire/command/Message.java
+++ b/apollo-openwire/src/main/scala/org/apache/activemq/apollo/openwire/command/Message.java
@@ -560,6 +560,7 @@ public abstract class Message extends BaseCommand implements MarshallAware
{
     }
 
     public void setUserID(UTF8Buffer jmsxUserID) {
+        cachedEncoding = null;
         this.userID = jmsxUserID;
     }
 

http://git-wip-us.apache.org/repos/asf/activemq-apollo/blob/989384b3/apollo-openwire/src/main/scala/org/apache/activemq/apollo/openwire/dto/OpenwireDTO.java
----------------------------------------------------------------------
diff --git a/apollo-openwire/src/main/scala/org/apache/activemq/apollo/openwire/dto/OpenwireDTO.java
b/apollo-openwire/src/main/scala/org/apache/activemq/apollo/openwire/dto/OpenwireDTO.java
index a356079..feb9319 100644
--- a/apollo-openwire/src/main/scala/org/apache/activemq/apollo/openwire/dto/OpenwireDTO.java
+++ b/apollo-openwire/src/main/scala/org/apache/activemq/apollo/openwire/dto/OpenwireDTO.java
@@ -48,6 +48,8 @@ public class OpenwireDTO extends ProtocolDTO {
     public Long max_frame_size;
     @XmlAttribute(name="buffer_size")
     public String buffer_size;
+    @XmlAttribute(name="add_jmsxuserid")
+    public Boolean add_jmsxuserid;
 
 
     @Override
@@ -58,24 +60,28 @@ public class OpenwireDTO extends ProtocolDTO {
 
         OpenwireDTO that = (OpenwireDTO) o;
 
+        if (buffer_size != null ? !buffer_size.equals(that.buffer_size) : that.buffer_size
!= null)
+            return false;
         if (cache != null ? !cache.equals(that.cache) : that.cache != null)
             return false;
-        if (cache_size != null ? !cache_size.equals(that.cache_size) : that.cache_size !=
null) return false;
+        if (cache_size != null ? !cache_size.equals(that.cache_size) : that.cache_size !=
null)
+            return false;
+        if (add_jmsxuserid != null ? !add_jmsxuserid.equals(that.add_jmsxuserid) : that.add_jmsxuserid
!= null)
+            return false;
         if (max_frame_size != null ? !max_frame_size.equals(that.max_frame_size) : that.max_frame_size
!= null)
             return false;
         if (max_inactivity_duration != null ? !max_inactivity_duration.equals(that.max_inactivity_duration)
: that.max_inactivity_duration != null)
             return false;
         if (max_inactivity_duration_initial_delay != null ? !max_inactivity_duration_initial_delay.equals(that.max_inactivity_duration_initial_delay)
: that.max_inactivity_duration_initial_delay != null)
             return false;
-        if (tcp_no_delay != null ? !tcp_no_delay.equals(that.tcp_no_delay) : that.tcp_no_delay
!= null)
-            return false;
         if (stack_trace != null ? !stack_trace.equals(that.stack_trace) : that.stack_trace
!= null)
             return false;
+        if (tcp_no_delay != null ? !tcp_no_delay.equals(that.tcp_no_delay) : that.tcp_no_delay
!= null)
+            return false;
         if (tight_encoding != null ? !tight_encoding.equals(that.tight_encoding) : that.tight_encoding
!= null)
             return false;
-        if (buffer_size != null ? !buffer_size.equals(that.buffer_size) : that.buffer_size
!= null)
+        if (version != null ? !version.equals(that.version) : that.version != null)
             return false;
-        if (version != null ? !version.equals(that.version) : that.version != null) return
false;
 
         return true;
     }
@@ -93,6 +99,7 @@ public class OpenwireDTO extends ProtocolDTO {
         result = 31 * result + (max_inactivity_duration_initial_delay != null ? max_inactivity_duration_initial_delay.hashCode()
: 0);
         result = 31 * result + (max_frame_size != null ? max_frame_size.hashCode() : 0);
         result = 31 * result + (buffer_size != null ? buffer_size.hashCode() : 0);
+        result = 31 * result + (add_jmsxuserid != null ? add_jmsxuserid.hashCode() : 0);
         return result;
     }
 }

http://git-wip-us.apache.org/repos/asf/activemq-apollo/blob/989384b3/apollo-openwire/src/test/resources/apollo-openwire-leveldb.xml
----------------------------------------------------------------------
diff --git a/apollo-openwire/src/test/resources/apollo-openwire-leveldb.xml b/apollo-openwire/src/test/resources/apollo-openwire-leveldb.xml
index 7e3e84e..79efef9 100644
--- a/apollo-openwire/src/test/resources/apollo-openwire-leveldb.xml
+++ b/apollo-openwire/src/test/resources/apollo-openwire-leveldb.xml
@@ -16,7 +16,7 @@
     limitations under the License.
 -->
 <broker xmlns="http://activemq.apache.org/schema/activemq/apollo">
-  <notes>Has a BDB store enabled.</notes>
+  <notes>Has a LevelDB store enabled.</notes>
 
   <virtual_host id="default">
     <host_name>localhost</host_name>

http://git-wip-us.apache.org/repos/asf/activemq-apollo/blob/989384b3/apollo-openwire/src/test/scala/org/apache/activemq/apollo/openwire/test/SecurityTest.scala
----------------------------------------------------------------------
diff --git a/apollo-openwire/src/test/scala/org/apache/activemq/apollo/openwire/test/SecurityTest.scala
b/apollo-openwire/src/test/scala/org/apache/activemq/apollo/openwire/test/SecurityTest.scala
index b26d7f2..1b4f5d7 100644
--- a/apollo-openwire/src/test/scala/org/apache/activemq/apollo/openwire/test/SecurityTest.scala
+++ b/apollo-openwire/src/test/scala/org/apache/activemq/apollo/openwire/test/SecurityTest.scala
@@ -156,4 +156,29 @@ class SecurityTest extends OpenwireTestSupport with BrokerParallelTestExecution
       consumer.receive();
     }
   }
+
+  test("APLO-213: The JMSXUserID is set to be the authenticated user") {
+
+    val dest = queue(next_id("JMSXUserID"));
+
+    val producer_connection = connect(user="can_send_create_queue", password="can_send_create_queue")
+
+    val producer_session = producer_connection.createSession(false, Session.AUTO_ACKNOWLEDGE)
+    val producer = producer_session.createProducer(dest)
+    try {
+      producer.send(producer_session.createTextMessage("Test Message"))
+    } catch {
+      case e:Throwable => fail("Should not have thrown an exception")
+    }
+
+    val consumer_connection = connect(user="can_consume_queue", password="can_consume_queue")
+    val consumer_session = consumer_connection.createSession(false, Session.AUTO_ACKNOWLEDGE)
+    val consumer = consumer_session.createConsumer(dest)
+
+    val msg = consumer.receive(receive_timeout)
+    msg.getStringProperty("JMSXUserID") should equal("can_send_create_queue")
+
+  }
+
+
 }

http://git-wip-us.apache.org/repos/asf/activemq-apollo/blob/989384b3/apollo-website/src/documentation/openwire-manual.md
----------------------------------------------------------------------
diff --git a/apollo-website/src/documentation/openwire-manual.md b/apollo-website/src/documentation/openwire-manual.md
index 5bfabd8..4c88374 100644
--- a/apollo-website/src/documentation/openwire-manual.md
+++ b/apollo-website/src/documentation/openwire-manual.md
@@ -46,6 +46,7 @@ be closed. Default is `30000`
 * `max_inactivity_duration_initial_delay` : Amount of time to delay between determining the
socket should be closed
 and actually closing it. Default is `30000`
 * `max_frame_size` : Size in bytes of the largest frame that can be sent to the broker. Default
is `100MB`
+* `add_jmsxuserid` : If set to `false`, disables setting the JMSXUserID header on received
messages.  Default is `true`.
 
 An example of configuring the OpenWire protocol
 


Mime
View raw message