Search in sources :

Example 16 with WSS4JStaxOutInterceptor

use of org.apache.cxf.ws.security.wss4j.WSS4JStaxOutInterceptor in project cxf by apache.

the class CryptoCoverageCheckerTest method testSignedBodyOnlySoap12.

@org.junit.Test
public void testSignedBodyOnlySoap12() throws Exception {
    SpringBusFactory bf = new SpringBusFactory();
    URL busFile = CryptoCoverageCheckerTest.class.getResource("client.xml");
    Bus bus = bf.createBus(busFile.toString());
    BusFactory.setDefaultBus(bus);
    BusFactory.setThreadDefaultBus(bus);
    URL wsdl = CryptoCoverageCheckerTest.class.getResource("DoubleItCoverageChecker.wsdl");
    Service service = Service.create(wsdl, SERVICE_QNAME);
    QName portQName = new QName(NAMESPACE, "DoubleItBodyTimestampSoap12Port");
    DoubleItPortType port = service.getPort(portQName, DoubleItPortType.class);
    updateAddressPort(port, test.getPort());
    Map<String, Object> outProps = new HashMap<>();
    outProps.put("action", "Timestamp Signature");
    outProps.put("signaturePropFile", "alice.properties");
    outProps.put("user", "alice");
    outProps.put("passwordCallbackClass", "org.apache.cxf.systest.ws.common.KeystorePasswordCallback");
    outProps.put("signatureParts", "{}{http://www.w3.org/2003/05/soap-envelope}Body;");
    if (test.isStreaming()) {
        SecurityTestUtil.enableStreaming(port);
    }
    if (test.isStreaming()) {
        WSS4JStaxOutInterceptor staxOutInterceptor = new WSS4JStaxOutInterceptor(outProps);
        bus.getOutInterceptors().add(staxOutInterceptor);
    } else {
        WSS4JOutInterceptor outInterceptor = new WSS4JOutInterceptor(outProps);
        bus.getOutInterceptors().add(outInterceptor);
    }
    try {
        port.doubleIt(25);
        fail("Failure expected on not signing the Timestamp");
    } catch (Exception ex) {
    // expected
    }
    ((java.io.Closeable) port).close();
    bus.shutdown(true);
}
Also used : WSS4JStaxOutInterceptor(org.apache.cxf.ws.security.wss4j.WSS4JStaxOutInterceptor) Bus(org.apache.cxf.Bus) HashMap(java.util.HashMap) QName(javax.xml.namespace.QName) Service(javax.xml.ws.Service) URL(java.net.URL) SpringBusFactory(org.apache.cxf.bus.spring.SpringBusFactory) DoubleItPortType(org.example.contract.doubleit.DoubleItPortType) WSS4JOutInterceptor(org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor)

Example 17 with WSS4JStaxOutInterceptor

use of org.apache.cxf.ws.security.wss4j.WSS4JStaxOutInterceptor in project cxf by apache.

the class CryptoCoverageCheckerTest method testWSAddressingOptionalSignatureParts.

