You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2019/04/29 11:05:43 UTC

[camel] branch master updated: Fixed camel-crypto-cms mutlivalue issue with signer option. Lets make it more tooling friendly also.

This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/master by this push:
     new 14bf64b  Fixed camel-crypto-cms mutlivalue issue with signer option. Lets make it more tooling friendly also.
14bf64b is described below

commit 14bf64b1ac88807adf0a5751613c8aa46b591482
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Mon Apr 29 13:05:24 2019 +0200

    Fixed camel-crypto-cms mutlivalue issue with signer option. Lets make it more tooling friendly also.
---
 .../src/main/docs/crypto-cms-component.adoc        |  6 ++--
 .../cms/sig/SignedDataCreatorConfiguration.java    | 38 ++++++++++++----------
 .../camel/component/crypto/cms/ComponentTest.java  |  2 +-
 .../camel/component/crypto/cms/ProcessorsTest.java |  2 +-
 .../camel/component/crypto/cms/SignedDataTest.java |  4 +--
 .../src/test/resources/SpringCryptoCmsTests.xml    |  2 +-
 6 files changed, 28 insertions(+), 26 deletions(-)

diff --git a/components/camel-crypto-cms/src/main/docs/crypto-cms-component.adoc b/components/camel-crypto-cms/src/main/docs/crypto-cms-component.adoc
index 90c385a..4c8106b 100644
--- a/components/camel-crypto-cms/src/main/docs/crypto-cms-component.adoc
+++ b/components/camel-crypto-cms/src/main/docs/crypto-cms-component.adoc
@@ -85,7 +85,7 @@ with the following path and query parameters:
 | *unprotectedAttributes GeneratorProvider* (encrypt) | Provider of the generator for the unprotected attributes. The default value is null which means no unprotected attribute is added to the Enveloped Data object. See https://tools.ietf.org/html/rfc5652#section-6.1. |  | AttributesGenerator Provider
 | *toBase64* (encrypt_sign) | Indicates whether the Signed Data or Enveloped Data instance shall be base 64 encoded. Default value is false. | false | Boolean
 | *includeContent* (sign) | Indicates whether the signed content should be included into the Signed Data instance. If false then a detached Signed Data instance is created in the header CamelCryptoCmsSignedData. | true | Boolean
-| *signer* (sign) | Signer information: reference to a bean which implements org.apache.camel.component.crypto.cms.api.SignerInfo |  | List
+| *signer* (sign) | Signer information: reference to bean(s) which implements org.apache.camel.component.crypto.cms.api.SignerInfo. Multiple values can be separated by comma |  | String
 | *signedDataHeaderBase64* (verify) | Indicates whether the value in the header CamelCryptoCmsSignedData is base64 encoded. Default value is false. Only relevant for detached signatures. In the detached signature case, the header contains the Signed Data object. | false | Boolean
 | *verifySignaturesOfAll Signers* (verify) | If true then the signatures of all signers contained in the Signed Data object are verified. If false then only one signature whose signer info matches with one of the specified certificates is verified. Default value is true. | true | Boolean
 |===
@@ -326,7 +326,7 @@ simpleReg.put("signer1", signerInfo1); //register signer info in the registry
 simpleReg.put("signer2", signerInfo2); //register signer info in the registry
 
 from("direct:start")
-    .to("crypto-cms:sign://testsign?signer=#signer1&signer=#signer2&includeContent=true")
+    .to("crypto-cms:sign://testsign?signer=#signer1,#signer2&includeContent=true")
     .to("crypto-cms:verify://testverify?keyStoreParameters=#keyStoreParameters")
     .to("mock:result");
 ----
@@ -358,7 +358,7 @@ from("direct:start")
 ...
     <route>
         <from uri="direct:start" />
-        <to uri="crypto-cms:sign://testsign?signer=#signer1&amp;signer=#signer2&amp;includeContent=true" />
+        <to uri="crypto-cms:sign://testsign?signer=#signer1,#signer2&amp;includeContent=true" />
         <to uri="crypto-cms:verify://testverify?keyStoreParameters=#keyStoreParameters1" />
         <to uri="mock:result" />
     </route>    
