use of org.apache.cxf.ws.security.wss4j.WSS4JStaxOutInterceptor in project cxf by apache.
the class StaxToDOMSamlTest method testSaml1TokenHOK.
@Test
public void testSaml1TokenHOK() throws Exception {
// Create + configure service
Service service = createService();
Map<String, Object> inProperties = new HashMap<>();
inProperties.put(ConfigurationConstants.ACTION, ConfigurationConstants.SAML_TOKEN_SIGNED + " " + ConfigurationConstants.SIGNATURE);
inProperties.put(ConfigurationConstants.SIG_VER_PROP_FILE, "insecurity.properties");
final Map<QName, Object> customMap = new HashMap<>();
CustomSamlValidator validator = new CustomSamlValidator();
customMap.put(WSConstants.SAML_TOKEN, validator);
customMap.put(WSConstants.SAML2_TOKEN, validator);
inProperties.put(WSS4JInInterceptor.VALIDATOR_MAP, customMap);
WSS4JInInterceptor inInterceptor = new WSS4JInInterceptor(inProperties);
service.getInInterceptors().add(inInterceptor);
// Create + configure client
Echo echo = createClientProxy();
Client client = ClientProxy.getClient(echo);
client.getInInterceptors().add(new LoggingInInterceptor());
client.getOutInterceptors().add(new LoggingOutInterceptor());
WSSSecurityProperties properties = new WSSSecurityProperties();
List<WSSConstants.Action> actions = new ArrayList<WSSConstants.Action>();
actions.add(WSSConstants.SAML_TOKEN_SIGNED);
properties.setActions(actions);
SAML1CallbackHandler callbackHandler = new SAML1CallbackHandler();
callbackHandler.setSignAssertion(true);
callbackHandler.setConfirmationMethod(SAML1Constants.CONF_HOLDER_KEY);
properties.setSamlCallbackHandler(callbackHandler);
properties.setSignatureUser("alice");
Properties cryptoProperties = CryptoFactory.getProperties("alice.properties", this.getClass().getClassLoader());
properties.setSignatureCryptoProperties(cryptoProperties);
properties.setSignatureKeyIdentifier(WSSecurityTokenConstants.KEYIDENTIFIER_SECURITY_TOKEN_DIRECT_REFERENCE);
properties.setCallbackHandler(new PasswordCallbackHandler());
WSS4JStaxOutInterceptor ohandler = new WSS4JStaxOutInterceptor(properties);
client.getOutInterceptors().add(ohandler);
try {
echo.echo("test");
fail("Failure expected on receiving sender vouches instead of HOK");
} catch (javax.xml.ws.soap.SOAPFaultException ex) {
// expected
}
validator.setRequireSenderVouches(false);
assertEquals("test", echo.echo("test"));
}
use of org.apache.cxf.ws.security.wss4j.WSS4JStaxOutInterceptor in project cxf by apache.
the class StaxToDOMSamlTest method testSaml2SignedSenderVouches.
@Test
public void testSaml2SignedSenderVouches() throws Exception {
// Create + configure service
Service service = createService();
Map<String, Object> inProperties = new HashMap<>();
inProperties.put(ConfigurationConstants.ACTION, ConfigurationConstants.SAML_TOKEN_UNSIGNED + " " + ConfigurationConstants.SIGNATURE);
inProperties.put(ConfigurationConstants.SIG_VER_PROP_FILE, "insecurity.properties");
final Map<QName, Object> customMap = new HashMap<>();
CustomSamlValidator validator = new CustomSamlValidator();
validator.setRequireSAML1Assertion(false);
customMap.put(WSConstants.SAML_TOKEN, validator);
customMap.put(WSConstants.SAML2_TOKEN, validator);
inProperties.put(WSS4JInInterceptor.VALIDATOR_MAP, customMap);
WSS4JInInterceptor inInterceptor = new WSS4JInInterceptor(inProperties);
service.getInInterceptors().add(inInterceptor);
// Create + configure client
Echo echo = createClientProxy();
Client client = ClientProxy.getClient(echo);
client.getInInterceptors().add(new LoggingInInterceptor());
client.getOutInterceptors().add(new LoggingOutInterceptor());
WSSSecurityProperties properties = new WSSSecurityProperties();
List<WSSConstants.Action> actions = new ArrayList<WSSConstants.Action>();
actions.add(WSSConstants.SAML_TOKEN_SIGNED);
properties.setActions(actions);
properties.setSamlCallbackHandler(new SAML2CallbackHandler());
properties.setCallbackHandler(new PasswordCallbackHandler());
properties.setSignatureKeyIdentifier(WSSecurityTokenConstants.KEYIDENTIFIER_SECURITY_TOKEN_DIRECT_REFERENCE);
WSS4JStaxOutInterceptor ohandler = new WSS4JStaxOutInterceptor(properties);
client.getOutInterceptors().add(ohandler);
assertEquals("test", echo.echo("test"));
}
use of org.apache.cxf.ws.security.wss4j.WSS4JStaxOutInterceptor 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.apache.cxf.ws.security.wss4j.WSS4JStaxOutInterceptor 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.apache.cxf.ws.security.wss4j.WSS4JStaxOutInterceptor 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);
}
Aggregations