@org.junit.Test
public void testWSAddressingOptionalSignatureParts() throws Exception {
    SpringBusFactory bf = new SpringBusFactory();
    URL busFile = CryptoCoverageCheckerTest.class.getResource("client.xml");
    Bus bus = bf.createBus(busFile.toString());
    BusFactory.setDefaultBus(bus);
    BusFactory.setThreadDefaultBus(bus);
    URL wsdl = CryptoCoverageCheckerTest.class.getResource("DoubleItCoverageChecker.wsdl");
    Service service = Service.create(wsdl, SERVICE_QNAME);
    QName portQName = new QName(NAMESPACE, "DoubleItWSAPort");
    DoubleItPortType port = service.getPort(portQName, DoubleItPortType.class);
    updateAddressPort(port, test.getPort());
    Map<String, Object> outProps = new HashMap<>();
    outProps.put("action", "Timestamp Signature");
    outProps.put("signaturePropFile", "alice.properties");
    outProps.put("user", "alice");
    outProps.put("passwordCallbackClass", "org.apache.cxf.systest.ws.common.KeystorePasswordCallback");
    outProps.put("optionalSignatureParts", "{}{http://schemas.xmlsoap.org/soap/envelope/}Body;" + "{}{http://docs.oasis-open.org/wss/2004/01/oasis-" + "200401-wss-wssecurity-utility-1.0.xsd}Timestamp;" + "{}{http://www.w3.org/2005/08/addressing}ReplyTo;");
    if (test.isStreaming()) {
        SecurityTestUtil.enableStreaming(port);
    }
    WSS4JStaxOutInterceptor staxOutInterceptor = null;
    WSS4JOutInterceptor outInterceptor = null;
    if (test.isStreaming()) {
        staxOutInterceptor = new WSS4JStaxOutInterceptor(outProps);
        bus.getOutInterceptors().add(staxOutInterceptor);
    } else {
        outInterceptor = new WSS4JOutInterceptor(outProps);
        bus.getOutInterceptors().add(outInterceptor);
    }
    assertEquals(50, port.doubleIt(25));
    ((java.io.Closeable) port).close();
    bus.shutdown(true);
}
Also used : WSS4JStaxOutInterceptor(org.apache.cxf.ws.security.wss4j.WSS4JStaxOutInterceptor) Bus(org.apache.cxf.Bus) HashMap(java.util.HashMap) QName(javax.xml.namespace.QName) Service(javax.xml.ws.Service) URL(java.net.URL) SpringBusFactory(org.apache.cxf.bus.spring.SpringBusFactory) DoubleItPortType(org.example.contract.doubleit.DoubleItPortType) WSS4JOutInterceptor(org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor)

Example 18 with WSS4JStaxOutInterceptor

use of org.apache.cxf.ws.security.wss4j.WSS4JStaxOutInterceptor in project cxf by apache.

the class CryptoCoverageCheckerTest method testSignedTimestampOnly.

@org.junit.Test
public void testSignedTimestampOnly() throws Exception {
    SpringBusFactory bf = new SpringBusFactory();
    URL busFile = CryptoCoverageCheckerTest.class.getResource("client.xml");
    Bus bus = bf.createBus(busFile.toString());
    BusFactory.setDefaultBus(bus);
    BusFactory.setThreadDefaultBus(bus);
    URL wsdl = CryptoCoverageCheckerTest.class.getResource("DoubleItCoverageChecker.wsdl");
    Service service = Service.create(wsdl, SERVICE_QNAME);
    QName portQName = new QName(NAMESPACE, "DoubleItBodyTimestampPort");
    DoubleItPortType port = service.getPort(portQName, DoubleItPortType.class);
    updateAddressPort(port, test.getPort());
    Map<String, Object> outProps = new HashMap<>();
    outProps.put("action", "Timestamp Signature");
    outProps.put("signaturePropFile", "alice.properties");
    outProps.put("user", "alice");
    outProps.put("passwordCallbackClass", "org.apache.cxf.systest.ws.common.KeystorePasswordCallback");
    outProps.put("signatureParts", "{}{http://docs.oasis-open.org/wss/2004/01/oasis-" + "200401-wss-wssecurity-utility-1.0.xsd}Timestamp;");
    if (test.isStreaming()) {
        SecurityTestUtil.enableStreaming(port);
    }
    if (test.isStreaming()) {
        WSS4JStaxOutInterceptor staxOutInterceptor = new WSS4JStaxOutInterceptor(outProps);
        bus.getOutInterceptors().add(staxOutInterceptor);
    } else {
        WSS4JOutInterceptor outInterceptor = new WSS4JOutInterceptor(outProps);
        bus.getOutInterceptors().add(outInterceptor);
    }
    try {
        port.doubleIt(25);
        fail("Failure expected on not signing the Timestamp");
    } catch (Exception ex) {
    // expected
    }
    ((java.io.Closeable) port).close();
    bus.shutdown(true);
}
Also used : WSS4JStaxOutInterceptor(org.apache.cxf.ws.security.wss4j.WSS4JStaxOutInterceptor) Bus(org.apache.cxf.Bus) HashMap(java.util.HashMap) QName(javax.xml.namespace.QName) Service(javax.xml.ws.Service) URL(java.net.URL) SpringBusFactory(org.apache.cxf.bus.spring.SpringBusFactory) DoubleItPortType(org.example.contract.doubleit.DoubleItPortType) WSS4JOutInterceptor(org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor)

