camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r927285 - in /camel/trunk/components/camel-crypto: ./ src/main/java/org/apache/camel/component/crypto/ src/main/resources/META-INF/services/org/apache/camel/component/ src/test/java/org/apache/camel/component/crypto/ src/test/resources/org/...
Date Thu, 25 Mar 2010 06:12:38 GMT
Author: davsclaus
Date: Thu Mar 25 06:12:37 2010
New Revision: 927285

URL: http://svn.apache.org/viewvc?rev=927285&view=rev
Log:
CAMEL-2482: Applied patch with thanks to Stephen Gargan.

Added:
    camel/trunk/components/camel-crypto/src/main/resources/META-INF/services/org/apache/camel/component/crypto
Removed:
    camel/trunk/components/camel-crypto/src/main/resources/META-INF/services/org/apache/camel/component/verify
Modified:
    camel/trunk/components/camel-crypto/pom.xml
    camel/trunk/components/camel-crypto/src/main/java/org/apache/camel/component/crypto/DigitalSignatureComponent.java
    camel/trunk/components/camel-crypto/src/main/java/org/apache/camel/component/crypto/DigitalSignatureConfiguration.java
    camel/trunk/components/camel-crypto/src/main/java/org/apache/camel/component/crypto/DigitalSignatureEndpoint.java
    camel/trunk/components/camel-crypto/src/test/java/org/apache/camel/component/crypto/SignatureTests.java
    camel/trunk/components/camel-crypto/src/test/resources/org/apache/camel/component/crypto/SpringSignatureTests.xml

Modified: camel/trunk/components/camel-crypto/pom.xml
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-crypto/pom.xml?rev=927285&r1=927284&r2=927285&view=diff
==============================================================================
--- camel/trunk/components/camel-crypto/pom.xml (original)
+++ camel/trunk/components/camel-crypto/pom.xml Thu Mar 25 06:12:37 2010
@@ -46,13 +46,13 @@
             <groupId>commons-codec</groupId>
             <artifactId>commons-codec</artifactId>
         </dependency>
+
+        <!-- for testing -->
         <dependency>
             <groupId>bouncycastle</groupId>
             <artifactId>bcprov-jdk15</artifactId>
-            <optional>true</optional>
+            <scope>test</scope>
         </dependency>
-
-        <!-- for testing -->
         <dependency>
             <groupId>org.apache.camel</groupId>
             <artifactId>camel-test</artifactId>

Modified: camel/trunk/components/camel-crypto/src/main/java/org/apache/camel/component/crypto/DigitalSignatureComponent.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-crypto/src/main/java/org/apache/camel/component/crypto/DigitalSignatureComponent.java?rev=927285&r1=927284&r2=927285&view=diff
==============================================================================
--- camel/trunk/components/camel-crypto/src/main/java/org/apache/camel/component/crypto/DigitalSignatureComponent.java
(original)
+++ camel/trunk/components/camel-crypto/src/main/java/org/apache/camel/component/crypto/DigitalSignatureComponent.java
Thu Mar 25 06:12:37 2010
@@ -16,6 +16,8 @@
  */
 package org.apache.camel.component.crypto;
 
+import java.net.MalformedURLException;
+import java.net.URI;
 import java.util.Map;
 
 import org.apache.camel.CamelContext;
@@ -44,7 +46,12 @@ public class DigitalSignatureComponent e
         DigitalSignatureConfiguration config = getConfiguration().copy();
         setProperties(config, parameters);
         config.setCamelContext(getCamelContext());
-
+        try {
+            config.setCryptoOperation(new URI(remaining).getScheme());
+        } catch (Exception e) {
+            throw new MalformedURLException(String.format("An invalid crypto uri was provided
'%s'."
+                    + " Check the uri matches the format crypto:sign or crypto:verify", uri));
+        }
         return new DigitalSignatureEndpoint(uri, this, config);
     }
 

Modified: camel/trunk/components/camel-crypto/src/main/java/org/apache/camel/component/crypto/DigitalSignatureConfiguration.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-crypto/src/main/java/org/apache/camel/component/crypto/DigitalSignatureConfiguration.java?rev=927285&r1=927284&r2=927285&view=diff
==============================================================================
--- camel/trunk/components/camel-crypto/src/main/java/org/apache/camel/component/crypto/DigitalSignatureConfiguration.java
(original)
+++ camel/trunk/components/camel-crypto/src/main/java/org/apache/camel/component/crypto/DigitalSignatureConfiguration.java
Thu Mar 25 06:12:37 2010
@@ -51,6 +51,7 @@ public class DigitalSignatureConfigurati
     private String keystoreName;
     private String randomName;
     private boolean clearHeaders;
