Search in sources :

Example 76 with RouteBuilder

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);
}
Also used : RouteBuilder(org.apache.camel.builder.RouteBuilder) NodeList(org.w3c.dom.NodeList) KeyStoreParameters(org.apache.camel.util.jsse.KeyStoreParameters) Document(org.w3c.dom.Document) Test(org.junit.Test)

Example 77 with RouteBuilder

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);
}
Also used : RouteBuilder(org.apache.camel.builder.RouteBuilder) Test(org.junit.Test)

Example 78 with RouteBuilder

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);
}
Also used : RouteBuilder(org.apache.camel.builder.RouteBuilder) KeyStoreParameters(org.apache.camel.util.jsse.KeyStoreParameters) Test(org.junit.Test)

Example 79 with RouteBuilder

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);
}
Also used : RouteBuilder(org.apache.camel.builder.RouteBuilder) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) KeyStoreParameters(org.apache.camel.util.jsse.KeyStoreParameters) Test(org.junit.Test)

Example 80 with RouteBuilder

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);
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) RouteBuilder(org.apache.camel.builder.RouteBuilder) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) KeyStoreParameters(org.apache.camel.util.jsse.KeyStoreParameters) Test(org.junit.Test)

Aggregations

RouteBuilder (org.apache.camel.builder.RouteBuilder)1759 Exchange (org.apache.camel.Exchange)628 Processor (org.apache.camel.Processor)545 Test (org.junit.Test)476 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)341 CamelExecutionException (org.apache.camel.CamelExecutionException)135 FailedToCreateRouteException (org.apache.camel.FailedToCreateRouteException)119 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)104 File (java.io.File)68 CamelContext (org.apache.camel.CamelContext)64 IOException (java.io.IOException)61 ResolveEndpointFailedException (org.apache.camel.ResolveEndpointFailedException)42 HashMap (java.util.HashMap)35 Path (org.apache.hadoop.fs.Path)34 CountDownLatch (java.util.concurrent.CountDownLatch)32 Configuration (org.apache.hadoop.conf.Configuration)32 Endpoint (org.apache.camel.Endpoint)30 ArrayFile (org.apache.hadoop.io.ArrayFile)30 SequenceFile (org.apache.hadoop.io.SequenceFile)30 RuntimeCamelException (org.apache.camel.RuntimeCamelException)26