Example 19 with WSS4JStaxOutInterceptor

use of org.apache.cxf.ws.security.wss4j.WSS4JStaxOutInterceptor in project cxf by apache.

the class CryptoCoverageCheckerTest method testNotEncryptedUsernameToken.

@org.junit.Test
public void testNotEncryptedUsernameToken() throws Exception {
    if (!unrestrictedPoliciesInstalled) {
        return;
    }
    SpringBusFactory bf = new SpringBusFactory();
    URL busFile = CryptoCoverageCheckerTest.class.getResource("client.xml");
    Bus bus = bf.createBus(busFile.toString());
    BusFactory.setDefaultBus(bus);
    BusFactory.setThreadDefaultBus(bus);
    URL wsdl = CryptoCoverageCheckerTest.class.getResource("DoubleItCoverageChecker.wsdl");
    Service service = Service.create(wsdl, SERVICE_QNAME);
    QName portQName = new QName(NAMESPACE, "DoubleItEncryptedUsernameTokenPort");
    DoubleItPortType port = service.getPort(portQName, DoubleItPortType.class);
    updateAddressPort(port, test.getPort());
    Map<String, Object> outProps = new HashMap<>();
    outProps.put("action", "UsernameToken Encrypt");
    outProps.put("encryptionPropFile", "bob.properties");
    outProps.put("user", "alice");
    outProps.put("encryptionUser", "bob");
    outProps.put("passwordCallbackClass", "org.apache.cxf.systest.ws.common.KeystorePasswordCallback");
    outProps.put("encryptionParts", "{}{http://schemas.xmlsoap.org/soap/envelope/}Body;");
    if (test.isStreaming()) {
        SecurityTestUtil.enableStreaming(port);
    }
    if (test.isStreaming()) {
        WSS4JStaxOutInterceptor staxOutInterceptor = new WSS4JStaxOutInterceptor(outProps);
        bus.getOutInterceptors().add(staxOutInterceptor);
    } else {
        WSS4JOutInterceptor outInterceptor = new WSS4JOutInterceptor(outProps);
        bus.getOutInterceptors().add(outInterceptor);
    }
    try {
        port.doubleIt(25);
        fail("Failure expected on not encrypting the UsernameToken");
    } catch (Exception ex) {
    // expected
    }
    ((java.io.Closeable) port).close();
    bus.shutdown(true);
}
Also used : WSS4JStaxOutInterceptor(org.apache.cxf.ws.security.wss4j.WSS4JStaxOutInterceptor) Bus(org.apache.cxf.Bus) HashMap(java.util.HashMap) QName(javax.xml.namespace.QName) Service(javax.xml.ws.Service) URL(java.net.URL) SpringBusFactory(org.apache.cxf.bus.spring.SpringBusFactory) DoubleItPortType(org.example.contract.doubleit.DoubleItPortType) WSS4JOutInterceptor(org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor)

Example 20 with WSS4JStaxOutInterceptor

use of org.apache.cxf.ws.security.wss4j.WSS4JStaxOutInterceptor in project cxf by apache.

the class CryptoCoverageCheckerTest method testSignedTimestampOnlySoap12.