+    private String operation;
 
     public DigitalSignatureConfiguration copy() {
         try {
@@ -399,4 +400,20 @@ public class DigitalSignatureConfigurati
         this.clearHeaders = clearHeaders;
     }
 
+    /**
+     * Set the Crypto operation from that supplied after the crypto scheme in the
+     * endpoint uri e.g. crypto:sign sets sign as the operation.
+     *
+     * @param operation the operation supplied after the crypto scheme
+     */
+    public void setCryptoOperation(String operation) {
+        this.operation = operation;
+    }
+
+    /**
+     * Gets the Crypto operation that was supplied in the the crypto scheme in the endpoint
uri
+     */
+    public String getCryptoOperation() {
+        return operation;
+    }
 }

Modified: camel/trunk/components/camel-crypto/src/main/java/org/apache/camel/component/crypto/DigitalSignatureEndpoint.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-crypto/src/main/java/org/apache/camel/component/crypto/DigitalSignatureEndpoint.java?rev=927285&r1=927284&r2=927285&view=diff
==============================================================================
--- camel/trunk/components/camel-crypto/src/main/java/org/apache/camel/component/crypto/DigitalSignatureEndpoint.java
(original)
+++ camel/trunk/components/camel-crypto/src/main/java/org/apache/camel/component/crypto/DigitalSignatureEndpoint.java
Thu Mar 25 06:12:37 2010
@@ -41,7 +41,7 @@ public class DigitalSignatureEndpoint ex
     }
 
     public Producer createProducer() throws Exception {
-        return getEndpointUri().startsWith("sign")
+        return "sign".equals(configuration.getCryptoOperation())
             ? new DigitalSignatureProducer(this, new SigningProcessor(configuration)) : new
DigitalSignatureProducer(this, new VerifyingProcessor(configuration));
     }
 

Added: camel/trunk/components/camel-crypto/src/main/resources/META-INF/services/org/apache/camel/component/crypto
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-crypto/src/main/resources/META-INF/services/org/apache/camel/component/crypto?rev=927285&view=auto
==============================================================================
--- camel/trunk/components/camel-crypto/src/main/resources/META-INF/services/org/apache/camel/component/crypto
(added)
+++ camel/trunk/components/camel-crypto/src/main/resources/META-INF/services/org/apache/camel/component/crypto
Thu Mar 25 06:12:37 2010
@@ -0,0 +1,18 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+class=org.apache.camel.component.crypto.DigitalSignatureComponent

