Author: davsclaus
Date: Tue Aug  3 09:40:49 2010
New Revision: 981791

URL: http://svn.apache.org/viewvc?rev=981791&view=rev
Log:
CAMEL-3017: Added unit test for security failure on sending.

Added:
    
camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/tx/JmsToJmsTransactedSecurityTest.java
    
camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/tx/JmsToJmsTransactedSecurityTest.xml
      - copied, changed from r981511, 
camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/tx/JmsToJmsTransactedTest.xml
    
camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/tx/activemq-security.xml
      - copied, changed from r981511, 
camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/tx/activemq.xml
Modified:
    
camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsConfiguration.java

Modified: 
camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsConfiguration.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsConfiguration.java?rev=981791&r1=981790&r2=981791&view=diff
==============================================================================
--- 
camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsConfiguration.java
 (original)
+++ 
camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsConfiguration.java
 Tue Aug  3 09:40:49 2010
@@ -192,7 +192,7 @@ public class JmsConfiguration implements
 
             Assert.notNull(messageCreator, "MessageCreator must not be null");
             MessageProducer producer = createProducer(session, destination);
-            Message message = null;
+            Message message;
             try {
                 message = messageCreator.createMessage(session);
                 doSend(producer, message);
@@ -256,6 +256,9 @@ public class JmsConfiguration implements
                     logger.debug("Sending JMS message to: " + 
producer.getDestination() + " with message: " + message);
                 }
                 super.doSend(producer, message);
+                if (logger.isTraceEnabled()) {
+                    logger.trace("Sent JMS message to: " + 
producer.getDestination() + " with message: " + message);
+                }
             }
         }
     }

Added: 
camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/tx/JmsToJmsTransactedSecurityTest.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/tx/JmsToJmsTransactedSecurityTest.java?rev=981791&view=auto
==============================================================================
--- 
camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/tx/JmsToJmsTransactedSecurityTest.java
 (added)
+++ 
camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/tx/JmsToJmsTransactedSecurityTest.java
 Tue Aug  3 09:40:49 2010
@@ -0,0 +1,86 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.jms.tx;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.junit4.CamelSpringTestSupport;
+import org.junit.Test;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+/**
+ * @version $Revision$
+ */
+public class JmsToJmsTransactedSecurityTest extends CamelSpringTestSupport {
+
+    protected ClassPathXmlApplicationContext createApplicationContext() {
+        return new 
ClassPathXmlApplicationContext("/org/apache/camel/component/jms/tx/JmsToJmsTransactedSecurityTest.xml");
+    }
+
+    protected int getExpectedRouteCount() {
+        return 0;
+    }
+
+    @Test
+    public void testJmsSecurityFailure() throws Exception {
+        context.addRoutes(new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("activemq:queue:foo")
+                        .transacted()
+                        .to("log:foo")
+                        .to("activemq:queue:bar");
+
+                from("activemq:queue:bar").to("mock:bar");
+            }
+        });
+        context.start();
+
+        MockEndpoint mock = getMockEndpoint("mock:bar");
+        mock.expectedMessageCount(0);
+
+        template.sendBody("activemq:queue:foo", "Hello World");
+
+        mock.assertIsSatisfied(3000);
+
+        // should be in DLQ
+        String reply = consumer.receiveBody("activemq:queue:ActiveMQ.DLQ", 
5000, String.class);
+        assertEquals("Hello World", reply);
+    }
+
+    @Test
+    public void testJmsSecurityOK() throws Exception {
+        context.addRoutes(new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:start")
+                        .to("log:start")
+                        .to("activemq:queue:foo");
+
+                from("activemq:queue:foo").to("mock:foo");
+            }
+        });
+        context.start();
+
+        getMockEndpoint("mock:foo").expectedBodiesReceived("Hello World");
+
+        template.sendBody("direct:start", "Hello World");
+
+        assertMockEndpointsSatisfied();
+    }
+
+}

Copied: 
camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/tx/JmsToJmsTransactedSecurityTest.xml
 (from r981511, 
camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/tx/JmsToJmsTransactedTest.xml)
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/tx/JmsToJmsTransactedSecurityTest.xml?p2=camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/tx/JmsToJmsTransactedSecurityTest.xml&p1=camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/tx/JmsToJmsTransactedTest.xml&r1=981511&r2=981791&rev=981791&view=diff
==============================================================================
--- 
camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/tx/JmsToJmsTransactedTest.xml
 (original)
