Search in sources :

Example 6 with SOAPService

use of org.apache.hello_world.services.SOAPService in project cxf by apache.

the class CertConstraintsTest method testFailedCall.

public final void testFailedCall(String address) throws Exception {
    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);
    BindingProvider provider = (BindingProvider) port;
    provider.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, address);
    try {
        assertEquals(port.greetMe("Kitty"), "Hello Kitty");
        fail("Failure expected");
    } catch (javax.xml.ws.soap.SOAPFaultException ex) {
    // expected
    } catch (javax.xml.ws.WebServiceException ex) {
    // expected
    }
}
Also used : SOAPService(org.apache.hello_world.services.SOAPService) Greeter(org.apache.hello_world.Greeter) BindingProvider(javax.xml.ws.BindingProvider) URL(java.net.URL)

Example 7 with SOAPService

use of org.apache.hello_world.services.SOAPService in project cxf by apache.

the class HostnameVerificationTest method testSubjectAlternativeNameNoMatch.

// Subject Alternative Name does not match (but the CN does - still an error)
@org.junit.Test
public void testSubjectAlternativeNameNoMatch() throws Exception {
    SpringBusFactory bf = new SpringBusFactory();
    URL busFile = HostnameVerificationTest.class.getResource("hostname-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, PORT2);
    try {
        port.greetMe("Kitty");
        fail("Failure expected on a non-matching subject alternative name");
    } catch (Exception ex) {
    // expected
    }
    // Enable Async
    ((BindingProvider) port).getRequestContext().put("use.async.http.conduit", true);
    try {
        port.greetMe("Kitty");
        fail("Failure expected on a non-matching subject alternative name");
    } catch (Exception ex) {
    // expected
    }
    ((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)

Example 8 with SOAPService

use of org.apache.hello_world.services.SOAPService in project cxf by apache.

the class HostnameVerificationTest method testNoSubjectAlternativeNameNoCNMatch.

// No Subject Alternative Name, no matching CN
@org.junit.Test
public void testNoSubjectAlternativeNameNoCNMatch() throws Exception {
    SpringBusFactory bf = new SpringBusFactory();
    URL busFile = HostnameVerificationTest.class.getResource("hostname-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);
    try {
        port.greetMe("Kitty");
        fail("Failure expected with no matching Subject Alt Name or CN");
    } catch (Exception ex) {
    // expected
    }
    // Enable Async
    ((BindingProvider) port).getRequestContext().put("use.async.http.conduit", true);
    try {
        port.greetMe("Kitty");
        fail("Failure expected with no matching Subject Alt Name or CN");
    } catch (Exception ex) {
    // expected
    }
    ((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)

Example 9 with SOAPService

use of org.apache.hello_world.services.SOAPService in project cxf by apache.

the class HostnameVerificationTest method testSubjectAlternativeNameMatch.

// Subject Alternative Name matches (but not the CN)
@org.junit.Test
public void testSubjectAlternativeNameMatch() throws Exception {
    SpringBusFactory bf = new SpringBusFactory();
    URL busFile = HostnameVerificationTest.class.getResource("hostname-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, PORT);
    assertEquals(port.greetMe("Kitty"), "Hello Kitty");
    // Enable Async
    ((BindingProvider) port).getRequestContext().put("use.async.http.conduit", true);
    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) SpringBusFactory(org.apache.cxf.bus.spring.SpringBusFactory) Greeter(org.apache.hello_world.Greeter) URL(java.net.URL)

Example 10 with SOAPService

use of org.apache.hello_world.services.SOAPService in project cxf by apache.

the class TrustManagerTest method testValidServerCertX509TrustManager2.

// Here the Trust Manager checks the server cert. this time we are invoking on the
// service that is configured in code (not by spring)
@org.junit.Test
public void testValidServerCertX509TrustManager2() 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, PORT3);
    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)

Aggregations

Greeter (org.apache.hello_world.Greeter)57 SOAPService (org.apache.hello_world.services.SOAPService)57 URL (java.net.URL)56 Bus (org.apache.cxf.Bus)41 SpringBusFactory (org.apache.cxf.bus.spring.SpringBusFactory)40 Client (org.apache.cxf.endpoint.Client)14 HTTPConduit (org.apache.cxf.transport.http.HTTPConduit)14 Test (org.junit.Test)13 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 UntrustedURLConnectionIOException (org.apache.cxf.transport.http.UntrustedURLConnectionIOException)3 MalformedURLException (java.net.MalformedURLException)2 InputStream (java.io.InputStream)1