You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by js...@apache.org on 2006/09/26 15:32:53 UTC

svn commit: r450044 - in /incubator/activemq/trunk/activemq-core/src: main/java/org/apache/activemq/broker/ main/java/org/apache/activemq/openwire/ test/java/org/apache/activemq/security/ test/resources/org/apache/activemq/security/

Author: jstrachan
Date: Tue Sep 26 06:32:52 2006
New Revision: 450044

URL: http://svn.apache.org/viewvc?view=rev&rev=450044
Log:
applied patch from Kelly Campbell for AMQ-940 wth thanks

Modified:
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/ConnectionContext.java
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/openwire/OpenWireFormat.java
    incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/security/SecurityTestSupport.java
    incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/security/SimpleSecurityBrokerSystemTest.java
    incubator/activemq/trunk/activemq-core/src/test/resources/org/apache/activemq/security/jaas-broker.xml

Modified: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/ConnectionContext.java
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/ConnectionContext.java?view=diff&rev=450044&r1=450043&r2=450044
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/ConnectionContext.java (original)
+++ incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/ConnectionContext.java Tue Sep 26 06:32:52 2006
@@ -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;
     }
 

Modified: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/openwire/OpenWireFormat.java
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/openwire/OpenWireFormat.java?view=diff&rev=450044&r1=450043&r2=450044
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/openwire/OpenWireFormat.java (original)
+++ incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/openwire/OpenWireFormat.java Tue Sep 26 06:32:52 2006
@@ -46,7 +46,7 @@
     private static final int MARSHAL_CACHE_PREFERED_SIZE = MARSHAL_CACHE_SIZE-100;
     
     private DataStreamMarshaller dataMarshallers[];
-    private int version;
+    private int version = 2;
     private boolean stackTraceEnabled=false;
     private boolean tcpNoDelayEnabled=false;
     private boolean cacheEnabled=false;

Modified: incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/security/SecurityTestSupport.java
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/security/SecurityTestSupport.java?view=diff&rev=450044&r1=450043&r2=450044
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/security/SecurityTestSupport.java (original)
+++ incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/security/SecurityTestSupport.java Tue Sep 26 06:32:52 2006
@@ -17,8 +17,11 @@
  */
 package org.apache.activemq.security;
 
+import org.apache.activemq.CombinationTestSupport;
 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 +40,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 +86,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 +100,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 +120,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 +150,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 +168,7 @@
         }
         catch (JMSException e) {
             if (fail && e.getCause() instanceof SecurityException)
-                return;
+                return null;
             throw e;
         }
 
@@ -165,9 +181,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 +195,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 +231,9 @@
                 new ActiveMQTopic("USERS.FOO"), });
     }
 
+    /**
+     * @see {@link CombinationTestSupport}
+     */
     public void initCombosForTestUserSendSucceeds() {
         addCombinationValues("userName", new Object[] { "user" });
         addCombinationValues("password", new Object[] { "password" });
@@ -206,12 +241,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 +260,9 @@
                 new ActiveMQTopic("USERS.FOO"), });
     }
 
+    /**
+     * @see {@link CombinationTestSupport}
+     */
     public void initCombosForTestGuestSendSucceeds() {
         addCombinationValues("userName", new Object[] { "guest" });
         addCombinationValues("password", new Object[] { "password" });

Modified: incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/security/SimpleSecurityBrokerSystemTest.java
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/security/SimpleSecurityBrokerSystemTest.java?view=diff&rev=450044&r1=450043&r2=450044
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/security/SimpleSecurityBrokerSystemTest.java (original)
+++ incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/security/SimpleSecurityBrokerSystemTest.java Tue Sep 26 06:32:52 2006
@@ -17,6 +17,7 @@
  */
 package org.apache.activemq.security;
 
+import org.apache.activemq.CombinationTestSupport;
 import org.apache.activemq.broker.Broker;
 import org.apache.activemq.broker.BrokerPlugin;
 import org.apache.activemq.broker.BrokerService;
@@ -124,13 +125,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;

Modified: incubator/activemq/trunk/activemq-core/src/test/resources/org/apache/activemq/security/jaas-broker.xml
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-core/src/test/resources/org/apache/activemq/security/jaas-broker.xml?view=diff&rev=450044&r1=450043&r2=450044
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/test/resources/org/apache/activemq/security/jaas-broker.xml (original)
+++ incubator/activemq/trunk/activemq-core/src/test/resources/org/apache/activemq/security/jaas-broker.xml Tue Sep 26 06:32:52 2006
@@ -21,7 +21,7 @@
 <beans>
   <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"/>
 
-  <broker useJmx="false" persistent="false" xmlns="http://activemq.org/config/1.0">
+  <broker useJmx="false" persistent="false" xmlns="http://activemq.org/config/1.0" populateJMSXUserID="true">
 
     <plugins>
       <!--  use JAAS to authenticate using the login.config file on the classpath to configure JAAS -->