Index: activemq-core/src/test/java/org/apache/activemq/security/SecurityTestSupport.java
===================================================================
--- activemq-core/src/test/java/org/apache/activemq/security/SecurityTestSupport.java	(revision 449711)
+++ activemq-core/src/test/java/org/apache/activemq/security/SecurityTestSupport.java	(working copy)
@@ -18,7 +18,9 @@
 package org.apache.activemq.security;
 
 import org.apache.activemq.JmsTestSupport;
+import org.apache.activemq.broker.BrokerService;
 import org.apache.activemq.command.ActiveMQDestination;
+import org.apache.activemq.command.ActiveMQMessage;
 import org.apache.activemq.command.ActiveMQQueue;
 import org.apache.activemq.command.ActiveMQTopic;
 
@@ -37,6 +39,15 @@
 
     public ActiveMQDestination destination;
 
+    /**
+     * Overrides to set the JMSXUserID flag to true.
+     */
+    protected BrokerService createBroker() throws Exception {
+        BrokerService broker = super.createBroker();
+        broker.setPopulateJMSXUserID(true);
+        return broker;
+    }
+
     public void testUserReceiveFails() throws JMSException {
         doReceive(true);
     }
@@ -74,7 +85,9 @@
     }
 
     public void testUserReceiveSucceeds() throws JMSException {
-        doReceive(false);
+        Message m = doReceive(false);
+        assertEquals("system", ((ActiveMQMessage)m).getUserID());
+        assertEquals("system", m.getStringProperty("JMSXUserID"));
     }
 
     public void testGuestReceiveSucceeds() throws JMSException {
@@ -86,7 +99,9 @@
     }
 
     public void testUserSendSucceeds() throws JMSException {
-        doSend(false);
+        Message m = doSend(false);
+        assertEquals("user", ((ActiveMQMessage)m).getUserID());
+        assertEquals("user", m.getStringProperty("JMSXUserID"));
     }
 
     public void testUserSendFails() throws JMSException {
@@ -104,7 +119,7 @@
     /**
      * @throws JMSException
      */
-    public void doSend(boolean fail) throws JMSException {
+    public Message doSend(boolean fail) throws JMSException {
 
         Connection adminConnection = factory.createConnection("system", "manager");
         connections.add(adminConnection);
@@ -134,13 +149,13 @@
             assertEquals("0", ((TextMessage) m).getText());
             assertNull(consumer.receiveNoWait());
         }
-
+        return m;
     }
 
     /**
      * @throws JMSException
      */
-    public void doReceive(boolean fail) throws JMSException {
+    public Message doReceive(boolean fail) throws JMSException {
 
         connection.start();
         Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
@@ -152,7 +167,7 @@
         }
         catch (JMSException e) {
             if (fail && e.getCause() instanceof SecurityException)
-                return;
+                return null;
             throw e;
         }
 
@@ -165,9 +180,13 @@
         assertNotNull(m);
         assertEquals("0", ((TextMessage) m).getText());
         assertNull(consumer.receiveNoWait());
+        return m;
 
     }
 
+    /**
+     * @see {@link CombinationTestSupport}
+     */
     public void initCombosForTestUserReceiveFails() {
         addCombinationValues("userName", new Object[] { "user" });
         addCombinationValues("password", new Object[] { "password" });
@@ -175,23 +194,35 @@
                 new ActiveMQTopic("GUEST.BAR"), });
     }
 
+    /**
+     * @see {@link CombinationTestSupport}
+     */
     public void initCombosForTestInvalidAuthentication() {
         addCombinationValues("userName", new Object[] { "user" });
         addCombinationValues("password", new Object[] { "password" });
     }
 
+    /**
+     * @see {@link CombinationTestSupport}
+     */
     public void initCombosForTestUserReceiveSucceeds() {
         addCombinationValues("userName", new Object[] { "user" });
         addCombinationValues("password", new Object[] { "password" });
         addCombinationValues("destination", new Object[] { new ActiveMQQueue("USERS.FOO"), new ActiveMQTopic("USERS.FOO"), });
     }
 
