use of org.apache.camel.builder.RouteBuilder in project camel by apache.
the class XMLSecurityDataFormatTest method testAsymmetricEncryptionAddKeyValue.
@Test
public void testAsymmetricEncryptionAddKeyValue() throws Exception {
KeyStoreParameters tsParameters = new KeyStoreParameters();
tsParameters.setPassword("password");
tsParameters.setResource("sender.ts");
final XMLSecurityDataFormat xmlEncDataFormat = new XMLSecurityDataFormat();
xmlEncDataFormat.setKeyOrTrustStoreParameters(tsParameters);
xmlEncDataFormat.setXmlCipherAlgorithm(testCypherAlgorithm);
xmlEncDataFormat.setRecipientKeyAlias("recipient");
xmlEncDataFormat.setAddKeyValueForEncryptedKey(true);
context.addRoutes(new RouteBuilder() {
public void configure() {
from("direct:start").marshal(xmlEncDataFormat).to("mock:encrypted");
}
});
Document doc = xmlsecTestHelper.testEncryption(TestHelper.XML_FRAGMENT, context);
NodeList nodeList = doc.getElementsByTagNameNS("http://www.w3.org/2000/09/xmldsig#", "RSAKeyValue");
Assert.assertTrue(nodeList.getLength() > 0);
}
use of org.apache.camel.builder.RouteBuilder in project camel by apache.
the class XMLSecurityDataFormatTest method testPartialPayloadMultiNodeXMLContentDecryption.
@Test
public void testPartialPayloadMultiNodeXMLContentDecryption() throws Exception {
if (!TestHelper.HAS_3DES) {
return;
}
context.addRoutes(new RouteBuilder() {
public void configure() {
from("direct:start").marshal().secureXML("//cheesesites/*/cheese", true).to("mock:encrypted").unmarshal().secureXML("//cheesesites/*/cheese", true).to("mock:decrypted");
}
});
xmlsecTestHelper.testDecryption(context);
}
use of org.apache.camel.builder.RouteBuilder in project camel by apache.
the class XMLSecurityDataFormatTest method testFullPayloadAsymmetricKeyDecryption.
@Test
public void testFullPayloadAsymmetricKeyDecryption() throws Exception {
final KeyStoreParameters tsParameters = new KeyStoreParameters();
tsParameters.setPassword("password");
tsParameters.setResource("sender.ts");
final KeyStoreParameters ksParameters = new KeyStoreParameters();
ksParameters.setPassword("password");
ksParameters.setResource("recipient.ks");
context.addRoutes(new RouteBuilder() {
public void configure() {
from("direct:start").marshal().secureXML("", true, "recipient", testCypherAlgorithm, XMLCipher.RSA_v1dot5, tsParameters).to("mock:encrypted").unmarshal().secureXML("", true, "recipient", testCypherAlgorithm, XMLCipher.RSA_v1dot5, ksParameters).to("mock:decrypted");
}
});
xmlsecTestHelper.testDecryption(context);
}
use of org.apache.camel.builder.RouteBuilder in project camel by apache.
the class XMLSecurityDataFormatTest method testAsymmetricEncryptionAlgorithmFullPayload.
@Test
public void testAsymmetricEncryptionAlgorithmFullPayload() throws Exception {
final KeyStoreParameters tsParameters = new KeyStoreParameters();
tsParameters.setPassword("password");
tsParameters.setResource("sender.ts");
final KeyStoreParameters ksParameters = new KeyStoreParameters();
ksParameters.setPassword("password");
ksParameters.setResource("recipient.ks");
// RSA v1.5 is not allowed unless explicitly configured
context.addRoutes(new RouteBuilder() {
public void configure() {
from("direct:start").marshal().secureXML("", true, "recipient", testCypherAlgorithm, XMLCipher.RSA_v1dot5, tsParameters).to("mock:encrypted").unmarshal().secureXML("", true, "recipient", testCypherAlgorithm, XMLCipher.RSA_OAEP, ksParameters).to("mock:decrypted");
}
});
MockEndpoint resultEndpoint = context.getEndpoint("mock:decrypted", MockEndpoint.class);
resultEndpoint.setExpectedMessageCount(0);
// verify that the message was encrypted before checking that it is decrypted
xmlsecTestHelper.testEncryption(TestHelper.XML_FRAGMENT, context);
resultEndpoint.assertIsSatisfied(100);
}
use of org.apache.camel.builder.RouteBuilder in project camel by apache.
the class XMLSecurityDataFormatTest method testPartialPayloadAsymmetricKeyEncryptionWithExchangeRecipientAlias.
@Test
@SuppressWarnings("deprecation")
public void testPartialPayloadAsymmetricKeyEncryptionWithExchangeRecipientAlias() throws Exception {
MockEndpoint resultEndpoint = context.getEndpoint("mock:foo", MockEndpoint.class);
resultEndpoint.setExpectedMessageCount(1);
final KeyStoreParameters tsParameters = new KeyStoreParameters();
tsParameters.setPassword("password");
tsParameters.setResource("sender.ts");
context.addRoutes(new RouteBuilder() {
public void configure() {
from("direct:start").process(new Processor() {
public void process(Exchange exchange) throws Exception {
exchange.getIn().setHeader(XMLSecurityDataFormat.XML_ENC_RECIPIENT_ALIAS, "recipient");
}
}).marshal().secureXML("//cheesesites/italy/cheese", true, null, testCypherAlgorithm, XMLCipher.RSA_v1dot5, tsParameters).to("mock:encrypted");
}
});
xmlsecTestHelper.testEncryption(context);
}
Aggregations