servicemix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ff...@apache.org
Subject svn commit: r1092019 - in /servicemix/smx4/features/trunk/cxf/cxf-transport-nmr: pom.xml src/main/java/org/apache/servicemix/cxf/transport/nmr/NMRDestination.java src/test/java/org/apache/servicemix/cxf/transport/nmr/NMRDestinationTest.java
Date Thu, 14 Apr 2011 06:55:45 GMT
Author: ffang
Date: Thu Apr 14 06:55:45 2011
New Revision: 1092019

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

Modified:
    servicemix/smx4/features/trunk/cxf/cxf-transport-nmr/pom.xml
    servicemix/smx4/features/trunk/cxf/cxf-transport-nmr/src/main/java/org/apache/servicemix/cxf/transport/nmr/NMRDestination.java
    servicemix/smx4/features/trunk/cxf/cxf-transport-nmr/src/test/java/org/apache/servicemix/cxf/transport/nmr/NMRDestinationTest.java

Modified: servicemix/smx4/features/trunk/cxf/cxf-transport-nmr/pom.xml
URL: http://svn.apache.org/viewvc/servicemix/smx4/features/trunk/cxf/cxf-transport-nmr/pom.xml?rev=1092019&r1=1092018&r2=1092019&view=diff
==============================================================================
--- servicemix/smx4/features/trunk/cxf/cxf-transport-nmr/pom.xml (original)
+++ servicemix/smx4/features/trunk/cxf/cxf-transport-nmr/pom.xml Thu Apr 14 06:55:45 2011
@@ -38,6 +38,11 @@
             <artifactId>org.apache.servicemix.nmr.api</artifactId>
         </dependency>
         <dependency>
+            <groupId>org.apache.servicemix.nmr</groupId>
+            <artifactId>org.apache.servicemix.nmr.core</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
             <groupId>org.apache.cxf</groupId>
             <artifactId>cxf-bundle</artifactId>
         </dependency>

Modified: servicemix/smx4/features/trunk/cxf/cxf-transport-nmr/src/main/java/org/apache/servicemix/cxf/transport/nmr/NMRDestination.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/features/trunk/cxf/cxf-transport-nmr/src/main/java/org/apache/servicemix/cxf/transport/nmr/NMRDestination.java?rev=1092019&r1=1092018&r2=1092019&view=diff
==============================================================================
--- servicemix/smx4/features/trunk/cxf/cxf-transport-nmr/src/main/java/org/apache/servicemix/cxf/transport/nmr/NMRDestination.java
(original)
+++ servicemix/smx4/features/trunk/cxf/cxf-transport-nmr/src/main/java/org/apache/servicemix/cxf/transport/nmr/NMRDestination.java
Thu Apr 14 06:55:45 2011
@@ -65,14 +65,25 @@ public class NMRDestination extends Abst
         this.nmr = nmr;
         this.properties = new HashMap<String, Object>();
         String address = info.getAddress();
+        if (address != null && address.indexOf(Endpoint.RUN_AS_SUBJECT) >= 0)
{
+        	String asSubject = address.substring(address.indexOf(Endpoint.RUN_AS_SUBJECT) 
+        			+ Endpoint.RUN_AS_SUBJECT.length() + 1);
+        	this.properties.put(Endpoint.RUN_AS_SUBJECT, asSubject);
+        }
         if (address != null && address.startsWith("nmr:")) {
-            this.properties.put(Endpoint.NAME, address.substring(4, info.getAddress().length()));
+        	if (address.indexOf("?") > 0) {
+        		this.properties.put(Endpoint.NAME, address.substring(4, address.indexOf("?")));
+        	} else {
+        		this.properties.put(Endpoint.NAME, address.substring(4));
+        	}
         } else {
             this.properties.put(Endpoint.NAME, info.getName().toString());
         }
         
         this.properties.put(Endpoint.SERVICE_NAME, info.getService().getName().toString());
         this.properties.put(Endpoint.INTERFACE_NAME, info.getInterface().getName().toString());
