use of org.example.contract.doubleit.DoubleItPortType in project cxf by apache.
the class CryptoCoverageCheckerTest method testWSAddressing.
@org.junit.Test
public void testWSAddressing() 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("signatureParts", "{}{http://schemas.xmlsoap.org/soap/envelope/}Body;" + "{}{http://docs.oasis-open.org/wss/2004/01/oasis-" + "200401-wss-wssecurity-utility-1.0.xsd}Timestamp;");
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);
}
try {
port.doubleIt(25);
fail("Failure expected on not signing the WS-Addressing headers");
} catch (Exception ex) {
// expected
}
// Now sign the WS-Addressing headers
outProps.put("signatureParts", "{}{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()) {
bus.getOutInterceptors().remove(staxOutInterceptor);
SecurityTestUtil.enableStreaming(port);
} else {
bus.getOutInterceptors().remove(outInterceptor);
}
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);
}
use of org.example.contract.doubleit.DoubleItPortType in project cxf by apache.
the class CryptoCoverageCheckerTest method testSignedEncryptedBody.
@org.junit.Test
public void testSignedEncryptedBody() 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, "DoubleItSignedEncryptedBodyPort");
DoubleItPortType port = service.getPort(portQName, DoubleItPortType.class);
updateAddressPort(port, test.getPort());
Map<String, Object> outProps = new HashMap<>();
outProps.put("action", "Timestamp Signature Encrypt");
outProps.put("signaturePropFile", "alice.properties");
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("signatureParts", "{}{http://schemas.xmlsoap.org/soap/envelope/}Body;");
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);
}
assertEquals(50, port.doubleIt(25));
((java.io.Closeable) port).close();
bus.shutdown(true);
}
use of org.example.contract.doubleit.DoubleItPortType in project cxf by apache.
the class CryptoCoverageCheckerTest method testSignedNotEncryptedBody.
@org.junit.Test
public void testSignedNotEncryptedBody() 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, "DoubleItSignedEncryptedBodyPort");
DoubleItPortType port = service.getPort(portQName, DoubleItPortType.class);
updateAddressPort(port, test.getPort());
Map<String, Object> outProps = new HashMap<>();
outProps.put("action", "Timestamp Signature Encrypt");
outProps.put("signaturePropFile", "alice.properties");
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("signatureParts", "{}{http://schemas.xmlsoap.org/soap/envelope/}Body;");
outProps.put("encryptionParts", "{}{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 encrypting the SOAP Body");
} catch (Exception ex) {
// expected
}
((java.io.Closeable) port).close();
bus.shutdown(true);
}
use of org.example.contract.doubleit.DoubleItPortType in project cxf by apache.
the class CryptoCoverageCheckerTest method testEncryptedUsernameToken.
@org.junit.Test
public void testEncryptedUsernameToken() 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;" + "{Element}{" + WSS4JConstants.WSSE_NS + "}UsernameToken;");
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);
}
assertEquals(50, port.doubleIt(25));
((java.io.Closeable) port).close();
bus.shutdown(true);
}
use of org.example.contract.doubleit.DoubleItPortType in project cxf by apache.
the class FaultTest method testSoap11PolicyWithParts.
@org.junit.Test
public void testSoap11PolicyWithParts() throws Exception {
SpringBusFactory bf = new SpringBusFactory();
URL busFile = FaultTest.class.getResource("client.xml");
Bus bus = bf.createBus(busFile.toString());
BusFactory.setDefaultBus(bus);
BusFactory.setThreadDefaultBus(bus);
URL wsdl = FaultTest.class.getResource("DoubleItFault.wsdl");
Service service = Service.create(wsdl, SERVICE_QNAME);
QName portQName = new QName(NAMESPACE, "DoubleItSoap11PolicyWithPartsPort");
DoubleItPortType utPort = service.getPort(portQName, DoubleItPortType.class);
updateAddressPort(utPort, PORT);
// Make a successful invocation
((BindingProvider) utPort).getRequestContext().put(SecurityConstants.USERNAME, "alice");
assertEquals(50, utPort.doubleIt(25));
// Now make an invocation using another username
((BindingProvider) utPort).getRequestContext().put(SecurityConstants.USERNAME, "bob");
((BindingProvider) utPort).getRequestContext().put("security.password", "password");
try {
utPort.doubleIt(25);
fail("Expected failure on bob");
} catch (Exception ex) {
assertTrue(ex.getMessage().contains("This is a fault"));
}
((java.io.Closeable) utPort).close();
bus.shutdown(true);
}
Aggregations