diff --git a/components/camel-crypto-cms/src/main/java/org/apache/camel/component/crypto/cms/sig/SignedDataCreatorConfiguration.java b/components/camel-crypto-cms/src/main/java/org/apache/camel/component/crypto/cms/sig/SignedDataCreatorConfiguration.java
index f00047c..e2b34dd 100644
--- a/components/camel-crypto-cms/src/main/java/org/apache/camel/component/crypto/cms/sig/SignedDataCreatorConfiguration.java
+++ b/components/camel-crypto-cms/src/main/java/org/apache/camel/component/crypto/cms/sig/SignedDataCreatorConfiguration.java
@@ -35,8 +35,8 @@ public class SignedDataCreatorConfiguration extends CryptoCmsMarshallerConfigura
     @UriParam(label = "sign", defaultValue = "true")
     private Boolean includeContent = Boolean.TRUE;
 
-    @UriParam(label = "sign", multiValue = true, description = "Signer information: reference to a bean which implements org.apache.camel.component.crypto.cms.api.SignerInfo")
-    private final List<SignerInfo> signer = new ArrayList<>(3);
+    @UriParam(label = "sign", javaType = "java.lang.String", description = "Signer information: reference to bean(s) which implements org.apache.camel.component.crypto.cms.api.SignerInfo. Multiple values can be separated by comma")
+    private List<SignerInfo> signer = new ArrayList<>();
 
     public SignedDataCreatorConfiguration(CamelContext context) {
         super(context);
@@ -59,28 +59,30 @@ public class SignedDataCreatorConfiguration extends CryptoCmsMarshallerConfigura
         return signer;
     }
 
