Search in sources :

Example 16 with RouteBuilder

use of org.apache.camel.builder.RouteBuilder in project camel by apache.

the class CometdProducerConsumerInteractiveAuthenticatedMain method createRouteBuilder.

private RouteBuilder createRouteBuilder() {
    return new RouteBuilder() {

        public void configure() {
            CometdComponent component = (CometdComponent) context.getComponent("cometds");
            component.setSslPassword(pwd);
            component.setSslKeyPassword(pwd);
            CometdComponent component2 = (CometdComponent) context.getComponent("cometd");
            BayeuxAuthenticator bayeuxAuthenticator = new BayeuxAuthenticator();
            component2.setSecurityPolicy(bayeuxAuthenticator);
            component2.addExtension(bayeuxAuthenticator);
            File file = new File("./src/test/resources/jsse/localhost.ks");
            URI keyStoreUrl = file.toURI();
            component.setSslKeystore(keyStoreUrl.getPath());
            from("stream:in").to(URI).to(URIS);
        }
    };
}
Also used : RouteBuilder(org.apache.camel.builder.RouteBuilder) File(java.io.File) URI(java.net.URI)

Example 17 with RouteBuilder

use of org.apache.camel.builder.RouteBuilder in project camel by apache.

the class CometdProducerConsumerInteractiveExtensionMain method createRouteBuilder.

private RouteBuilder createRouteBuilder() {
    return new RouteBuilder() {

        public void configure() {
            CometdComponent component = (CometdComponent) context.getComponent("cometds");
            component.setSslPassword(pwd);
            component.setSslKeyPassword(pwd);
            CometdComponent component2 = (CometdComponent) context.getComponent("cometd");
            Censor bayeuxAuthenticator = new Censor();
            component2.addExtension(bayeuxAuthenticator);
            File file = new File("./src/test/resources/jsse/localhost.ks");
            URI keyStoreUrl = file.toURI();
            component.setSslKeystore(keyStoreUrl.getPath());
            from("stream:in").to(URI).to(URIS);
        }
    };
}
Also used : RouteBuilder(org.apache.camel.builder.RouteBuilder) File(java.io.File) URI(java.net.URI)

Example 18 with RouteBuilder

use of org.apache.camel.builder.RouteBuilder in project camel by apache.

the class CometdProducerConsumerInteractiveMain method createRouteBuilder.

private RouteBuilder createRouteBuilder() {
    return new RouteBuilder() {

        public void configure() {
            CometdComponent component = (CometdComponent) context.getComponent("cometds");
            component.setSslPassword(pwd);
            component.setSslKeyPassword(pwd);
            File file = new File("./src/test/resources/jsse/localhost.ks");
            URI keyStoreUrl = file.toURI();
            component.setSslKeystore(keyStoreUrl.getPath());
            from("stream:in").to(URI).to(URIS);
        }
    };
}
Also used : RouteBuilder(org.apache.camel.builder.RouteBuilder) File(java.io.File) URI(java.net.URI)

Example 19 with RouteBuilder

use of org.apache.camel.builder.RouteBuilder in project camel by apache.

the class SignatureTests method createRouteBuilders.

