Search in sources :

Example 86 with HTTPConduit

use of org.apache.cxf.transport.http.HTTPConduit in project cxf by apache.

the class HTTPSConduitTest method testHttpsBasicConnection.

/**
 * This methods tests a basic https connection to Bethal.
 * It supplies an authorization policy with premetive user/pass
 * to avoid the 401.
 */
@Test
public void testHttpsBasicConnection() throws Exception {
    startServer("Bethal");
    URL wsdl = getClass().getResource("greeting.wsdl");
    assertNotNull("WSDL is null", wsdl);
    SOAPService service = new SOAPService(wsdl, serviceName);
    assertNotNull("Service is null", service);
    Greeter bethal = service.getPort(bethalQ, Greeter.class);
    assertNotNull("Port is null", bethal);
    updateAddressPort(bethal, getPort("PORT4"));
    // Okay, I'm sick of configuration files.
    // This also tests dynamic configuration of the conduit.
    Client client = ClientProxy.getClient(bethal);
    HTTPConduit http = (HTTPConduit) client.getConduit();
    HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();
    httpClientPolicy.setAutoRedirect(false);
    // If we set any name, but Edward, Mary, or George,
    // and a password of "password" we will get through
    // Bethal.
    AuthorizationPolicy authPolicy = new AuthorizationPolicy();
    authPolicy.setUserName("Betty");
    authPolicy.setPassword("password");
    http.setClient(httpClientPolicy);
    http.setTlsClientParameters(tlsClientParameters);
    http.setAuthorization(authPolicy);
    configureProxy(client);
    String answer = bethal.sayHi();
    assertTrue("Unexpected answer: " + answer, "Bonjour from Bethal".equals(answer));
    assertProxyRequestCount(0);
}
Also used : SOAPService(org.apache.hello_world.services.SOAPService) HTTPConduit(org.apache.cxf.transport.http.HTTPConduit) AuthorizationPolicy(org.apache.cxf.configuration.security.AuthorizationPolicy) Greeter(org.apache.hello_world.Greeter) HTTPClientPolicy(org.apache.cxf.transports.http.configuration.HTTPClientPolicy) Client(org.apache.cxf.endpoint.Client) URL(java.net.URL) Test(org.junit.Test)

Example 87 with HTTPConduit

use of org.apache.cxf.transport.http.HTTPConduit in project cxf by apache.

the class HTTPSConduitTest method testHttpsTrustRedirect.

@Test
public void testHttpsTrustRedirect() throws Exception {
    startServer("Tarpin");
    startServer("Gordy");
    startServer("Bethal");
    URL wsdl = getClass().getResource("greeting.wsdl");
    assertNotNull("WSDL is null", wsdl);
    SOAPService service = new SOAPService(wsdl, serviceName);
    assertNotNull("Service is null", service);
    Greeter tarpin = service.getPort(tarpinQ, Greeter.class);
    assertNotNull("Port is null", tarpin);
    updateAddressPort(tarpin, getPort("PORT1"));
    // Okay, I'm sick of configuration files.
    // This also tests dynamic configuration of the conduit.
    Client client = ClientProxy.getClient(tarpin);
    HTTPConduit http = (HTTPConduit) client.getConduit();
    HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();
    httpClientPolicy.setAutoRedirect(true);
    // If we set any name, but Edward, Mary, or George,
    // and a password of "password" we will get through
    // Bethal.
    AuthorizationPolicy authPolicy = new AuthorizationPolicy();
    authPolicy.setUserName("Betty");
    authPolicy.setPassword("password");
    http.setClient(httpClientPolicy);
    http.setTlsClientParameters(tlsClientParameters);
    http.setAuthorization(authPolicy);
    // We get redirected from Tarpin, to Gordy, to Bethal.
    MyHttpsTrustDecider trustDecider = new MyHttpsTrustDecider(new String[] { "Tarpin", "Gordy", "Bethal" });
    http.setTrustDecider(trustDecider);
    // We actually get our answer from Bethal at the end of the
    // redirects.
    configureProxy(ClientProxy.getClient(tarpin));
    String answer = tarpin.sayHi();
    assertProxyRequestCount(0);
    assertTrue("Trust Decider wasn't called correctly", 3 == trustDecider.wasCalled());
    assertTrue("Unexpected answer: " + answer, "Bonjour from Bethal".equals(answer));
    // Limit the redirects to 1, since there are two, this should fail.
    http.getClient().setMaxRetransmits(1);
    try {
        answer = tarpin.sayHi();
        fail("Unexpected answer from Tarpin: " + answer);
    } catch (Exception e) {
    // e.printStackTrace();
    }
    assertProxyRequestCount(0);
    // Set back to unlimited.
    http.getClient().setMaxRetransmits(-1);
    // Effectively we will not trust Gordy in the middle.
    trustDecider = new MyHttpsTrustDecider(new String[] { "Tarpin", "Bethal" });
    http.setTrustDecider(trustDecider);
    try {
        answer = tarpin.sayHi();
        fail("Unexpected answer from Tarpin: " + answer);
    } catch (Exception e) {
        // e.printStackTrace();
        assertTrue("Trust Decider wasn't called correctly", 2 == trustDecider.wasCalled());
    }
    assertProxyRequestCount(0);
}
Also used : SOAPService(org.apache.hello_world.services.SOAPService) HTTPConduit(org.apache.cxf.transport.http.HTTPConduit) AuthorizationPolicy(org.apache.cxf.configuration.security.AuthorizationPolicy) Greeter(org.apache.hello_world.Greeter) HTTPClientPolicy(org.apache.cxf.transports.http.configuration.HTTPClientPolicy) Client(org.apache.cxf.endpoint.Client) URL(java.net.URL) GeneralSecurityException(java.security.GeneralSecurityException) UntrustedURLConnectionIOException(org.apache.cxf.transport.http.UntrustedURLConnectionIOException) IOException(java.io.IOException) Test(org.junit.Test)