Modified: camel/trunk/components/camel-crypto/src/test/java/org/apache/camel/component/crypto/SignatureTests.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-crypto/src/test/java/org/apache/camel/component/crypto/SignatureTests.java?rev=927285&r1=927284&r2=927285&view=diff
==============================================================================
--- camel/trunk/components/camel-crypto/src/test/java/org/apache/camel/component/crypto/SignatureTests.java
(original)
+++ camel/trunk/components/camel-crypto/src/test/java/org/apache/camel/component/crypto/SignatureTests.java
Thu Mar 25 06:12:37 2010
@@ -69,7 +69,7 @@ public class SignatureTests extends Cont
         return new RouteBuilder[] {new RouteBuilder() {
             public void configure() throws Exception {
                 // START SNIPPET: basic
-                from("direct:keypair").to("sign://basic?privateKey=myPrivateKey", "verify://basic?publicKey=myPublicKey",
"mock:result");
+                from("direct:keypair").to("crypto:sign://basic?privateKey=#myPrivateKey",
"crypto:verify://basic?publicKey=#myPublicKey", "mock:result");
                 // END SNIPPET: basic
             }
         }, new RouteBuilder() {
@@ -82,61 +82,61 @@ public class SignatureTests extends Cont
                 PublicKey publicKey = keyPair.getPublic();
 
                 // we can set the keys explicitly on the endpoint instances.
-                context.getEndpoint("sign://rsa?algorithm=MD5withRSA", DigitalSignatureEndpoint.class).setPrivateKey(privateKey);
-                context.getEndpoint("verify://rsa?algorithm=MD5withRSA", DigitalSignatureEndpoint.class).setPublicKey(publicKey);
-                from("direct:algorithm").to("sign://rsa?algorithm=MD5withRSA", "verify://rsa?algorithm=MD5withRSA",
"mock:result");
+                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: buffersize
-                from("direct:buffersize").to("sign://buffer?privateKey=myPrivateKey&buffersize=1024",
"verify://buffer?publicKey=myPublicKey&buffersize=1024", "mock:result");
+                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("sign://provider?privateKey=myPrivateKey&provider=SUN",
"verify://provider?publicKey=myPublicKey&provider=SUN", "mock:result");
+                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("sign://withcert?privateKey=myPrivateKey",
"verify://withcert?certificate=myCert", "mock:result");
+                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("sign://keystore?keystore=keystore&alias=bob&password=letmein",
"verify://keystore?keystore=keystore&alias=bob", "mock:result");
+                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: signature-header
-                from("direct:signature-header").to("sign://another?privateKey=myPrivateKey&signatureHeader=AnotherDigitalSignature",
-                                                   "verify://another?publicKey=myPublicKey&signatureHeader=AnotherDigitalSignature",
"mock:result");
+                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("sign://another?privateKey=myPrivateKey&secureRandom=someRandom",
"verify://another?publicKey=myPublicKey&secureRandom=someRandom",
+                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("sign://alias?keystore=keystore");
-                from("direct:alias-verify").to("verify://alias?keystore=keystore", "mock:result");
+                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("sign://alais");
-                from("direct:headerkey-verify").to("verify://alias", "mock:result");
+                from("direct:headerkey-sign").to("crypto:sign://alias");
+                from("direct:headerkey-verify").to("crypto:verify://alias", "mock:result");
                 // END SNIPPET: headerkey
             }
         }};
@@ -299,6 +299,7 @@ public class SignatureTests extends Cont
     @Override
     protected void setUp() throws Exception {
         setUpKeys("DSA");
+        disableJMX();
         super.setUp();
     }
 

Modified: camel/trunk/components/camel-crypto/src/test/resources/org/apache/camel/component/crypto/SpringSignatureTests.xml
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-crypto/src/test/resources/org/apache/camel/component/crypto/SpringSignatureTests.xml?rev=927285&r1=927284&r2=927285&view=diff
==============================================================================
--- camel/trunk/components/camel-crypto/src/test/resources/org/apache/camel/component/crypto/SpringSignatureTests.xml
(original)
+++ camel/trunk/components/camel-crypto/src/test/resources/org/apache/camel/component/crypto/SpringSignatureTests.xml
Thu Mar 25 06:12:37 2010
@@ -26,8 +26,8 @@
         <!-- START SNIPPET: basic -->
         <route>
             <from uri="direct:keypair"/>
-            <to uri="sign://basic?privateKey=myPrivateKey" />
-            <to uri="verify://basic?publicKey=myPublicKey" />
+            <to uri="crypto:sign://basic?privateKey=#myPrivateKey" />
+            <to uri="crypto:verify://basic?publicKey=#myPublicKey" />
             <to uri="mock:result"/>
         </route>
         <!-- END SNIPPET: basic -->
@@ -35,8 +35,8 @@
         <!-- START SNIPPET: algorithm -->
         <route>
             <from uri="direct:algorithm"/>
-            <to uri="sign://rsa?algorithm=MD5withRSA&amp;privateKey=rsaPrivateKey"
/>
-            <to uri="verify://rsa?algorithm=MD5withRSA&amp;publicKey=rsaPublicKey"
/>
+            <to uri="crypto:sign://rsa?algorithm=MD5withRSA&amp;privateKey=#rsaPrivateKey"
/>
+            <to uri="crypto:verify://rsa?algorithm=MD5withRSA&amp;publicKey=#rsaPublicKey"
/>
             <to uri="mock:result"/>
         </route>        
         <!-- END SNIPPET: algorithm -->
@@ -44,8 +44,8 @@
         <!-- START SNIPPET: buffersize -->
         <route>
             <from uri="direct:buffersize" />
-            <to uri="sign://buffer?privateKey=myPrivateKey&amp;buffersize=1024" />
-            <to uri="verify://buffer?publicKey=myPublicKey&amp;buffersize=1024" />
+            <to uri="crypto:sign://buffer?privateKey=#myPrivateKey&amp;buffersize=1024"
/>
+            <to uri="crypto:verify://buffer?publicKey=#myPublicKey&amp;buffersize=1024"
/>
             <to uri="mock:result"/>
         </route>        
         <!-- END SNIPPET: buffersize -->