@Override
protected RouteBuilder[] createRouteBuilders() throws Exception {
    return new RouteBuilder[] { new RouteBuilder() {

        public void configure() throws Exception {
            // START SNIPPET: basic
            from("direct:keypair").to("crypto:sign:basic?privateKey=#myPrivateKey", "crypto:verify:basic?publicKey=#myPublicKey", "mock:result");
        // END SNIPPET: basic
        }
    }, new RouteBuilder() {

        public void configure() throws Exception {
            // START SNIPPET: algorithm
            keyPair = getKeyPair("RSA");
            PrivateKey privateKey = keyPair.getPrivate();
            PublicKey publicKey = keyPair.getPublic();
            // we can set the keys explicitly on the endpoint instances.
            context.getEndpoint("crypto:sign:rsa?algorithm=MD5withRSA", DigitalSignatureEndpoint.class).setPrivateKey(privateKey);
            context.getEndpoint("crypto:verify:rsa?algorithm=MD5withRSA", DigitalSignatureEndpoint.class).setPublicKey(publicKey);
            from("direct:algorithm").to("crypto:sign:rsa?algorithm=MD5withRSA", "crypto:verify:rsa?algorithm=MD5withRSA", "mock:result");
        // END SNIPPET: algorithm
        }
    }, new RouteBuilder() {

        public void configure() throws Exception {
            // START SNIPPET: rsa-sha1
            keyPair = getKeyPair("RSA");
            PrivateKey privateKey = keyPair.getPrivate();
            PublicKey publicKey = keyPair.getPublic();
            // we can set the keys explicitly on the endpoint instances.
            context.getEndpoint("crypto:sign:rsa?algorithm=SHA1withRSA", DigitalSignatureEndpoint.class).setPrivateKey(privateKey);
            context.getEndpoint("crypto:verify:rsa?algorithm=SHA1withRSA", DigitalSignatureEndpoint.class).setPublicKey(publicKey);
            from("direct:rsa-sha1").to("crypto:sign:rsa?algorithm=SHA1withRSA", "crypto:verify:rsa?algorithm=SHA1withRSA", "mock:result");
        // END SNIPPET: rsa-sha1
        }
    }, new RouteBuilder() {

        public void configure() throws Exception {
            // START SNIPPET: rsa-sha256
            keyPair = getKeyPair("RSA");
            PrivateKey privateKey = keyPair.getPrivate();
            PublicKey publicKey = keyPair.getPublic();
            // we can set the keys explicitly on the endpoint instances.
            context.getEndpoint("crypto:sign:rsa?algorithm=SHA256withRSA", DigitalSignatureEndpoint.class).setPrivateKey(privateKey);
            context.getEndpoint("crypto:verify:rsa?algorithm=SHA256withRSA", DigitalSignatureEndpoint.class).setPublicKey(publicKey);
            from("direct:rsa-sha256").to("crypto:sign:rsa?algorithm=SHA256withRSA", "crypto:verify:rsa?algorithm=SHA256withRSA", "mock:result");
        // END SNIPPET: rsa-sha256
        }
    }, new RouteBuilder() {

        public void configure() throws Exception {
            // START SNIPPET: buffersize
            from("direct:buffersize").to("crypto:sign:buffer?privateKey=#myPrivateKey&buffersize=1024", "crypto:verify:buffer?publicKey=#myPublicKey&buffersize=1024", "mock:result");
        // END SNIPPET: buffersize
        }
    }, new RouteBuilder() {

        public void configure() throws Exception {
            // START SNIPPET: provider
            from("direct:provider").to("crypto:sign:provider?privateKey=#myPrivateKey&provider=SUN", "crypto:verify:provider?publicKey=#myPublicKey&provider=SUN", "mock:result");
        // END SNIPPET: provider
        }
    }, new RouteBuilder() {

        public void configure() throws Exception {
            // START SNIPPET: certificate
            from("direct:certificate").to("crypto:sign:withcert?privateKey=#myPrivateKey", "crypto:verify:withcert?certificate=#myCert", "mock:result");
        // END SNIPPET: certificate
        }
    }, new RouteBuilder() {

        public void configure() throws Exception {
            // START SNIPPET: keystore
            from("direct:keystore").to("crypto:sign:keystore?keystore=#keystore&alias=bob&password=letmein", "crypto:verify:keystore?keystore=#keystore&alias=bob", "mock:result");
        // END SNIPPET: keystore
        }
    }, new RouteBuilder() {

        public void configure() throws Exception {
            // START SNIPPET: keystore
            from("direct:keystoreParameters").to("crypto:sign:keyStoreParameters?keyStoreParameters=#signatureParams&alias=bob&password=letmein", "crypto:verify:keyStoreParameters?keyStoreParameters=#signatureParams&alias=bob", "mock:result");
        // END SNIPPET: keystore
        }
    }, new RouteBuilder() {

        public void configure() throws Exception {
            // START SNIPPET: signature-header
            from("direct:signature-header").to("crypto:sign:another?privateKey=#myPrivateKey&signatureHeader=AnotherDigitalSignature", "crypto:verify:another?publicKey=#myPublicKey&signatureHeader=AnotherDigitalSignature", "mock:result");
        // END SNIPPET: signature-header
        }
    }, new RouteBuilder() {

        public void configure() throws Exception {
            // START SNIPPET: random
            from("direct:random").to("crypto:sign:another?privateKey=#myPrivateKey&secureRandom=#someRandom", "crypto:verify:another?publicKey=#myPublicKey&secureRandom=#someRandom", "mock:result");
        // END SNIPPET: random
        }
    }, new RouteBuilder() {

        public void configure() throws Exception {
            // START SNIPPET: alias
            from("direct:alias-sign").to("crypto:sign:alias?keystore=#keystore");
            from("direct:alias-verify").to("crypto:verify:alias?keystore=#keystore", "mock:result");
        // END SNIPPET: alias
        }
    }, new RouteBuilder() {

        public void configure() throws Exception {
            // START SNIPPET: headerkey
            from("direct:headerkey-sign").to("crypto:sign:alias");
            from("direct:headerkey-verify").to("crypto:verify:alias", "mock:result");
        // END SNIPPET: headerkey
        }
    }, new RouteBuilder() {

        public void configure() throws Exception {
            // START SNIPPET: clearheaders
            from("direct:headers").to("crypto:sign:headers?privateKey=#myPrivateKey", "crypto:verify:headers?publicKey=#myPublicKey&clearHeaders=false", "mock:result");
        // END SNIPPET: clearheaders
        }
    } };
}
Also used : PrivateKey(java.security.PrivateKey) RouteBuilder(org.apache.camel.builder.RouteBuilder) PublicKey(java.security.PublicKey)