Example 88 with HTTPConduit

use of org.apache.cxf.transport.http.HTTPConduit in project cxf by apache.

the class HTTPSConduitTest method testHttpsRedirect401Response.

/**
 * This tests redirects through Gordy to Bethal. Bethal will
 * supply a series of 401s. See PushBack401.
 */
@Test
public void testHttpsRedirect401Response() throws Exception {
    startServer("Gordy");
    startServer("Bethal");
    URL wsdl = getClass().getResource("greeting.wsdl");
    assertNotNull("WSDL is null", wsdl);
    SOAPService service = new SOAPService(wsdl, serviceName);
    assertNotNull("Service is null", service);
    Greeter gordy = service.getPort(gordyQ, Greeter.class);
    assertNotNull("Port is null", gordy);
    updateAddressPort(gordy, getPort("PORT3"));
    // Okay, I'm sick of configuration files.
    // This also tests dynamic configuration of the conduit.
    Client client = ClientProxy.getClient(gordy);
    HTTPConduit http = (HTTPConduit) client.getConduit();
    HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();
    httpClientPolicy.setAutoRedirect(true);
    http.setClient(httpClientPolicy);
    http.setTlsClientParameters(tlsClientParameters);
    // We get redirected from Gordy, to Bethal.
    http.setTrustDecider(new MyHttpsTrustDecider(new String[] { "Gordy", "Bethal" }));
    // Without preemptive user/pass Bethal returns a
    // 401 for realm Cronus. If we supply any name other
    // than Edward, George, or Mary, with the pass of "password"
    // we should succeed.
    http.setAuthSupplier(new MyBasicAuthSupplier("Cronus", "Betty", "password"));
    // We actually get our answer from Bethal at the end of the
    // redirects.
    String answer = gordy.sayHi();
    assertTrue("Unexpected answer: " + answer, "Bonjour from Bethal".equals(answer));
    // The loop auth supplier,
    // We should die with looping realms.
    http.setAuthSupplier(new MyBasicAuthSupplier());
    try {
        answer = gordy.sayHi();
        fail("Unexpected answer from Gordy: " + answer);
    } catch (Exception e) {
    // e.printStackTrace();
    }
}
Also used : SOAPService(org.apache.hello_world.services.SOAPService) HTTPConduit(org.apache.cxf.transport.http.HTTPConduit) Greeter(org.apache.hello_world.Greeter) HTTPClientPolicy(org.apache.cxf.transports.http.configuration.HTTPClientPolicy) Client(org.apache.cxf.endpoint.Client) URL(java.net.URL) GeneralSecurityException(java.security.GeneralSecurityException) UntrustedURLConnectionIOException(org.apache.cxf.transport.http.UntrustedURLConnectionIOException) IOException(java.io.IOException) Test(org.junit.Test)

Example 89 with HTTPConduit

use of org.apache.cxf.transport.http.HTTPConduit in project cxf by apache.