+        
+        
     }
 
     public void setChannel(Channel dc) {

Modified: servicemix/smx4/features/trunk/cxf/cxf-transport-nmr/src/test/java/org/apache/servicemix/cxf/transport/nmr/NMRDestinationTest.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/features/trunk/cxf/cxf-transport-nmr/src/test/java/org/apache/servicemix/cxf/transport/nmr/NMRDestinationTest.java?rev=1092019&r1=1092018&r2=1092019&view=diff
==============================================================================
--- servicemix/smx4/features/trunk/cxf/cxf-transport-nmr/src/test/java/org/apache/servicemix/cxf/transport/nmr/NMRDestinationTest.java
(original)
+++ servicemix/smx4/features/trunk/cxf/cxf-transport-nmr/src/test/java/org/apache/servicemix/cxf/transport/nmr/NMRDestinationTest.java
Thu Apr 14 06:55:45 2011
@@ -20,9 +20,11 @@
 package org.apache.servicemix.cxf.transport.nmr;
 
 import java.io.ByteArrayInputStream;
+import java.security.AccessController;
 import java.util.HashMap;
 import java.util.logging.Logger;
 
+import javax.security.auth.Subject;
 import javax.xml.namespace.QName;
 import javax.xml.transform.Source;
 import javax.xml.transform.stream.StreamSource;
@@ -37,8 +39,13 @@ import org.apache.cxf.service.model.Inte
 import org.apache.cxf.service.model.ServiceInfo;
 import org.apache.cxf.transport.MessageObserver;
 import org.apache.servicemix.nmr.api.Channel;
+import org.apache.servicemix.nmr.api.Endpoint;
 import org.apache.servicemix.nmr.api.EndpointRegistry;
+import org.apache.servicemix.nmr.api.Pattern;
 import org.apache.servicemix.nmr.api.Status;
+import org.apache.servicemix.nmr.api.security.UserPrincipal;
+import org.apache.servicemix.nmr.api.service.ServiceHelper;
+import org.apache.servicemix.nmr.core.ServiceMix;
 import org.easymock.EasyMock;
 
 
@@ -139,4 +146,53 @@ public class NMRDestinationTest extends 
         destination.process(xchg);
         assertNotNull(inMessage);
     }
+    
+    @Test
+    public void testNMRDestinationRunAsSubjct() throws Exception {
+    	ServiceMix smx = new ServiceMix();
+        smx.init();
+        nmr = smx;
+        EndpointInfo ei = new EndpointInfo();
+        ei.setAddress("nmr:dumy?RUN_AS_SUBJECT=true");
+        ei.setName(new QName("http://test", "endpoint"));
+        ServiceInfo si = new ServiceInfo();
+        si.setName(new QName("http://test", "service"));
+        InterfaceInfo interInfo = new InterfaceInfo(si, new QName("http://test", "interface"));
+        si.setInterface(interInfo);
+        ei.setService(si);
+        nmrTransportFactory.setNmr(nmr);
+        NMRDestination destination = (NMRDestination) nmrTransportFactory.getDestination(ei);
+        destination.activate();
+               
+        assertNotNull(destination);
+        
+        Subject subject = new Subject();
+        subject.getPrincipals().add(new UserPrincipal("ffang"));
+
+        Channel channel = nmr.createChannel();
+        org.apache.servicemix.nmr.api.Exchange exchange = channel.createExchange(Pattern.InOut);
+        exchange.setTarget(
+                nmr.getEndpointRegistry().lookup(ServiceHelper.createMap(Endpoint.NAME, "dumy")));
+        exchange.getIn().setSecuritySubject(subject);
+        Source source = new StreamSource(new ByteArrayInputStream(
+                "<message>TestHelloWorld</message>".getBytes()));
+        exchange.getIn().setBody(source);
+        observer = new MessageObserver() {
+            public void onMessage(Message m) {                    
+                inMessage = m;
+                Subject receivedSubject = 
+                	(Subject)inMessage.get(NMRTransportFactory.NMR_SECURITY_SUBJECT);
+                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);
+            }
+        };
+        destination.setMessageObserver(observer);
+        channel.send(exchange);       
+        Thread.sleep(2000);
+        assertNotNull(inMessage);
+    }
 }



Mime
View raw message