+++ 
camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/tx/JmsToJmsTransactedSecurityTest.xml
 Tue Aug  3 09:40:49 2010
@@ -23,7 +23,12 @@
          http://camel.apache.org/schema/spring 
http://camel.apache.org/schema/spring/camel-spring.xsd";>
 
     <bean id="jmsConnectionFactory" 
class="org.apache.activemq.ActiveMQConnectionFactory">
-        <property name="brokerURL" 
value="vm://localhost?broker.persistent=false&amp;broker.useJmx=false"/>
+        <property name="brokerURL" 
value="vm://myBroker?brokerConfig=xbean:org/apache/camel/component/jms/tx/activemq-security.xml"/>
+        <!-- use scott as user -->
+        <property name="userName" value="scott"/>
+        <property name="password" value="tiger"/>
+        <!-- ensure to send sync so we can catch and handle all security 
related exceptions for sending -->
+        <property name="alwaysSyncSend" value="true"/>
     </bean>
 
     <bean id="jmsTransactionManager" 
class="org.springframework.jms.connection.JmsTransactionManager">
@@ -36,8 +41,4 @@
         <property name="transactionManager" ref="jmsTransactionManager"/>
     </bean>
 
-    <bean id="activemq2" 
class="org.apache.activemq.camel.component.ActiveMQComponent">
-        <property name="brokerURL" 
value="vm://localhost?broker.persistent=false&amp;broker.useJmx=false"/>
-    </bean>
-
 </beans>

Copied: 
camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/tx/activemq-security.xml
 (from r981511, 
camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/tx/activemq.xml)
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/tx/activemq-security.xml?p2=camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/tx/activemq-security.xml&p1=camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/tx/activemq.xml&r1=981511&r2=981791&rev=981791&view=diff
==============================================================================
--- 
camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/tx/activemq.xml
 (original)
+++ 
camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/tx/activemq-security.xml
 Tue Aug  3 09:40:49 2010
@@ -14,7 +14,7 @@
     See the License for the specific language governing permissions and
     limitations under the License.
 -->
-<!-- START SNIPPET: example -->
+
 <beans
         xmlns="http://www.springframework.org/schema/beans";
         xmlns:broker="http://activemq.apache.org/schema/core";
@@ -25,11 +25,36 @@
     <!-- you may want to use a specific activemq-core.xsd version
          that matches your broker, such as activemq-core-5.3.0.xsd -->
 
-    <broker:broker id="broker" useJmx="false" persistent="false" 
dataDirectory="target/activemq">
+    <broker:broker id="broker" useJmx="true" brokerName="myBroker" 
persistent="false" dataDirectory="target/activemq">
+
+        <broker:plugins>
+            <broker:simpleAuthenticationPlugin>
+                <broker:users>
+                    <broker:authenticationUser username="admin" 
password="secret" groups="admin,user"/>
+                    <broker:authenticationUser username="scott" 
password="tiger" groups="user"/>
+                </broker:users>
+            </broker:simpleAuthenticationPlugin>
+
+            <broker:authorizationPlugin>
+                <broker:map>
+                    <broker:authorizationMap>
+                        <broker:authorizationEntries>
+                            <broker:authorizationEntry queue=">" read="admin" 
write="admin" admin="admin"/>
+                            <broker:authorizationEntry queue="foo" 
read="admin,user" write="admin,user" admin="admin,user"/>
+                            <broker:authorizationEntry queue="bar" 
read="admin,user" write="admin" admin="admin,user"/>
+                            <broker:authorizationEntry queue="ActiveMQ.DLQ" 
read="admin,user" write="admin,user" admin="admin,user"/>
+                            <broker:authorizationEntry 
topic="ActiveMQ.Advisory.>" read="admin,user" write="admin,user"
+                                                       admin="admin,user"/>
+                        </broker:authorizationEntries>
+                    </broker:authorizationMap>
+                </broker:map>
+            </broker:authorizationPlugin>
+        </broker:plugins>
+
         <broker:transportConnectors>
-            <broker:transportConnector name="openwire" uri="vm://localhost"/>
+            <broker:transportConnector name="openwire" uri="vm://myBroker"/>
         </broker:transportConnectors>
+
     </broker:broker>
 
 </beans>
-<!-- END SNIPPET: example -->


Reply via email to