-    public void setSigner(SignerInfo signer) {
-        this.signer.add(signer);
+    public void setSigner(List<SignerInfo> signer) {
+        this.signer = signer;
     }
 
-    // for multi values
-    public void setSigner(List<?> signers) {
-        if (signers == null) {
-            return;
-        }
-        for (Object signerOb : signers) {
-            if (signerOb instanceof String) {
-                String signerName = (String)signerOb;
-                String valueNoHash = signerName.replaceAll("#", "");
-                if (getContext() != null && signerName != null) {
-                    SignerInfo signer = getContext().getRegistry().lookupByNameAndType(valueNoHash, SignerInfo.class);
-                    if (signer != null) {
-                        setSigner(signer);
-                    }
+    public void setSigner(String signer) {
+        String[] values = signer.split(",");
+        for (String s : values) {
+            if (s.startsWith("#")) {
+                s = s.substring(1);
+            }
+            if (getContext() != null) {
+                SignerInfo obj = getContext().getRegistry().lookupByNameAndType(s, SignerInfo.class);
+                if (obj != null) {
+                    addSigner(obj);
                 }
             }
         }
+    }
 
+    public void addSigner(SignerInfo info) {
+        if (this.signer == null) {
+            this.signer = new ArrayList<>();
+        }
+        this.signer.add(info);
     }
 
     public void init() throws CryptoCmsException {
diff --git a/components/camel-crypto-cms/src/test/java/org/apache/camel/component/crypto/cms/ComponentTest.java b/components/camel-crypto-cms/src/test/java/org/apache/camel/component/crypto/cms/ComponentTest.java
index 16bb2b8..622a305 100644
--- a/components/camel-crypto-cms/src/test/java/org/apache/camel/component/crypto/cms/ComponentTest.java
+++ b/components/camel-crypto-cms/src/test/java/org/apache/camel/component/crypto/cms/ComponentTest.java
@@ -127,7 +127,7 @@ public class ComponentTest extends CamelTestSupport {
 
                 onException(CryptoCmsVerifierCertificateNotValidException.class).handled(false).to("mock:exception");
 
-                from("direct:start").to("crypto-cms:sign://testsign?signer=#signer1&signer=#signer2&includeContent=true")
+                from("direct:start").to("crypto-cms:sign://testsign?signer=#signer1,#signer2&includeContent=true")
                     .to("crypto-cms:encrypt://testencrpyt?toBase64=true&recipient=#recipient1&contentEncryptionAlgorithm=DESede/CBC/PKCS5Padding&secretKeyLength=128")
                     // .to("file:target/test_signed_encrypted.base64")
                     .to("crypto-cms:decrypt://testdecrypt?fromBase64=true&keyStoreParameters=#keyStoreParameters")
diff --git a/components/camel-crypto-cms/src/test/java/org/apache/camel/component/crypto/cms/ProcessorsTest.java b/components/camel-crypto-cms/src/test/java/org/apache/camel/component/crypto/cms/ProcessorsTest.java
index ce45890..445781f 100644
--- a/components/camel-crypto-cms/src/test/java/org/apache/camel/component/crypto/cms/ProcessorsTest.java
+++ b/components/camel-crypto-cms/src/test/java/org/apache/camel/component/crypto/cms/ProcessorsTest.java
@@ -99,7 +99,7 @@ public class ProcessorsTest extends CamelTestSupport {
                 signerInfo.setKeyStoreParameters(keystore);
 
                 SignedDataCreatorConfiguration config = new SignedDataCreatorConfiguration(new DefaultCamelContext());
-                config.setSigner(signerInfo);
+                config.addSigner(signerInfo);
                 config.setIncludeContent(true); // optional default value is
                                                 // true
                 config.init();
diff --git a/components/camel-crypto-cms/src/test/java/org/apache/camel/component/crypto/cms/SignedDataTest.java b/components/camel-crypto-cms/src/test/java/org/apache/camel/component/crypto/cms/SignedDataTest.java
index 012e63c..55100ca 100644
--- a/components/camel-crypto-cms/src/test/java/org/apache/camel/component/crypto/cms/SignedDataTest.java
+++ b/components/camel-crypto-cms/src/test/java/org/apache/camel/component/crypto/cms/SignedDataTest.java
@@ -128,7 +128,7 @@ public class SignedDataTest {
 
         SignedDataCreatorConfiguration config = new SignedDataCreatorConfiguration(new DefaultCamelContext());
         for (SignerInfo signer : signers) {
-            config.setSigner(signer);
+            config.addSigner(signer);
         }
         // config.setBlockSize(blockSize); // optional
         config.setIncludeContent(includeContent); // optional default value is
@@ -350,7 +350,7 @@ public class SignedDataTest {
         signerInfo.setKeyStoreParameters(keystore);
 
         SignedDataCreatorConfiguration config = new SignedDataCreatorConfiguration(new DefaultCamelContext());
-        config.setSigner(signerInfo);
+        config.addSigner(signerInfo);
         config.setIncludeContent(false); // optional default value is true
         config.setToBase64(Boolean.TRUE);
         config.init();
diff --git a/components/camel-crypto-cms/src/test/resources/SpringCryptoCmsTests.xml b/components/camel-crypto-cms/src/test/resources/SpringCryptoCmsTests.xml
index 820f1bd..b60ea20 100644
--- a/components/camel-crypto-cms/src/test/resources/SpringCryptoCmsTests.xml
+++ b/components/camel-crypto-cms/src/test/resources/SpringCryptoCmsTests.xml
@@ -39,7 +39,7 @@
         <route>
             <from uri="direct:start" />
             <to
-                uri="crypto-cms:sign://testsign?signer=#signer1&amp;signer=#signer2&amp;includeContent=true" />
+                uri="crypto-cms:sign://testsign?signer=#signer1,signer=#signer2&amp;includeContent=true" />
             <to
                 uri="crypto-cms:encrypt://testencrpyt?toBase64=true&amp;recipient=#recipient1&amp;contentEncryptionAlgorithm=DESede/CBC/PKCS5Padding&amp;secretKeyLength=128" />
             <to