@@ -53,8 +53,8 @@
         <!-- START SNIPPET: random -->
         <route>
             <from uri="direct:random" />
-            <to uri="sign://random?privateKey=myPrivateKey&amp;secureRandom=someRandom"
/>
-            <to uri="verify://random?publicKey=myPublicKey" />
+            <to uri="crypto:sign://random?privateKey=#myPrivateKey&amp;secureRandom=#someRandom"
/>
+            <to uri="crypto:verify://random?publicKey=#myPublicKey" />
             <to uri="mock:result"/>
         </route>        
         <!-- END SNIPPET: random -->
@@ -62,8 +62,8 @@
         <!-- START SNIPPET: provider -->
         <route>
             <from uri="direct:provider"/>
-            <to uri="sign://provider?privateKey=myPrivateKey&amp;provider=SUN" />
-            <to uri="verify://provider?publicKey=myPublicKey&amp;provider=SUN" />
+            <to uri="crypto:sign://provider?privateKey=#myPrivateKey&amp;provider=SUN"
/>
+            <to uri="crypto:verify://provider?publicKey=#myPublicKey&amp;provider=SUN"
/>
             <to uri="mock:result"/>
         </route>        
         <!-- END SNIPPET: provider -->
@@ -71,8 +71,8 @@
         <!-- START SNIPPET: certificate -->
         <route>
             <from uri="direct:certificate"/>
-            <to uri="sign://withcert?privateKey=myPrivateKey" />
-            <to uri="verify://withcert?certificate=myCert" />
+            <to uri="crypto:sign://withcert?privateKey=#myPrivateKey" />
+            <to uri="crypto:verify://withcert?certificate=#myCert" />
             <to uri="mock:result"/>
         </route>        
         <!-- END SNIPPET: certificate -->
@@ -80,8 +80,8 @@
         <!-- START SNIPPET: keystore -->
         <route>
             <from uri="direct:keystore"/>
-            <to uri="sign://keystore?keystore=keystore&amp;alias=bob&amp;password=letmein"
/>
-            <to uri="verify://keystore?keystore=keystore&amp;alias=bob" />
+            <to uri="crypto:sign://keystore?keystore=#keystore&amp;alias=bob&amp;password=letmein"
/>
+            <to uri="crypto:verify://keystore?keystore=#keystore&amp;alias=bob" />
             <to uri="mock:result"/>
         </route>        
         <!-- END SNIPPET: keystore -->
@@ -89,8 +89,8 @@
          <!-- START SNIPPET: signature-header -->
         <route>
             <from uri="direct:signature-header"/>
-            <to uri="sign://another?privateKey=myPrivateKey&amp;signatureHeader=AnotherDigitalSignature"
/>
-            <to uri="verify://another?publicKey=myPublicKey&amp;signatureHeader=AnotherDigitalSignature"
/>
+            <to uri="crypto:sign://another?privateKey=#myPrivateKey&amp;signatureHeader=AnotherDigitalSignature"
/>
+            <to uri="crypto:verify://another?publicKey=#myPublicKey&amp;signatureHeader=AnotherDigitalSignature"
/>
             <to uri="mock:result"/>
         </route>        
         <!-- END SNIPPET: signature-header -->
@@ -98,11 +98,11 @@
         <!-- START SNIPPET: alias -->
         <route>
             <from uri="direct:alias-sign"/>
-            <to uri="sign://alias?keystore=keystore" />
+            <to uri="crypto:sign://alias?keystore=#keystore" />
         </route>       
         <route>
             <from uri="direct:alias-verify"/>
-            <to uri="verify://alias?keystore=keystore" />
+            <to uri="crypto:verify://alias?keystore=#keystore" />
             <to uri="mock:result"/>
         </route>    
         <!-- END SNIPPET: alias -->
@@ -110,11 +110,11 @@
         <!-- START SNIPPET: headerkey -->
         <route>
             <from uri="direct:headerkey-sign"/>
-            <to uri="sign://headerkey" />
+            <to uri="crypto:sign://headerkey" />
         </route>       
         <route>
             <from uri="direct:headerkey-verify"/>
-            <to uri="verify://headerkey" />
+            <to uri="crypto:verify://headerkey" />
             <to uri="mock:result"/>
         </route>    
         <!-- END SNIPPET: headerkey -->



Mime
View raw message