the class HTTPSProxyAuthConduitTest method configureProxy.

public void configureProxy(Client client) {
    HTTPConduit cond = (HTTPConduit) client.getConduit();
    HTTPClientPolicy pol = cond.getClient();
    if (pol == null) {
        pol = new HTTPClientPolicy();
        cond.setClient(pol);
    }
    pol.setProxyServer("localhost");
    pol.setProxyServerPort(PROXY_PORT);
    ProxyAuthorizationPolicy auth = new ProxyAuthorizationPolicy();
    auth.setUserName("CXF");
    auth.setPassword("password");
    cond.setProxyAuthorization(auth);
}
Also used : HTTPConduit(org.apache.cxf.transport.http.HTTPConduit) ProxyAuthorizationPolicy(org.apache.cxf.configuration.security.ProxyAuthorizationPolicy) HTTPClientPolicy(org.apache.cxf.transports.http.configuration.HTTPClientPolicy)

Example 90 with HTTPConduit

use of org.apache.cxf.transport.http.HTTPConduit in project cxf by apache.

the class TrustManagerTest method testNoOpX509TrustManager.

// The X509TrustManager is effectively empty here so trust verification should work
@org.junit.Test
public void testNoOpX509TrustManager() throws Exception {
    SpringBusFactory bf = new SpringBusFactory();
    URL busFile = TrustManagerTest.class.getResource("client-trust.xml");
    Bus bus = bf.createBus(busFile.toString());
    BusFactory.setDefaultBus(bus);
    BusFactory.setThreadDefaultBus(bus);
    URL url = SOAPService.WSDL_LOCATION;
    SOAPService service = new SOAPService(url, SOAPService.SERVICE);
    assertNotNull("Service is null", service);
    final Greeter port = service.getHttpsPort();
    assertNotNull("Port is null", port);
    updateAddressPort(port, PORT);
    TLSClientParameters tlsParams = new TLSClientParameters();
    X509TrustManager trustManager = new NoOpX509TrustManager();
    TrustManager[] trustManagers = new TrustManager[1];
    trustManagers[0] = trustManager;
    tlsParams.setTrustManagers(trustManagers);
    tlsParams.setDisableCNCheck(true);
    Client client = ClientProxy.getClient(port);
    HTTPConduit http = (HTTPConduit) client.getConduit();
    http.setTlsClientParameters(tlsParams);
    assertEquals(port.greetMe("Kitty"), "Hello Kitty");
    ((java.io.Closeable) port).close();
    bus.shutdown(true);
}
Also used : SOAPService(org.apache.hello_world.services.SOAPService) Bus(org.apache.cxf.Bus) TLSClientParameters(org.apache.cxf.configuration.jsse.TLSClientParameters) URL(java.net.URL) TrustManager(javax.net.ssl.TrustManager) X509TrustManager(javax.net.ssl.X509TrustManager) HTTPConduit(org.apache.cxf.transport.http.HTTPConduit) SpringBusFactory(org.apache.cxf.bus.spring.SpringBusFactory) X509TrustManager(javax.net.ssl.X509TrustManager) Greeter(org.apache.hello_world.Greeter) Client(org.apache.cxf.endpoint.Client)

Aggregations

HTTPConduit (org.apache.cxf.transport.http.HTTPConduit)125 Client (org.apache.cxf.endpoint.Client)52 HTTPClientPolicy (org.apache.cxf.transports.http.configuration.HTTPClientPolicy)47 Test (org.junit.Test)42 URL (java.net.URL)35 Bus (org.apache.cxf.Bus)32 TLSClientParameters (org.apache.cxf.configuration.jsse.TLSClientParameters)32 QName (javax.xml.namespace.QName)22 SpringBusFactory (org.apache.cxf.bus.spring.SpringBusFactory)20 Service (javax.xml.ws.Service)16 KeyStore (java.security.KeyStore)15 AuthorizationPolicy (org.apache.cxf.configuration.security.AuthorizationPolicy)15 Greeter (org.apache.hello_world.Greeter)14 SOAPService (org.apache.hello_world.services.SOAPService)14 TrustManager (javax.net.ssl.TrustManager)13 IOException (java.io.IOException)12 TrustManagerFactory (javax.net.ssl.TrustManagerFactory)11 InputStream (java.io.InputStream)8 X509TrustManager (javax.net.ssl.X509TrustManager)8 BindingProvider (javax.xml.ws.BindingProvider)8