Search in sources :

Example 76 with DoubleItPortType

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

the class HTTPGetTest method testSOAPClientSecurityPolicy.

@org.junit.Test
public void testSOAPClientSecurityPolicy() throws Exception {
    if (!unrestrictedPoliciesInstalled) {
        return;
    }
    SpringBusFactory bf = new SpringBusFactory();
    URL busFile = HTTPGetTest.class.getResource("client.xml");
    Bus bus = bf.createBus(busFile.toString());
    BusFactory.setDefaultBus(bus);
    BusFactory.setThreadDefaultBus(bus);
    URL wsdl = HTTPGetTest.class.getResource("DoubleItHTTPGet.wsdl");
    Service service = Service.create(wsdl, SERVICE_QNAME);
    QName portQName = new QName(NAMESPACE, "DoubleItKeyIdentifierPort");
    DoubleItPortType x509Port = service.getPort(portQName, DoubleItPortType.class);
    updateAddressPort(x509Port, PORT);
    int result = x509Port.doubleIt(25);
    assertEquals(result, 50);
    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 77 with DoubleItPortType

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

the class HttpsTokenTest method testNoClientCertRequirement.

@org.junit.Test
public void testNoClientCertRequirement() throws Exception {
    SpringBusFactory bf = new SpringBusFactory();
    URL busFile = HttpsTokenTest.class.getResource("client.xml");
    Bus bus = bf.createBus(busFile.toString());
    BusFactory.setDefaultBus(bus);
    BusFactory.setThreadDefaultBus(bus);
    URL wsdl = HttpsTokenTest.class.getResource("DoubleItHttps.wsdl");
    Service service = Service.create(wsdl, SERVICE_QNAME);
    QName portQName = new QName(NAMESPACE, "DoubleItNoClientCertRequirementPort");
    DoubleItPortType port = service.getPort(portQName, DoubleItPortType.class);
    updateAddressPort(port, test.getPort());
    if (test.isStreaming()) {
        SecurityTestUtil.enableStreaming(port);
    }
    try {
        port.doubleIt(25);
        fail("(Policy) Failure expected on not using a client cert");
    } catch (Exception ex) {
    // expected
    }
    // This should work, as we're disable the RequireClientCertificate check via a
    // JAX-WS property
    portQName = new QName(NAMESPACE, "DoubleItNoClientCertRequirementPort2");
    port = service.getPort(portQName, DoubleItPortType.class);
    updateAddressPort(port, test.getPort());
    if (test.isStreaming()) {
        SecurityTestUtil.enableStreaming(port);
    }
    assertEquals(50, port.doubleIt(25));
    ((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 78 with DoubleItPortType

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

the class MTOMSecurityTest method testAsymmetricBytesInAttachment.

// Here we moving encrypted bytes to attachments instead, and referencing them via xop:Include
// This avoids the BASE-64 encoding/decoding step when the raw bytes are included in the SOAP Envelope
@org.junit.Test
public void testAsymmetricBytesInAttachment() throws Exception {
    SpringBusFactory bf = new SpringBusFactory();
    URL busFile = MTOMSecurityTest.class.getResource("client.xml");
    Bus bus = bf.createBus(busFile.toString());
    BusFactory.setDefaultBus(bus);
    BusFactory.setThreadDefaultBus(bus);
    URL wsdl = MTOMSecurityTest.class.getResource("DoubleItMtom.wsdl");
    Service service = Service.create(wsdl, SERVICE_QNAME);
    QName portQName = new QName(NAMESPACE, "DoubleItAsymmetricPort");
    DoubleItPortType port = service.getPort(portQName, DoubleItPortType.class);
    updateAddressPort(port, PORT);
    int result = port.doubleIt(25);
    assertEquals(result, 50);
    ((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 79 with DoubleItPortType

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

the class PartsTest method testSignedElements.

@org.junit.Test
public void testSignedElements() 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, "DoubleItSignedElementsPort");
    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 To header must be signed
    portQName = new QName(NAMESPACE, "DoubleItSignedElementsPort2");
    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 = "SignedElements";
        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 80 with DoubleItPortType

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

the class PartsTest method testEncryptedParts.

@org.junit.Test
public void testEncryptedParts() 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, "DoubleItEncryptedPartsPort");
    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 encrypted
    portQName = new QName(NAMESPACE, "DoubleItEncryptedPartsPort2");
    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 encrypted");
    } catch (javax.xml.ws.soap.SOAPFaultException ex) {
        String error = "EncryptedParts";
        assertTrue(ex.getMessage().contains(error) || ex.getMessage().contains("Body must be encrypted"));
    }
    // This should fail, as the service requires that the To header must be encrypted
    portQName = new QName(NAMESPACE, "DoubleItEncryptedPartsPort3");
    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 encrypted");
    } catch (javax.xml.ws.soap.SOAPFaultException ex) {
        String error = "EncryptedParts";
        assertTrue(ex.getMessage().contains(error) || ex.getMessage().contains("To must be encrypted"));
    }
    ((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)

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