Example 20 with RouteBuilder

use of org.apache.camel.builder.RouteBuilder in project camel by apache.

the class CryptoDataFormatTest method createRouteBuilders.

protected RouteBuilder[] createRouteBuilders() throws Exception {
    return new RouteBuilder[] { new RouteBuilder() {

        public void configure() throws Exception {
            // START SNIPPET: basic
            KeyGenerator generator = KeyGenerator.getInstance("DES");
            CryptoDataFormat cryptoFormat = new CryptoDataFormat("DES", generator.generateKey());
            from("direct:basic-encryption").marshal(cryptoFormat).to("mock:encrypted").unmarshal(cryptoFormat).to("mock:unencrypted");
        // END SNIPPET: basic
        }
    }, new RouteBuilder() {

        public void configure() throws Exception {
            // START SNIPPET: init-vector
            KeyGenerator generator = KeyGenerator.getInstance("DES");
            byte[] initializationVector = new byte[] { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 };
            CryptoDataFormat cryptoFormat = new CryptoDataFormat("DES/CBC/PKCS5Padding", generator.generateKey());
            cryptoFormat.setInitializationVector(initializationVector);
            from("direct:init-vector").marshal(cryptoFormat).to("mock:encrypted").unmarshal(cryptoFormat).to("mock:unencrypted");
        // END SNIPPET: init-vector
        }
    }, new RouteBuilder() {

        public void configure() throws Exception {
            // START SNIPPET: inline-init-vector
            KeyGenerator generator = KeyGenerator.getInstance("DES");
            byte[] initializationVector = new byte[] { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 };
            SecretKey key = generator.generateKey();
            CryptoDataFormat cryptoFormat = new CryptoDataFormat("DES/CBC/PKCS5Padding", key);
            cryptoFormat.setInitializationVector(initializationVector);
            cryptoFormat.setShouldInlineInitializationVector(true);
            CryptoDataFormat decryptFormat = new CryptoDataFormat("DES/CBC/PKCS5Padding", key);
            decryptFormat.setShouldInlineInitializationVector(true);
            from("direct:inline").marshal(cryptoFormat).to("mock:encrypted").unmarshal(decryptFormat).to("mock:unencrypted");
        // END SNIPPET: inline-init-vector
        }
    }, new RouteBuilder() {

        public void configure() throws Exception {
            // START SNIPPET: hmac
            KeyGenerator generator = KeyGenerator.getInstance("DES");
            CryptoDataFormat cryptoFormat = new CryptoDataFormat("DES", generator.generateKey());
            cryptoFormat.setShouldAppendHMAC(true);
            from("direct:hmac").marshal(cryptoFormat).to("mock:encrypted").unmarshal(cryptoFormat).to("mock:unencrypted");
        // END SNIPPET: hmac
        }
    }, new RouteBuilder() {

        public void configure() throws Exception {
            // START SNIPPET: hmac-algorithm
            KeyGenerator generator = KeyGenerator.getInstance("DES");
            CryptoDataFormat cryptoFormat = new CryptoDataFormat("DES", generator.generateKey());
            cryptoFormat.setShouldAppendHMAC(true);
            cryptoFormat.setMacAlgorithm("HmacMD5");
            from("direct:hmac-algorithm").marshal(cryptoFormat).to("mock:encrypted").unmarshal(cryptoFormat).to("mock:unencrypted");
        // END SNIPPET: hmac-algorithm
        }
    }, new RouteBuilder() {

        public void configure() throws Exception {
            // START SNIPPET: hmac-sha256-algorithm
            KeyGenerator generator = KeyGenerator.getInstance("DES");
            CryptoDataFormat cryptoFormat = new CryptoDataFormat("DES", generator.generateKey());
            cryptoFormat.setShouldAppendHMAC(true);
            cryptoFormat.setMacAlgorithm("HmacSHA256");
            from("direct:hmac-sha-256-algorithm").marshal(cryptoFormat).to("mock:encrypted").unmarshal(cryptoFormat).to("mock:unencrypted");
        // END SNIPPET: hmac-sha256-algorithm
        }
    }, new RouteBuilder() {

        public void configure() throws Exception {
            // START SNIPPET: key-in-header
            CryptoDataFormat cryptoFormat = new CryptoDataFormat("DES", null);
            /**
                 * Note: the header containing the key should be cleared after
                 * marshalling to stop it from leaking by accident and
                 * potentially being compromised. The processor version below is
                 * arguably better as the key is left in the header when you use
                 * the DSL leaks the fact that camel encryption was used.
                 */
            from("direct:key-in-header-encrypt").marshal(cryptoFormat).removeHeader(CryptoDataFormat.KEY).to("mock:encrypted");
            from("direct:key-in-header-decrypt").unmarshal(cryptoFormat).process(new Processor() {

                public void process(Exchange exchange) throws Exception {
                    exchange.getIn().getHeaders().remove(CryptoDataFormat.KEY);
                    exchange.getOut().copyFrom(exchange.getIn());
                }
            }).to("mock:unencrypted");
        // END SNIPPET: key-in-header
        }
    }, new RouteBuilder() {

        public void configure() throws Exception {
            // START SNIPPET: 3DES-ECB
            KeyGenerator generator = KeyGenerator.getInstance("DESede");
            CryptoDataFormat cryptoFormat = new CryptoDataFormat("DESede/ECB/PKCS5Padding", generator.generateKey());
            from("direct:3des-ecb-encryption").marshal(cryptoFormat).to("mock:encrypted").unmarshal(cryptoFormat).to("mock:unencrypted");
        // END SNIPPET: 3DES-ECB
        }
    }, new RouteBuilder() {

        public void configure() throws Exception {
            // START SNIPPET: 3DES-CBC
            KeyGenerator generator = KeyGenerator.getInstance("DES");
            byte[] iv = new byte[8];
            SecureRandom random = new SecureRandom();
            random.nextBytes(iv);
            Key key = generator.generateKey();
            CryptoDataFormat encCryptoFormat = new CryptoDataFormat("DES/CBC/PKCS5Padding", key);
            encCryptoFormat.setInitializationVector(iv);
            encCryptoFormat.setShouldInlineInitializationVector(true);
            CryptoDataFormat decCryptoFormat = new CryptoDataFormat("DES/CBC/PKCS5Padding", key);
            decCryptoFormat.setShouldInlineInitializationVector(true);
            from("direct:3des-cbc-encryption").marshal(encCryptoFormat).to("mock:encrypted").unmarshal(decCryptoFormat).to("mock:unencrypted");
        // END SNIPPET: 3DES-CBC
        }
    }, new RouteBuilder() {

        public void configure() throws Exception {
            // START SNIPPET: AES-128-ECB
            KeyGenerator generator = KeyGenerator.getInstance("AES");
            CryptoDataFormat cryptoFormat = new CryptoDataFormat("AES/ECB/PKCS5Padding", generator.generateKey());
            from("direct:aes-128-ecb-encryption").marshal(cryptoFormat).to("mock:encrypted").unmarshal(cryptoFormat).to("mock:unencrypted");
        // END SNIPPET: AES-128-ECB
        }
    } };
}
Also used : Exchange(org.apache.camel.Exchange) SecretKey(javax.crypto.SecretKey) Processor(org.apache.camel.Processor) RouteBuilder(org.apache.camel.builder.RouteBuilder) SecureRandom(java.security.SecureRandom) KeyGenerator(javax.crypto.KeyGenerator) Key(java.security.Key) SecretKey(javax.crypto.SecretKey)

Aggregations

RouteBuilder (org.apache.camel.builder.RouteBuilder)1744 Exchange (org.apache.camel.Exchange)624 Processor (org.apache.camel.Processor)542 Test (org.junit.Test)470 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)338 CamelExecutionException (org.apache.camel.CamelExecutionException)135 FailedToCreateRouteException (org.apache.camel.FailedToCreateRouteException)119 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)100 File (java.io.File)65 IOException (java.io.IOException)61 CamelContext (org.apache.camel.CamelContext)61 ResolveEndpointFailedException (org.apache.camel.ResolveEndpointFailedException)42 HashMap (java.util.HashMap)34 Path (org.apache.hadoop.fs.Path)34 CountDownLatch (java.util.concurrent.CountDownLatch)32 Configuration (org.apache.hadoop.conf.Configuration)32 ArrayFile (org.apache.hadoop.io.ArrayFile)30 SequenceFile (org.apache.hadoop.io.SequenceFile)30 Endpoint (org.apache.camel.Endpoint)27 RuntimeCamelException (org.apache.camel.RuntimeCamelException)26