Search in sources :

Example 81 with DoubleItPortType

use of org.example.contract.doubleit.DoubleItPortType in project cxf by apache.

the class PartsTest method testSignedParts.

@org.junit.Test
public void testSignedParts() throws Exception {
    SpringBusFactory bf = new SpringBusFactory();
    URL busFile = PartsTest.class.getResource("client.xml");
    Bus bus = bf.createBus(busFile.toString());
    BusFactory.setDefaultBus(bus);
    BusFactory.setThreadDefaultBus(bus);
    URL wsdl = PartsTest.class.getResource("DoubleItParts.wsdl");
    Service service = Service.create(wsdl, SERVICE_QNAME);
    // Successful invocation
    QName portQName = new QName(NAMESPACE, "DoubleItSignedPartsPort");
    DoubleItPortType port = service.getPort(portQName, DoubleItPortType.class);
    updateAddressPort(port, test.getPort());
    if (test.isStreaming()) {
        SecurityTestUtil.enableStreaming(port);
    }
    assertEquals(50, port.doubleIt(25));
    // This should fail, as the service requires that the Body must be signed
    portQName = new QName(NAMESPACE, "DoubleItSignedPartsPort2");
    port = service.getPort(portQName, DoubleItPortType.class);
    updateAddressPort(port, test.getPort());
    if (test.isStreaming()) {
        SecurityTestUtil.enableStreaming(port);
    }
    try {
        port.doubleIt(25);
        fail("Failure expected on a body which isn't signed");
    } catch (javax.xml.ws.soap.SOAPFaultException ex) {
        String error = "SignedParts";
        assertTrue(ex.getMessage().contains(error) || ex.getMessage().contains("Body must be signed"));
    }
    // This should fail, as the service requires that the To header must be signed
    portQName = new QName(NAMESPACE, "DoubleItSignedPartsPort3");
    port = service.getPort(portQName, DoubleItPortType.class);
    updateAddressPort(port, test.getPort());
    if (test.isStreaming()) {
        SecurityTestUtil.enableStreaming(port);
    }
    try {
        port.doubleIt(25);
        fail("Failure expected on a header which isn't signed");
    } catch (javax.xml.ws.soap.SOAPFaultException ex) {
        String error = "SignedParts";
        assertTrue(ex.getMessage().contains(error) || ex.getMessage().contains("To must be signed"));
    }
    ((java.io.Closeable) port).close();
    bus.shutdown(true);
}
Also used : Bus(org.apache.cxf.Bus) SpringBusFactory(org.apache.cxf.bus.spring.SpringBusFactory) QName(javax.xml.namespace.QName) Service(javax.xml.ws.Service) DoubleItPortType(org.example.contract.doubleit.DoubleItPortType) URL(java.net.URL)

Example 82 with DoubleItPortType

use of org.example.contract.doubleit.DoubleItPortType in project cxf by apache.

the class PartsTest method testRequiredElements.

@org.junit.Test
public void testRequiredElements() throws Exception {
    SpringBusFactory bf = new SpringBusFactory();
    URL busFile = PartsTest.class.getResource("client.xml");
    Bus bus = bf.createBus(busFile.toString());
    BusFactory.setDefaultBus(bus);
    BusFactory.setThreadDefaultBus(bus);
    URL wsdl = PartsTest.class.getResource("DoubleItParts.wsdl");
    Service service = Service.create(wsdl, SERVICE_QNAME);
    // Successful invocation
    QName portQName = new QName(NAMESPACE, "DoubleItRequiredElementsPort");
    DoubleItPortType port = service.getPort(portQName, DoubleItPortType.class);
    updateAddressPort(port, test.getPort());
    if (test.isStreaming()) {
        SecurityTestUtil.enableStreaming(port);
    }
    assertEquals(50, port.doubleIt(25));
    // This should fail, as the service requires a (bad) header
    portQName = new QName(NAMESPACE, "DoubleItRequiredElementsPort2");
    port = service.getPort(portQName, DoubleItPortType.class);
    updateAddressPort(port, test.getPort());
    if (test.isStreaming()) {
        SecurityTestUtil.enableStreaming(port);
    }
    try {
        port.doubleIt(25);
        fail("Failure expected on a required header which isn't present");
    } catch (javax.xml.ws.soap.SOAPFaultException ex) {
        String error = "RequiredElements: No header element";
        assertTrue(ex.getMessage().contains(error) || ex.getMessage().contains("ToTo must be present"));
    }
    ((java.io.Closeable) port).close();
    bus.shutdown(true);
}
Also used : Bus(org.apache.cxf.Bus) SpringBusFactory(org.apache.cxf.bus.spring.SpringBusFactory) QName(javax.xml.namespace.QName) Service(javax.xml.ws.Service) DoubleItPortType(org.example.contract.doubleit.DoubleItPortType) URL(java.net.URL)

Example 83 with DoubleItPortType

use of org.example.contract.doubleit.DoubleItPortType in project cxf by apache.

the class PolicyAlternativeTest method testNoSecurity.

/**
 * The client uses no security - this should fail.
 */
