camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cohei...@apache.org
Subject camel git commit: Extend the DefaultKeySelector so that you can use Jasypt encoded passwords
Date Thu, 27 Nov 2014 23:17:48 GMT
Repository: camel
Updated Branches:
  refs/heads/camel-2.14.x f9044427b -> 71eed349b


Extend the DefaultKeySelector so that you can use Jasypt encoded passwords


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/71eed349
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/71eed349
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/71eed349

Branch: refs/heads/camel-2.14.x
Commit: 71eed349b8ba7fa160cc1d3a10bfb9de4e25041b
Parents: f904442
Author: Colm O hEigeartaigh <coheigea@apache.org>
Authored: Thu Nov 27 22:43:06 2014 +0000
Committer: Colm O hEigeartaigh <coheigea@apache.org>
Committed: Thu Nov 27 23:04:50 2014 +0000

----------------------------------------------------------------------
 .../xmlsecurity/api/DefaultKeySelector.java     | 33 ++++++++++++++++++--
 1 file changed, 30 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/71eed349/components/camel-xmlsecurity/src/main/java/org/apache/camel/component/xmlsecurity/api/DefaultKeySelector.java
----------------------------------------------------------------------
diff --git a/components/camel-xmlsecurity/src/main/java/org/apache/camel/component/xmlsecurity/api/DefaultKeySelector.java
b/components/camel-xmlsecurity/src/main/java/org/apache/camel/component/xmlsecurity/api/DefaultKeySelector.java
index bcb8982..1091ccd 100644
--- a/components/camel-xmlsecurity/src/main/java/org/apache/camel/component/xmlsecurity/api/DefaultKeySelector.java
+++ b/components/camel-xmlsecurity/src/main/java/org/apache/camel/component/xmlsecurity/api/DefaultKeySelector.java
@@ -32,6 +32,9 @@ import javax.xml.crypto.KeySelectorResult;
 import javax.xml.crypto.XMLCryptoContext;
 import javax.xml.crypto.dsig.keyinfo.KeyInfo;
 
+import org.apache.camel.CamelContext;
+import org.apache.camel.CamelContextAware;
+import org.apache.camel.RuntimeCamelException;
 import org.apache.camel.util.jsse.KeyStoreParameters;
 
 /**
@@ -39,11 +42,13 @@ import org.apache.camel.util.jsse.KeyStoreParameters;
  * for a given alias. Depending on the purpose a private or public key is
  * returned.
  */
-public class DefaultKeySelector extends KeySelector {
+public class DefaultKeySelector extends KeySelector implements CamelContextAware {
 
     private final KeyStoreAndAlias keyStoreAndAlias = new KeyStoreAndAlias();
 
     private KeySelectorResult nullKeyResult;
+    
+    private CamelContext context;
 
     public void setKeyStore(KeyStore keyStore) {
         keyStoreAndAlias.setKeyStore(keyStore);
@@ -57,7 +62,7 @@ public class DefaultKeySelector extends KeySelector {
         if (password == null) {
             keyStoreAndAlias.setPassword(null);
         } else {
-            keyStoreAndAlias.setPassword(password.toCharArray());
+            setPassword(password.toCharArray());
         }
     }
 
@@ -99,7 +104,19 @@ public class DefaultKeySelector extends KeySelector {
             }
             Key key;
             try {
-                key = keyStoreAndAlias.getKeyStore().getKey(keyStoreAndAlias.getAlias(),
keyStoreAndAlias.getPassword());
+                if (this.getCamelContext() != null && keyStoreAndAlias.getPassword()
!= null) {
+                    try {
+                        String passwordProperty = 
+                            this.getCamelContext().resolvePropertyPlaceholders(
+                                new String(keyStoreAndAlias.getPassword()));
+                        key = keyStoreAndAlias.getKeyStore().getKey(keyStoreAndAlias.getAlias(),
passwordProperty.toCharArray());
+                    } catch (Exception e) {
+                        throw new RuntimeCamelException("Error parsing property value: "

+                            + new String(keyStoreAndAlias.getPassword()), e);
+                    }
+                } else {
+                    key = keyStoreAndAlias.getKeyStore().getKey(keyStoreAndAlias.getAlias(),
keyStoreAndAlias.getPassword());
+                }
             } catch (UnrecoverableKeyException e) {
                 throw new KeySelectorException(e);
             } catch (KeyStoreException e) {
@@ -140,4 +157,14 @@ public class DefaultKeySelector extends KeySelector {
         return nullKeyResult;
     }
 
+    @Override
+    public CamelContext getCamelContext() {
+        return context;
+    }
+
+    @Override
+    public void setCamelContext(CamelContext context) {
+        this.context = context;
+    }
+
 }


Mime
View raw message