servicemix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ff...@apache.org
Subject svn commit: r1092582 - in /servicemix/smx4/features/trunk/camel/servicemix-camel/src: main/java/org/apache/servicemix/camel/nmr/ test/java/org/apache/servicemix/camel/nmr/
Date Fri, 15 Apr 2011 04:20:26 GMT
Author: ffang
Date: Fri Apr 15 04:20:25 2011
New Revision: 1092582

URL: http://svn.apache.org/viewvc?rev=1092582&view=rev
Log:
[SMX4-792]Support run as subject for Camel NMR endpoint

Added:
    servicemix/smx4/features/trunk/camel/servicemix-camel/src/test/java/org/apache/servicemix/camel/nmr/RunAsSubjectTest.java
Modified:
    servicemix/smx4/features/trunk/camel/servicemix-camel/src/main/java/org/apache/servicemix/camel/nmr/ServiceMixConsumer.java
    servicemix/smx4/features/trunk/camel/servicemix-camel/src/main/java/org/apache/servicemix/camel/nmr/ServiceMixEndpoint.java

Modified: servicemix/smx4/features/trunk/camel/servicemix-camel/src/main/java/org/apache/servicemix/camel/nmr/ServiceMixConsumer.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/features/trunk/camel/servicemix-camel/src/main/java/org/apache/servicemix/camel/nmr/ServiceMixConsumer.java?rev=1092582&r1=1092581&r2=1092582&view=diff
==============================================================================
--- servicemix/smx4/features/trunk/camel/servicemix-camel/src/main/java/org/apache/servicemix/camel/nmr/ServiceMixConsumer.java
(original)
+++ servicemix/smx4/features/trunk/camel/servicemix-camel/src/main/java/org/apache/servicemix/camel/nmr/ServiceMixConsumer.java
Fri Apr 15 04:20:25 2011
@@ -58,6 +58,7 @@ public class ServiceMixConsumer extends 
         Map<String, Object> result = ServiceHelper.createMap(Endpoint.NAME,
                                                              getEndpoint().getEndpointName());
         result.put(Endpoint.CHANNEL_SYNC_DELIVERY, getEndpoint().isSynchronous());
+        result.put(Endpoint.RUN_AS_SUBJECT, getEndpoint().isRunAsSubject());
         return result;
     }
 

Modified: servicemix/smx4/features/trunk/camel/servicemix-camel/src/main/java/org/apache/servicemix/camel/nmr/ServiceMixEndpoint.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/features/trunk/camel/servicemix-camel/src/main/java/org/apache/servicemix/camel/nmr/ServiceMixEndpoint.java?rev=1092582&r1=1092581&r2=1092582&view=diff
==============================================================================
--- servicemix/smx4/features/trunk/camel/servicemix-camel/src/main/java/org/apache/servicemix/camel/nmr/ServiceMixEndpoint.java
(original)
+++ servicemix/smx4/features/trunk/camel/servicemix-camel/src/main/java/org/apache/servicemix/camel/nmr/ServiceMixEndpoint.java
Fri Apr 15 04:20:25 2011
@@ -33,9 +33,11 @@ import org.apache.camel.Processor;
 public class ServiceMixEndpoint extends DefaultEndpoint {
 
     private static final String SYNCHRONOUS = "synchronous";
+    private static final String RUN_AS_SUBJECT = "RUN_AS_SUBJECT";
 
     private String endpointName;
     private boolean synchronous;
+    private boolean runAsSubject;
 
     public ServiceMixEndpoint(ServiceMixComponent component, String uri, String endpointName)
{
         super(uri, component);
@@ -45,6 +47,7 @@ public class ServiceMixEndpoint extends 
     @Override
     public void configureProperties(Map<String, Object> options) {
         synchronous = Boolean.valueOf((String) options.remove(SYNCHRONOUS));
+        runAsSubject = Boolean.valueOf((String) options.remove(RUN_AS_SUBJECT));
     }
 
     public ServiceMixComponent getComponent() {
@@ -59,6 +62,10 @@ public class ServiceMixEndpoint extends 
         return synchronous;
     }
 
+    public boolean isRunAsSubject() {
+        return runAsSubject;
+    }
+    
     public Producer createProducer() throws Exception {
         return new ServiceMixProducer(this, getComponent().getNmr());
     }

Added: servicemix/smx4/features/trunk/camel/servicemix-camel/src/test/java/org/apache/servicemix/camel/nmr/RunAsSubjectTest.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/features/trunk/camel/servicemix-camel/src/test/java/org/apache/servicemix/camel/nmr/RunAsSubjectTest.java?rev=1092582&view=auto
==============================================================================
--- servicemix/smx4/features/trunk/camel/servicemix-camel/src/test/java/org/apache/servicemix/camel/nmr/RunAsSubjectTest.java
(added)
+++ servicemix/smx4/features/trunk/camel/servicemix-camel/src/test/java/org/apache/servicemix/camel/nmr/RunAsSubjectTest.java
Fri Apr 15 04:20:25 2011
@@ -0,0 +1,75 @@
+/*
+ * 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.servicemix.camel.nmr;
+
+import java.security.AccessController;
+
+import javax.security.auth.Subject;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.servicemix.nmr.api.security.UserPrincipal;
+import org.junit.Test;
+
+public class RunAsSubjectTest  extends AbstractComponentTest {
+
+    private static final String REQUEST_MESSAGE = "Simple message body";
+
+    @Test
+    public void testRunAsSubject() throws InterruptedException {
+        MockEndpoint mock = getMockEndpoint("mock:caught");
+        mock.expectedMessageCount(1);
+
+        template.sendBody("direct:inonly", REQUEST_MESSAGE);
+
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+
+            @Override
+            public void configure() throws Exception {
+            	Subject subject = new Subject();
+                subject.getPrincipals().add(new UserPrincipal("ffang"));
+                from("direct:inonly").setHeader(Exchange.AUTHENTICATION).constant(subject).
+                	to("nmr:helloworld");
+                   
+                from("nmr:helloworld?RUN_AS_SUBJECT=true").process(new SubjectProcessor());
+                    
+            }
+        };
+    }
+
+    class SubjectProcessor implements Processor {
+
+		public void process(Exchange exchange) throws Exception {
+			Subject receivedSubject = 
+            	(Subject)exchange.getIn().getHeader(Exchange.AUTHENTICATION);
+            assertNotNull(receivedSubject);
+            assertEquals(receivedSubject.getPrincipals().size(), 1);
+            assertEquals(receivedSubject.getPrincipals().iterator().next().getName(), "ffang");
+            Subject onBefalfsubject = Subject.getSubject(AccessController.getContext());
+            assertNotNull(onBefalfsubject);
+            assertEquals(onBefalfsubject, receivedSubject);
+			
+		}
+    	
+    }
+}
\ No newline at end of file



Mime
View raw message