@org.junit.Test
public void testNoSecurity() throws Exception {
    SpringBusFactory bf = new SpringBusFactory();
    URL busFile = PolicyAlternativeTest.class.getResource("client.xml");
    Bus bus = bf.createBus(busFile.toString());
    BusFactory.setDefaultBus(bus);
    BusFactory.setThreadDefaultBus(bus);
    URL wsdl = PolicyAlternativeTest.class.getResource("DoubleItPolicy.wsdl");
    Service service = Service.create(wsdl, SERVICE_QNAME);
    QName portQName = new QName(NAMESPACE, "DoubleItNoSecurityPort");
    DoubleItPortType utPort = service.getPort(portQName, DoubleItPortType.class);
    updateAddressPort(utPort, test.getPort());
    if (test.isStreaming()) {
        SecurityTestUtil.enableStreaming(utPort);
    }
    try {
        utPort.doubleIt(25);
        fail("Failure expected on no Security");
    } catch (javax.xml.ws.soap.SOAPFaultException ex) {
    // expected
    }
    ((java.io.Closeable) utPort).close();
    bus.shutdown(true);
}
Also used : Bus(org.apache.cxf.Bus) SpringBusFactory(org.apache.cxf.bus.spring.SpringBusFactory) QName(javax.xml.namespace.QName) Service(javax.xml.ws.Service) DoubleItPortType(org.example.contract.doubleit.DoubleItPortType) URL(java.net.URL)

Example 84 with DoubleItPortType

use of org.example.contract.doubleit.DoubleItPortType in project cxf by apache.

the class PolicyAlternativeTest method testRequireClientCertToken.

/**
 * The client does not require a client cert so invocation should fail
 *
 * @throws Exception
 */
@org.junit.Test
public void testRequireClientCertToken() throws Exception {
    SpringBusFactory bf = new SpringBusFactory();
    URL busFile = PolicyAlternativeTest.class.getResource("client.xml");
    Bus bus = bf.createBus(busFile.toString());
    BusFactory.setDefaultBus(bus);
    BusFactory.setThreadDefaultBus(bus);
    URL wsdl = PolicyAlternativeTest.class.getResource("DoubleItPolicy.wsdl");
    Service service = Service.create(wsdl, SERVICE_QNAME);
    QName portQName = new QName(NAMESPACE, "DoubleItClientCertPort");
    DoubleItPortType utPort = service.getPort(portQName, DoubleItPortType.class);
    updateAddressPort(utPort, PORT2);
    if (test.isStreaming()) {
        SecurityTestUtil.enableStreaming(utPort);
    }
    try {
        utPort.doubleIt(25);
        fail("Failure expected because no client certificate");
    } catch (javax.xml.ws.soap.SOAPFaultException ex) {
        if (!test.isStreaming()) {
            assertTrue(ex.getMessage().contains("HttpsToken"));
        }
    }
    ((java.io.Closeable) utPort).close();
    bus.shutdown(true);
}
Also used : Bus(org.apache.cxf.Bus) SpringBusFactory(org.apache.cxf.bus.spring.SpringBusFactory) QName(javax.xml.namespace.QName) Service(javax.xml.ws.Service) DoubleItPortType(org.example.contract.doubleit.DoubleItPortType) URL(java.net.URL)

Example 85 with DoubleItPortType

use of org.example.contract.doubleit.DoubleItPortType in project cxf by apache.

the class PolicyAlternativeTest method testAsymmetric.

/**
 * The client uses the Asymmetric policy - this should succeed.
 */
@org.junit.Test
public void testAsymmetric() throws Exception {
    SpringBusFactory bf = new SpringBusFactory();
    URL busFile = PolicyAlternativeTest.class.getResource("client.xml");
    Bus bus = bf.createBus(busFile.toString());
    BusFactory.setDefaultBus(bus);
    BusFactory.setThreadDefaultBus(bus);
    URL wsdl = PolicyAlternativeTest.class.getResource("DoubleItPolicy.wsdl");
    Service service = Service.create(wsdl, SERVICE_QNAME);
    QName portQName = new QName(NAMESPACE, "DoubleItAsymmetricPort");
    DoubleItPortType utPort = service.getPort(portQName, DoubleItPortType.class);
    updateAddressPort(utPort, test.getPort());
    if (test.isStreaming()) {
        SecurityTestUtil.enableStreaming(utPort);
    }
    utPort.doubleIt(25);
    ((java.io.Closeable) utPort).close();
    bus.shutdown(true);
}
Also used : Bus(org.apache.cxf.Bus) SpringBusFactory(org.apache.cxf.bus.spring.SpringBusFactory) QName(javax.xml.namespace.QName) Service(javax.xml.ws.Service) DoubleItPortType(org.example.contract.doubleit.DoubleItPortType) URL(java.net.URL)

Aggregations

URL (java.net.URL)360 QName (javax.xml.namespace.QName)360 Service (javax.xml.ws.Service)360 DoubleItPortType (org.example.contract.doubleit.DoubleItPortType)360 Bus (org.apache.cxf.Bus)354 SpringBusFactory (org.apache.cxf.bus.spring.SpringBusFactory)352 SamlCallbackHandler (org.apache.cxf.systest.ws.saml.client.SamlCallbackHandler)31 Client (org.apache.cxf.endpoint.Client)22 STSClient (org.apache.cxf.ws.security.trust.STSClient)21 HashMap (java.util.HashMap)20 BindingProvider (javax.xml.ws.BindingProvider)17 WSS4JOutInterceptor (org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor)15 WSS4JStaxOutInterceptor (org.apache.cxf.ws.security.wss4j.WSS4JStaxOutInterceptor)13 KeystorePasswordCallback (org.apache.cxf.systest.ws.common.KeystorePasswordCallback)9 Test (org.junit.Test)9 SOAPFaultException (javax.xml.ws.soap.SOAPFaultException)8 BusException (org.apache.cxf.BusException)8 EndpointException (org.apache.cxf.endpoint.EndpointException)8 TokenStore (org.apache.cxf.ws.security.tokenstore.TokenStore)8 WebService (javax.jws.WebService)5