Search in sources :

Example 11 with Greeter

use of org.apache.hello_world.Greeter in project cxf by apache.

the class TrustManagerTest method testValidServerCertX509TrustManager.

// Here the Trust Manager checks the server cert
@org.junit.Test
public void testValidServerCertX509TrustManager() 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);
    String validPrincipalName = "CN=Bethal,OU=Bethal,O=ApacheTest,L=Syracuse,C=US";
    TLSClientParameters tlsParams = new TLSClientParameters();
    X509TrustManager trustManager = new ServerCertX509TrustManager(validPrincipalName);
    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)

Example 12 with Greeter

use of org.apache.hello_world.Greeter in project cxf by apache.

the class TrustManagerTest method testOSCPOverride.

@org.junit.Test
public void testOSCPOverride() 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, PORT2);
    // Read truststore
    KeyStore ts = KeyStore.getInstance("JKS");
    try (InputStream trustStore = ClassLoaderUtils.getResourceAsStream("keys/cxfca.jks", TrustManagerTest.class)) {
        ts.load(trustStore, "password".toCharArray());
    }
    try {
        Security.setProperty("ocsp.enable", "true");
        PKIXBuilderParameters param = new PKIXBuilderParameters(ts, new X509CertSelector());
        param.setRevocationEnabled(true);
        TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
        tmf.init(new CertPathTrustManagerParameters(param));
        TLSClientParameters tlsParams = new TLSClientParameters();
        tlsParams.setTrustManagers(tmf.getTrustManagers());
        tlsParams.setDisableCNCheck(true);
        Client client = ClientProxy.getClient(port);
        HTTPConduit http = (HTTPConduit) client.getConduit();
        http.setTlsClientParameters(tlsParams);
        try {
            port.greetMe("Kitty");
            fail("Failure expected on an invalid OCSP responder URL");
        } catch (Exception ex) {
        // expected
        }
    } finally {
        Security.setProperty("ocsp.enable", "false");
    }
    ((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) InputStream(java.io.InputStream) PKIXBuilderParameters(java.security.cert.PKIXBuilderParameters) CertPathTrustManagerParameters(javax.net.ssl.CertPathTrustManagerParameters) X509CertSelector(java.security.cert.X509CertSelector) KeyStore(java.security.KeyStore) URL(java.net.URL) CertificateException(java.security.cert.CertificateException) HTTPConduit(org.apache.cxf.transport.http.HTTPConduit) SpringBusFactory(org.apache.cxf.bus.spring.SpringBusFactory) Greeter(org.apache.hello_world.Greeter) TrustManagerFactory(javax.net.ssl.TrustManagerFactory) Client(org.apache.cxf.endpoint.Client)

Example 13 with Greeter

use of org.apache.hello_world.Greeter in project cxf by apache.

the class UDPTransportTest method testLargeRequest.

@Test
public void testLargeRequest() throws Exception {
    JaxWsProxyFactoryBean fact = new JaxWsProxyFactoryBean();
    fact.setAddress("udp://localhost:" + PORT);
    Greeter g = fact.create(Greeter.class);
    StringBuilder b = new StringBuilder(100000);
    for (int x = 0; x < 6500; x++) {
        b.append("Hello ");
    }
    assertEquals("Hello " + b.toString(), g.greetMe(b.toString()));
    ((java.io.Closeable) g).close();
}
Also used : Greeter(org.apache.hello_world.Greeter) JaxWsProxyFactoryBean(org.apache.cxf.jaxws.JaxWsProxyFactoryBean) Test(org.junit.Test)

Example 14 with Greeter

use of org.apache.hello_world.Greeter in project cxf by apache.

the class UDPTransportTest method testBroadcastUDP.

@Test
public void testBroadcastUDP() throws Exception {
    // Disable the test on Redhat Enterprise Linux which doesn't enable the UDP broadcast by default
    if (System.getProperties().getProperty("os.name").equals("Linux") && System.getProperties().getProperty("os.version").indexOf("el") > 0) {
        System.out.println("Skipping broadcast test for REL");
        return;
    }
    Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces();
    int count = 0;
    while (interfaces.hasMoreElements()) {
        NetworkInterface networkInterface = interfaces.nextElement();
        if (!networkInterface.isUp() || networkInterface.isLoopback()) {
            continue;
        }
        count++;
    }
    if (count == 0) {
        // no non-loopbacks, cannot do broadcasts
        System.out.println("Skipping broadcast test");
        return;
    }
    JaxWsProxyFactoryBean fact = new JaxWsProxyFactoryBean();
    fact.setAddress("udp://:" + PORT + "/foo");
    Greeter g = fact.create(Greeter.class);
    assertEquals("Hello World", g.greetMe("World"));
    ((java.io.Closeable) g).close();
}
Also used : Greeter(org.apache.hello_world.Greeter) JaxWsProxyFactoryBean(org.apache.cxf.jaxws.JaxWsProxyFactoryBean) NetworkInterface(java.net.NetworkInterface) Test(org.junit.Test)

Example 15 with Greeter

use of org.apache.hello_world.Greeter in project cxf by apache.

the class SSLv3Test method testTLSClientToEndpointWithSSL3Allowed.

@org.junit.Test
public void testTLSClientToEndpointWithSSL3Allowed() throws Exception {
    // Doesn't work with IBM JDK
    if ("IBM Corporation".equals(System.getProperty("java.vendor"))) {
        return;
    }
    SpringBusFactory bf = new SpringBusFactory();
    URL busFile = SSLv3Test.class.getResource("sslv3-client.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, PORT4);
    port.greetMe("Kitty");
    ((java.io.Closeable) port).close();
    bus.shutdown(true);
}
Also used : SOAPService(org.apache.hello_world.services.SOAPService) Bus(org.apache.cxf.Bus) SpringBusFactory(org.apache.cxf.bus.spring.SpringBusFactory) Greeter(org.apache.hello_world.Greeter) URL(java.net.URL)

Aggregations

Greeter (org.apache.hello_world.Greeter)63 URL (java.net.URL)57 SOAPService (org.apache.hello_world.services.SOAPService)57 Bus (org.apache.cxf.Bus)42 SpringBusFactory (org.apache.cxf.bus.spring.SpringBusFactory)40 Test (org.junit.Test)19 Client (org.apache.cxf.endpoint.Client)14 HTTPConduit (org.apache.cxf.transport.http.HTTPConduit)14 CertificateException (java.security.cert.CertificateException)9 TLSClientParameters (org.apache.cxf.configuration.jsse.TLSClientParameters)8 TrustManager (javax.net.ssl.TrustManager)7 X509TrustManager (javax.net.ssl.X509TrustManager)7 IOException (java.io.IOException)5 HTTPClientPolicy (org.apache.cxf.transports.http.configuration.HTTPClientPolicy)5 AuthorizationPolicy (org.apache.cxf.configuration.security.AuthorizationPolicy)4 GeneralSecurityException (java.security.GeneralSecurityException)3 BindingProvider (javax.xml.ws.BindingProvider)3 JaxWsProxyFactoryBean (org.apache.cxf.jaxws.JaxWsProxyFactoryBean)3 UntrustedURLConnectionIOException (org.apache.cxf.transport.http.UntrustedURLConnectionIOException)3 MalformedURLException (java.net.MalformedURLException)2