@org.junit.Test
public void testSignedTimestampOnlySoap12() throws Exception {
    SpringBusFactory bf = new SpringBusFactory();
    URL busFile = CryptoCoverageCheckerTest.class.getResource("client.xml");
    Bus bus = bf.createBus(busFile.toString());
    BusFactory.setDefaultBus(bus);
    BusFactory.setThreadDefaultBus(bus);
    URL wsdl = CryptoCoverageCheckerTest.class.getResource("DoubleItCoverageChecker.wsdl");
    Service service = Service.create(wsdl, SERVICE_QNAME);
    QName portQName = new QName(NAMESPACE, "DoubleItBodyTimestampSoap12Port");
    DoubleItPortType port = service.getPort(portQName, DoubleItPortType.class);
    updateAddressPort(port, test.getPort());
    Map<String, Object> outProps = new HashMap<>();
    outProps.put("action", "Timestamp Signature");
    outProps.put("signaturePropFile", "alice.properties");
    outProps.put("user", "alice");
    outProps.put("passwordCallbackClass", "org.apache.cxf.systest.ws.common.KeystorePasswordCallback");
    outProps.put("signatureParts", "{}{http://docs.oasis-open.org/wss/2004/01/oasis-" + "200401-wss-wssecurity-utility-1.0.xsd}Timestamp;");
    if (test.isStreaming()) {
        SecurityTestUtil.enableStreaming(port);
    }
    if (test.isStreaming()) {
        WSS4JStaxOutInterceptor staxOutInterceptor = new WSS4JStaxOutInterceptor(outProps);
        bus.getOutInterceptors().add(staxOutInterceptor);
    } else {
        WSS4JOutInterceptor outInterceptor = new WSS4JOutInterceptor(outProps);
        bus.getOutInterceptors().add(outInterceptor);
    }
    try {
        port.doubleIt(25);
        fail("Failure expected on not signing the Timestamp");
    } catch (Exception ex) {
    // expected
    }
    ((java.io.Closeable) port).close();
    bus.shutdown(true);
}
Also used : WSS4JStaxOutInterceptor(org.apache.cxf.ws.security.wss4j.WSS4JStaxOutInterceptor) Bus(org.apache.cxf.Bus) HashMap(java.util.HashMap) QName(javax.xml.namespace.QName) Service(javax.xml.ws.Service) URL(java.net.URL) SpringBusFactory(org.apache.cxf.bus.spring.SpringBusFactory) DoubleItPortType(org.example.contract.doubleit.DoubleItPortType) WSS4JOutInterceptor(org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor)

Aggregations

WSS4JStaxOutInterceptor (org.apache.cxf.ws.security.wss4j.WSS4JStaxOutInterceptor)27 HashMap (java.util.HashMap)25 QName (javax.xml.namespace.QName)25 URL (java.net.URL)14 Service (javax.xml.ws.Service)14 Bus (org.apache.cxf.Bus)14 SpringBusFactory (org.apache.cxf.bus.spring.SpringBusFactory)14 Client (org.apache.cxf.endpoint.Client)14 DoubleItPortType (org.example.contract.doubleit.DoubleItPortType)13 Test (org.junit.Test)13 LoggingInInterceptor (org.apache.cxf.ext.logging.LoggingInInterceptor)12 LoggingOutInterceptor (org.apache.cxf.ext.logging.LoggingOutInterceptor)12 Service (org.apache.cxf.service.Service)12 AbstractSecurityTest (org.apache.cxf.ws.security.wss4j.AbstractSecurityTest)12 Echo (org.apache.cxf.ws.security.wss4j.Echo)12 WSS4JInInterceptor (org.apache.cxf.ws.security.wss4j.WSS4JInInterceptor)12 WSS4JOutInterceptor (org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor)12 WSSSecurityProperties (org.apache.wss4j.stax.ext.WSSSecurityProperties)8 ArrayList (java.util.ArrayList)6 WSSConstants (org.apache.wss4j.stax.ext.WSSConstants)6