This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch CAMEL-13870 in repository https://gitbox.apache.org/repos/asf/camel.git
commit b1ac54017a0bfe03ab66e787bf24aeb9dd61a18b Author: Claus Ibsen <claus.ib...@gmail.com> AuthorDate: Tue Aug 20 20:33:54 2019 +0200 CAMEL-13870: Fast property configuration of Camel endpoints. Work in progress. --- .../crypto/DigitalSignatureConfiguration.java | 57 +++++++++++++++++----- .../component/crypto/DigitalSignatureEndpoint.java | 6 +-- .../crypto/processor/SigningProcessor.java | 2 +- .../DigitalSignatureEndpointBuilderFactory.java | 14 +----- .../DigitalSignatureComponentConfiguration.java | 6 +-- 5 files changed, 53 insertions(+), 32 deletions(-) diff --git a/components/camel-crypto/src/main/java/org/apache/camel/component/crypto/DigitalSignatureConfiguration.java b/components/camel-crypto/src/main/java/org/apache/camel/component/crypto/DigitalSignatureConfiguration.java index c81eb20..a0151dc 100644 --- a/components/camel-crypto/src/main/java/org/apache/camel/component/crypto/DigitalSignatureConfiguration.java +++ b/components/camel-crypto/src/main/java/org/apache/camel/component/crypto/DigitalSignatureConfiguration.java @@ -16,11 +16,16 @@ */ package org.apache.camel.component.crypto; +import java.io.IOException; +import java.security.GeneralSecurityException; import java.security.KeyStore; +import java.security.KeyStoreException; +import java.security.NoSuchAlgorithmException; import java.security.PrivateKey; import java.security.PublicKey; import java.security.SecureRandom; import java.security.Signature; +import java.security.UnrecoverableKeyException; import java.security.cert.Certificate; import org.apache.camel.CamelContext; @@ -59,8 +64,8 @@ public class DigitalSignatureConfiguration implements Cloneable, CamelContextAwa private String signatureHeaderName; @UriParam private String alias; - @UriParam(label = "security", javaType = "java.lang.String", secret = true) - private char[] password; + @UriParam(label = "security", secret = true) + private String password; @UriParam(label = "advanced") private PublicKey publicKey; @UriParam(label = "advanced") @@ -151,8 +156,8 @@ public class DigitalSignatureConfiguration implements Cloneable, CamelContextAwa /** * Get the PrivateKey that should be used to sign the exchange */ - public PrivateKey getPrivateKey() throws Exception { - return getPrivateKey(alias, password); + public PrivateKey getPrivateKey() { + return getPrivateKey(alias, password.toCharArray()); } /** @@ -162,7 +167,7 @@ public class DigitalSignatureConfiguration implements Cloneable, CamelContextAwa * @param alias the alias used to retrieve the Certificate from the keystore. */ public PrivateKey getPrivateKey(String alias) throws Exception { - return getPrivateKey(alias, password); + return getPrivateKey(alias, password.toCharArray()); } /** @@ -171,10 +176,14 @@ public class DigitalSignatureConfiguration implements Cloneable, CamelContextAwa * * @param alias the alias used to retrieve the Certificate from the keystore. */ - public PrivateKey getPrivateKey(String alias, char[] password) throws Exception { + public PrivateKey getPrivateKey(String alias, char[] password) { PrivateKey pk = null; if (alias != null && keystore != null) { - pk = (PrivateKey)keystore.getKey(alias, password); + try { + pk = (PrivateKey)keystore.getKey(alias, password); + } catch (Exception e) { + throw new RuntimeException(e); + } } if (pk == null) { pk = privateKey; @@ -191,6 +200,10 @@ public class DigitalSignatureConfiguration implements Cloneable, CamelContextAwa this.privateKey = privateKey; } + public String getPrivateKeyName() { + return privateKeyName; + } + /** * Sets the reference name for a PrivateKey that can be found in the registry. */ @@ -213,6 +226,10 @@ public class DigitalSignatureConfiguration implements Cloneable, CamelContextAwa this.publicKey = publicKey; } + public String getPublicKeyName() { + return publicKeyName; + } + /** * Sets the reference name for a publicKey that can be found in the registry. */ @@ -259,7 +276,7 @@ public class DigitalSignatureConfiguration implements Cloneable, CamelContextAwa * Get the explicitly configured {@link Certificate} that should be used to * verify the signature in the exchange. */ - public Certificate getCertificate() throws Exception { + public Certificate getCertificate() { return certificate; } @@ -271,6 +288,10 @@ public class DigitalSignatureConfiguration implements Cloneable, CamelContextAwa this.certificate = certificate; } + public String getCertificateName() { + return certificateName; + } + /** * Sets the reference name for a PrivateKey that can be found in the registry. */ @@ -310,6 +331,10 @@ public class DigitalSignatureConfiguration implements Cloneable, CamelContextAwa this.keystore = keystore; } + public String getKeystoreName() { + return keystoreName; + } + /** * Sets the reference name for a Keystore that can be found in the registry. */ @@ -328,14 +353,14 @@ public class DigitalSignatureConfiguration implements Cloneable, CamelContextAwa /** * Gets the password used to access an aliased {@link PrivateKey} in the KeyStore. */ - public char[] getPassword() { + public String getPassword() { return password; } /** * Sets the password used to access an aliased {@link PrivateKey} in the KeyStore. */ - public void setPassword(char[] password) { + public void setPassword(String password) { this.password = password; } @@ -352,10 +377,14 @@ public class DigitalSignatureConfiguration implements Cloneable, CamelContextAwa * supplied and there is only a single entry in the Keystore, then this * single entry will be used. */ - public void setKeyStoreParameters(KeyStoreParameters keyStoreParameters) throws Exception { + public void setKeyStoreParameters(KeyStoreParameters keyStoreParameters) { this.keyStoreParameters = keyStoreParameters; if (keyStoreParameters != null) { - this.keystore = keyStoreParameters.createKeyStore(); + try { + this.keystore = keyStoreParameters.createKeyStore(); + } catch (Exception e) { + throw new RuntimeException(e); + } } } @@ -366,6 +395,10 @@ public class DigitalSignatureConfiguration implements Cloneable, CamelContextAwa return secureRandom; } + public String getSecureRandomName() { + return secureRandomName; + } + /** * Sets the reference name for a SecureRandom that can be found in the registry. */ diff --git a/components/camel-crypto/src/main/java/org/apache/camel/component/crypto/DigitalSignatureEndpoint.java b/components/camel-crypto/src/main/java/org/apache/camel/component/crypto/DigitalSignatureEndpoint.java index 9d6c26f..f8269fe 100644 --- a/components/camel-crypto/src/main/java/org/apache/camel/component/crypto/DigitalSignatureEndpoint.java +++ b/components/camel-crypto/src/main/java/org/apache/camel/component/crypto/DigitalSignatureEndpoint.java @@ -58,7 +58,7 @@ public class DigitalSignatureEndpoint extends DefaultEndpoint { throw new UnsupportedOperationException("Digital Signatures endpoints are not meant to be consumed from. They are meant be used as an intermediate endpoints"); } -/** + /** * Sets the configuration to use */ public void setConfiguration(DigitalSignatureConfiguration configuration) { @@ -101,11 +101,11 @@ public class DigitalSignatureEndpoint extends DefaultEndpoint { getConfiguration().setKeystore(keystore); } - public char[] getPassword() { + public String getPassword() { return getConfiguration().getPassword(); } - public void setKeyPassword(char[] keyPassword) { + public void setKeyPassword(String keyPassword) { getConfiguration().setPassword(keyPassword); } diff --git a/components/camel-crypto/src/main/java/org/apache/camel/component/crypto/processor/SigningProcessor.java b/components/camel-crypto/src/main/java/org/apache/camel/component/crypto/processor/SigningProcessor.java index 142ee3c..dbbc43e 100644 --- a/components/camel-crypto/src/main/java/org/apache/camel/component/crypto/processor/SigningProcessor.java +++ b/components/camel-crypto/src/main/java/org/apache/camel/component/crypto/processor/SigningProcessor.java @@ -80,7 +80,7 @@ public class SigningProcessor extends DigitalSignatureProcessor { if (keystore != null) { password = exchange.getIn().getHeader(DigitalSignatureConstants.KEYSTORE_PASSWORD, char[].class); if (password == null) { - password = config.getPassword(); + password = config.getPassword() != null ? config.getPassword().toCharArray() : null; } } return password; diff --git a/core/camel-endpointdsl/src/main/java/org/apache/camel/builder/endpoint/dsl/DigitalSignatureEndpointBuilderFactory.java b/core/camel-endpointdsl/src/main/java/org/apache/camel/builder/endpoint/dsl/DigitalSignatureEndpointBuilderFactory.java index 7414fe8..9b1197a 100644 --- a/core/camel-endpointdsl/src/main/java/org/apache/camel/builder/endpoint/dsl/DigitalSignatureEndpointBuilderFactory.java +++ b/core/camel-endpointdsl/src/main/java/org/apache/camel/builder/endpoint/dsl/DigitalSignatureEndpointBuilderFactory.java @@ -220,19 +220,7 @@ public interface DigitalSignatureEndpointBuilderFactory { * Sets the password used to access an aliased PrivateKey in the * KeyStore. * - * The option is a: <code>char[]</code> type. - * - * Group: security - */ - default DigitalSignatureEndpointBuilder password(Character[] password) { - setProperty("password", password); - return this; - } - /** - * Sets the password used to access an aliased PrivateKey in the - * KeyStore. - * - * The option will be converted to a <code>char[]</code> type. + * The option is a: <code>java.lang.String</code> type. * * Group: security */ diff --git a/platforms/spring-boot/components-starter/camel-crypto-starter/src/main/java/org/apache/camel/component/crypto/springboot/DigitalSignatureComponentConfiguration.java b/platforms/spring-boot/components-starter/camel-crypto-starter/src/main/java/org/apache/camel/component/crypto/springboot/DigitalSignatureComponentConfiguration.java index 1dcccde..9c48f9c 100644 --- a/platforms/spring-boot/components-starter/camel-crypto-starter/src/main/java/org/apache/camel/component/crypto/springboot/DigitalSignatureComponentConfiguration.java +++ b/platforms/spring-boot/components-starter/camel-crypto-starter/src/main/java/org/apache/camel/component/crypto/springboot/DigitalSignatureComponentConfiguration.java @@ -137,7 +137,7 @@ public class DigitalSignatureComponentConfiguration * Sets the password used to access an aliased {@link PrivateKey} in the * KeyStore. */ - private char[] password; + private String password; /** * Sets the KeyStore that can contain keys and Certficates for use in * signing and verifying exchanges based on the given @@ -272,11 +272,11 @@ public class DigitalSignatureComponentConfiguration this.keystoreName = keystoreName; } - public char[] getPassword() { + public String getPassword() { return password; } - public void setPassword(char[] password) { + public void setPassword(String password) { this.password = password; }