Return-Path: Delivered-To: apmail-cxf-commits-archive@www.apache.org Received: (qmail 41834 invoked from network); 19 Jun 2008 06:14:25 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 19 Jun 2008 06:14:25 -0000 Received: (qmail 72076 invoked by uid 500); 19 Jun 2008 06:14:27 -0000 Delivered-To: apmail-cxf-commits-archive@cxf.apache.org Received: (qmail 72028 invoked by uid 500); 19 Jun 2008 06:14:27 -0000 Mailing-List: contact commits-help@cxf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cxf.apache.org Delivered-To: mailing list commits@cxf.apache.org Received: (qmail 72014 invoked by uid 99); 19 Jun 2008 06:14:27 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 18 Jun 2008 23:14:27 -0700 X-ASF-Spam-Status: No, hits=-1998.5 required=10.0 tests=ALL_TRUSTED,WEIRD_PORT X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 19 Jun 2008 06:13:37 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 5612B2388A2B; Wed, 18 Jun 2008 23:13:56 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r669396 - in /cxf/trunk/rt: frontend/simple/src/main/java/org/apache/cxf/frontend/ frontend/simple/src/test/java/org/apache/cxf/frontend/spring/ transports/http/src/test/java/org/apache/cxf/transport/http/ Date: Thu, 19 Jun 2008 06:13:55 -0000 To: commits@cxf.apache.org From: ningjiang@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20080619061356.5612B2388A2B@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: ningjiang Date: Wed Jun 18 23:13:55 2008 New Revision: 669396 URL: http://svn.apache.org/viewvc?rev=669396&view=rev Log: CXF-1617 support set basic authentication from ProxyFactoryBean Modified: cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/ClientFactoryBean.java cxf/trunk/rt/frontend/simple/src/test/java/org/apache/cxf/frontend/spring/SpringBeansTest.java cxf/trunk/rt/frontend/simple/src/test/java/org/apache/cxf/frontend/spring/clients.xml cxf/trunk/rt/transports/http/src/test/java/org/apache/cxf/transport/http/HTTPConduitTest.java Modified: cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/ClientFactoryBean.java URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/ClientFactoryBean.java?rev=669396&r1=669395&r2=669396&view=diff ============================================================================== --- cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/ClientFactoryBean.java (original) +++ cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/ClientFactoryBean.java Wed Jun 18 23:13:55 2008 @@ -21,6 +21,7 @@ import java.util.Map; import org.apache.cxf.BusException; +import org.apache.cxf.configuration.security.AuthorizationPolicy; import org.apache.cxf.databinding.DataBinding; import org.apache.cxf.endpoint.Client; import org.apache.cxf.endpoint.ClientImpl; @@ -33,23 +34,23 @@ public class ClientFactoryBean extends AbstractWSDLBasedEndpointFactory { private Client client; - + public ClientFactoryBean() { this(new ReflectionServiceFactoryBean()); } - public ClientFactoryBean(ReflectionServiceFactoryBean factory) { + public ClientFactoryBean(ReflectionServiceFactoryBean factory) { super(factory); } public Client create() { - + if (client != null) { return client; } applyExtraClass(); try { Endpoint ep = createEndpoint(); - + applyProperties(ep); createClient(ep); initializeAnnotationInterceptors(ep, getServiceClass()); } catch (EndpointException e) { @@ -72,7 +73,7 @@ } } } - + protected void applyExtraClass() { DataBinding dataBinding = getServiceFactory().getDataBinding(); if (dataBinding instanceof JAXBDataBinding) { @@ -83,12 +84,22 @@ } } } - + + + protected void applyProperties(Endpoint ep) { + //Apply the AuthorizationPolicy to the endpointInfo + Map props = this.getProperties(); + if (props != null && props.get(AuthorizationPolicy.class.getName()) != null) { + AuthorizationPolicy ap = (AuthorizationPolicy)props.get(AuthorizationPolicy.class.getName()); + ep.getEndpointInfo().addExtensor(ap); + } + } + public Client getClient() { return client; } public void setClient(Client client) { this.client = client; - } + } } Modified: cxf/trunk/rt/frontend/simple/src/test/java/org/apache/cxf/frontend/spring/SpringBeansTest.java URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/simple/src/test/java/org/apache/cxf/frontend/spring/SpringBeansTest.java?rev=669396&r1=669395&r2=669396&view=diff ============================================================================== --- cxf/trunk/rt/frontend/simple/src/test/java/org/apache/cxf/frontend/spring/SpringBeansTest.java (original) +++ cxf/trunk/rt/frontend/simple/src/test/java/org/apache/cxf/frontend/spring/SpringBeansTest.java Wed Jun 18 23:13:55 2008 @@ -27,6 +27,7 @@ import org.apache.cxf.binding.soap.SoapBindingConfiguration; import org.apache.cxf.binding.soap.saaj.SAAJInInterceptor; import org.apache.cxf.binding.soap.saaj.SAAJOutInterceptor; +import org.apache.cxf.configuration.security.AuthorizationPolicy; import org.apache.cxf.endpoint.Client; import org.apache.cxf.endpoint.NullConduitSelector; import org.apache.cxf.frontend.ClientProxy; @@ -37,66 +38,67 @@ import org.apache.cxf.interceptor.LoggingOutInterceptor; import org.apache.cxf.service.factory.HelloService; import org.apache.cxf.service.factory.HelloServiceImpl; +import org.apache.cxf.service.model.EndpointInfo; import org.junit.Test; import org.springframework.context.support.ClassPathXmlApplicationContext; public class SpringBeansTest extends Assert { - + @Test public void testServers() throws Exception { - ClassPathXmlApplicationContext ctx = + ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(new String[] {"/org/apache/cxf/frontend/spring/servers.xml"}); ServerFactoryBean bean = (ServerFactoryBean) ctx.getBean("simple"); assertNotNull(bean); - + if (!(bean.getServiceBean() instanceof HelloServiceImpl)) { fail("can't get the right serviceBean"); } bean = (ServerFactoryBean) ctx.getBean("inlineImplementor"); if (!(bean.getServiceBean() instanceof HelloServiceImpl)) { fail("can't get the right serviceBean"); - } + } bean = (ServerFactoryBean) ctx.getBean("inlineSoapBinding"); - assertNotNull(bean); - - - + assertNotNull(bean); + + + BindingConfiguration bc = bean.getBindingConfig(); assertTrue(bc instanceof SoapBindingConfiguration); SoapBindingConfiguration sbc = (SoapBindingConfiguration) bc; assertTrue(sbc.getVersion() instanceof Soap12); - + bean = (ServerFactoryBean) ctx.getBean("simpleWithBindingId"); - assertEquals("get the wrong BindingId", + assertEquals("get the wrong BindingId", bean.getBindingId(), "http://cxf.apache.org/bindings/xformat"); - + } - + @Test public void testClients() throws Exception { - ClassPathXmlApplicationContext ctx = + ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(new String[] {"/org/apache/cxf/frontend/spring/clients.xml"}); Object bean = ctx.getBean("client1.proxyFactory"); assertNotNull(bean); - - ClientProxyFactoryBean cpfbean = (ClientProxyFactoryBean)bean; + + ClientProxyFactoryBean cpfbean = (ClientProxyFactoryBean)bean; BindingConfiguration bc = cpfbean.getBindingConfig(); assertTrue(bc instanceof SoapBindingConfiguration); SoapBindingConfiguration sbc = (SoapBindingConfiguration) bc; assertTrue(sbc.getVersion() instanceof Soap12); - + HelloService greeter = (HelloService) ctx.getBean("client1"); assertNotNull(greeter); - + Client client = ClientProxy.getClient(greeter); assertNotNull("expected ConduitSelector", client.getConduitSelector()); assertTrue("unexpected ConduitSelector", client.getConduitSelector() instanceof NullConduitSelector); - + List inInterceptors = client.getInInterceptors(); boolean saaj = false; boolean logging = false; @@ -109,7 +111,7 @@ } assertTrue(saaj); assertTrue(logging); - + saaj = false; logging = false; for (Interceptor i : client.getOutInterceptors()) { @@ -121,16 +123,26 @@ } assertTrue(saaj); assertTrue(logging); - - ClientProxyFactoryBean clientProxyFactoryBean = + + ClientProxyFactoryBean clientProxyFactoryBean = (ClientProxyFactoryBean) ctx.getBean("client2.proxyFactory"); assertNotNull(clientProxyFactoryBean); - - assertEquals("get the wrong bindingId", + + assertEquals("get the wrong bindingId", clientProxyFactoryBean.getBindingId(), "http://cxf.apache.org/bindings/xformat"); - + greeter = (HelloService) ctx.getBean("client2"); assertNotNull(greeter); + + greeter = (HelloService) ctx.getBean("client3"); + assertNotNull(greeter); + + client = ClientProxy.getClient(greeter); + EndpointInfo epi = client.getEndpoint().getEndpointInfo(); + AuthorizationPolicy ap = epi.getExtensor(AuthorizationPolicy.class); + assertNotNull("The AuthorizationPolicy instance should not be null", ap); + assertEquals("Get the wrong username", ap.getUserName(), "testUser"); + assertEquals("Get the wrong password", ap.getPassword(), "password"); } } Modified: cxf/trunk/rt/frontend/simple/src/test/java/org/apache/cxf/frontend/spring/clients.xml URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/simple/src/test/java/org/apache/cxf/frontend/spring/clients.xml?rev=669396&r1=669395&r2=669396&view=diff ============================================================================== --- cxf/trunk/rt/frontend/simple/src/test/java/org/apache/cxf/frontend/spring/clients.xml (original) +++ cxf/trunk/rt/frontend/simple/src/test/java/org/apache/cxf/frontend/spring/clients.xml Wed Jun 18 23:13:55 2008 @@ -29,7 +29,7 @@ - + @@ -40,11 +40,11 @@ - + - - - - + endpointName="s:XMLPort" + bindingId="http://cxf.apache.org/bindings/xformat"> + + + Modified: cxf/trunk/rt/transports/http/src/test/java/org/apache/cxf/transport/http/HTTPConduitTest.java URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http/src/test/java/org/apache/cxf/transport/http/HTTPConduitTest.java?rev=669396&r1=669395&r2=669396&view=diff ============================================================================== --- cxf/trunk/rt/transports/http/src/test/java/org/apache/cxf/transport/http/HTTPConduitTest.java (original) +++ cxf/trunk/rt/transports/http/src/test/java/org/apache/cxf/transport/http/HTTPConduitTest.java Wed Jun 18 23:13:55 2008 @@ -55,11 +55,11 @@ public class HTTPConduitTest extends Assert { private Message inMessage; private IMocksControl control; - + @Before public void setUp() throws Exception { } - + @After public void tearDown() { } @@ -77,9 +77,9 @@ message.put(Message.PROTOCOL_HEADERS, headers); return message; } - + /** - * This test class is a Basic Auth Supplier with a + * This test class is a Basic Auth Supplier with a * preemptive UserPass. */ class BasicAuthSupplier extends HttpBasicAuthSupplier { @@ -104,14 +104,14 @@ ei.setAddress("http://nowhere.com/bar/foo"); HTTPConduit conduit = new HTTPConduit(bus, ei, null); conduit.finalizeConfig(); - - EndpointReferenceType target = + + EndpointReferenceType target = EndpointReferenceUtils.getEndpointReference( "http://nowhere.com/bar/foo"); - + // Test call EndpointReferenceType ref = conduit.getTarget(); - + assertNotNull("unexpected null target", ref); assertEquals("unexpected target", EndpointReferenceUtils.getAddress(ref), @@ -126,7 +126,7 @@ conduit.getURL().getPath(), "/bar/foo"); } - + /** * Verfies one of the tenents of our interface -- the Conduit sets up * an OutputStream on the message after a "prepare". @@ -140,18 +140,45 @@ conduit.finalizeConfig(); Message message = getNewMessage(); - + // Test call conduit.prepare(message); - - assertNotNull("Conduit should always set output stream.", + + assertNotNull("Conduit should always set output stream.", message.getContent(OutputStream.class)); } + @Test + public void testAuthPolicyFromEndpointInfo() throws Exception { + Bus bus = new CXFBusImpl(); + EndpointInfo ei = new EndpointInfo(); + AuthorizationPolicy ap = new AuthorizationPolicy(); + ap.setPassword("password"); + ap.setUserName("testUser"); + ei.addExtensor(ap); + ei.setAddress("http://nowhere.com/bar/foo"); + HTTPConduit conduit = new HTTPConduit(bus, ei, null); + conduit.finalizeConfig(); + Message message = getNewMessage(); + + // Test call + conduit.prepare(message); + + Map> headers = + CastUtils.cast((Map)message.get(Message.PROTOCOL_HEADERS)); + + assertNotNull("Authorization Header should exist", + headers.get("Authorization")); + + assertEquals("Unexpected Authorization Token", + "Basic " + Base64Utility.encode("testUser:password".getBytes()), + headers.get("Authorization").get(0)); + } + /** * This test verifies the precidence of Authorization Information. * Setting authorization information on the Message takes precidence - * over a Basic Auth Supplier with preemptive UserPass, and that + * over a Basic Auth Supplier with preemptive UserPass, and that * followed by setting it directly on the Conduit. */ @Test @@ -161,58 +188,58 @@ ei.setAddress("http://nowhere.com/bar/foo"); HTTPConduit conduit = new HTTPConduit(bus, ei, null); conduit.finalizeConfig(); - + conduit.getAuthorization().setUserName("Satan"); conduit.getAuthorization().setPassword("hell"); Message message = getNewMessage(); - + // Test call conduit.prepare(message); - + Map> headers = CastUtils.cast((Map)message.get(Message.PROTOCOL_HEADERS)); - + assertNotNull("Authorization Header should exist", headers.get("Authorization")); - - assertEquals("Unexpected Authorization Token", + + assertEquals("Unexpected Authorization Token", "Basic " + Base64Utility.encode("Satan:hell".getBytes()), headers.get("Authorization").get(0)); - + // Setting a Basic Auth User Pass should override conduit.setBasicAuthSupplier(new BasicAuthSupplier()); message = getNewMessage(); - + // Test Call conduit.prepare(message); - + headers = CastUtils.cast((Map)message.get(Message.PROTOCOL_HEADERS)); - assertEquals("Unexpected Authorization Token", + assertEquals("Unexpected Authorization Token", "Basic " + Base64Utility.encode("Gandalf:staff".getBytes()), headers.get("Authorization").get(0)); - + // Setting authorization policy on the message should override all. AuthorizationPolicy authPolicy = new AuthorizationPolicy(); authPolicy.setUserName("Hello"); authPolicy.setPassword("world"); message = getNewMessage(); message.put(AuthorizationPolicy.class, authPolicy); - + conduit.prepare(message); - + headers = CastUtils.cast((Map)message.get(Message.PROTOCOL_HEADERS)); - - assertEquals("Unexpected Authorization Token", + + assertEquals("Unexpected Authorization Token", "Basic " + Base64Utility.encode("Hello:world".getBytes()), headers.get("Authorization").get(0)); } public void testDecoupledEndpoint() throws Exception { control = EasyMock.createNiceControl(); - + Bus bus = new CXFBusImpl(); URL decoupledURL = new URL("http://nowhere.com/response"); @@ -230,31 +257,31 @@ EasyMock.expectLastCall().andReturn(destination); destination.setMessageObserver( EasyMock.isA(HTTPConduit.InterposedMessageObserver.class)); - + control.replay(); - + EndpointInfo ei = new EndpointInfo(); ei.setAddress("http://nowhere.com/bar/foo"); HTTPConduit conduit = new HTTPConduit(bus, ei, null); conduit.finalizeConfig(); - + // Test call conduit.getClient().setDecoupledEndpoint(decoupledURL.toString()); - + assertNotNull("expected back channel", conduit.getBackChannel()); - + MessageObserver observer = new MessageObserver() { public void onMessage(Message m) { inMessage = m; } }; - + // Test call conduit.setMessageObserver(observer); Message incoming = new MessageImpl(); conduit.getDecoupledObserver().onMessage(incoming); - + assertSame("expected pass thru onMessage() notification", inMessage, incoming); @@ -287,5 +314,5 @@ control = null; } } - + }