+    /**
+     * @see {@link CombinationTestSupport}
+     */
     public void initCombosForTestGuestReceiveSucceeds() {
         addCombinationValues("userName", new Object[] { "guest" });
         addCombinationValues("password", new Object[] { "password" });
         addCombinationValues("destination", new Object[] { new ActiveMQQueue("GUEST.BAR"), new ActiveMQTopic("GUEST.BAR"), });
     }
 
+    /**
+     * @see {@link CombinationTestSupport}
+     */
     public void initCombosForTestGuestReceiveFails() {
         addCombinationValues("userName", new Object[] { "guest" });
         addCombinationValues("password", new Object[] { "password" });
@@ -199,6 +230,9 @@
                 new ActiveMQTopic("USERS.FOO"), });
     }
 
+    /**
+     * @see {@link CombinationTestSupport}
+     */
     public void initCombosForTestUserSendSucceeds() {
         addCombinationValues("userName", new Object[] { "user" });
         addCombinationValues("password", new Object[] { "password" });
@@ -206,12 +240,18 @@
                 new ActiveMQTopic("GUEST.BAR"), });
     }
 
+    /**
+     * @see {@link CombinationTestSupport}
+     */
     public void initCombosForTestUserSendFails() {
         addCombinationValues("userName", new Object[] { "user" });
         addCombinationValues("password", new Object[] { "password" });
         addCombinationValues("destination", new Object[] { new ActiveMQQueue("TEST"), new ActiveMQTopic("TEST"), });
     }
 
+    /**
+     * @see {@link CombinationTestSupport}
+     */
     public void initCombosForTestGuestSendFails() {
         addCombinationValues("userName", new Object[] { "guest" });
         addCombinationValues("password", new Object[] { "password" });
@@ -219,6 +259,9 @@
                 new ActiveMQTopic("USERS.FOO"), });
     }
 
+    /**
+     * @see {@link CombinationTestSupport}
+     */
     public void initCombosForTestGuestSendSucceeds() {
         addCombinationValues("userName", new Object[] { "guest" });
         addCombinationValues("password", new Object[] { "password" });
Index: activemq-core/src/test/java/org/apache/activemq/security/SimpleSecurityBrokerSystemTest.java
===================================================================
--- activemq-core/src/test/java/org/apache/activemq/security/SimpleSecurityBrokerSystemTest.java	(revision 449711)
+++ activemq-core/src/test/java/org/apache/activemq/security/SimpleSecurityBrokerSystemTest.java	(working copy)
@@ -124,13 +124,16 @@
         }
     }
 
+    /**
+     * @see {@link CombinationTestSupport}
+     */
     public void initCombos() {
         addCombinationValues("authorizationPlugin", new Object[] { new AuthorizationPlugin(createAuthorizationMap()), });
         addCombinationValues("authenticationPlugin", new Object[] { new SimpleAuthenticationFactory(), new JaasAuthenticationPlugin(), });
     }
 
     protected BrokerService createBroker() throws Exception {
-        BrokerService broker = new BrokerService();
+        BrokerService broker = super.createBroker();
         broker.setPlugins(new BrokerPlugin[] { authorizationPlugin, authenticationPlugin });
         broker.setPersistent(false);
         return broker;
Index: activemq-core/src/main/java/org/apache/activemq/broker/ConnectionContext.java
===================================================================
--- activemq-core/src/main/java/org/apache/activemq/broker/ConnectionContext.java	(revision 449711)
+++ activemq-core/src/main/java/org/apache/activemq/broker/ConnectionContext.java	(working copy)
@@ -72,6 +72,11 @@
 
     public void setSecurityContext(SecurityContext subject) {
         this.securityContext = subject;
+        if (subject != null) {
+            setUserName(subject.getUserName());
+        } else {
+            setUserName(null);
+        }
     }
 
     /**
@@ -202,7 +207,7 @@
         return userName;
     }
 
-    public void setUserName(String userName) {
+    protected void setUserName(String userName) {
         this.userName = userName;
     }
 
