ws-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cohei...@apache.org
Subject svn commit: r1623958 - /webservices/wss4j/trunk/ws-security-common/src/main/java/org/apache/wss4j/common/crypto/JasyptPasswordEncryptor.java
Date Wed, 10 Sep 2014 09:40:52 GMT
Author: coheigea
Date: Wed Sep 10 09:40:52 2014
New Revision: 1623958

URL: http://svn.apache.org/r1623958
Log:
Delay asking a CallbackHandler for a password for the JasyptPasswordEncryptor until it is
actually needed

Modified:
    webservices/wss4j/trunk/ws-security-common/src/main/java/org/apache/wss4j/common/crypto/JasyptPasswordEncryptor.java

Modified: webservices/wss4j/trunk/ws-security-common/src/main/java/org/apache/wss4j/common/crypto/JasyptPasswordEncryptor.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/trunk/ws-security-common/src/main/java/org/apache/wss4j/common/crypto/JasyptPasswordEncryptor.java?rev=1623958&r1=1623957&r2=1623958&view=diff
==============================================================================
--- webservices/wss4j/trunk/ws-security-common/src/main/java/org/apache/wss4j/common/crypto/JasyptPasswordEncryptor.java
(original)
+++ webservices/wss4j/trunk/ws-security-common/src/main/java/org/apache/wss4j/common/crypto/JasyptPasswordEncryptor.java
Wed Sep 10 09:40:52 2014
@@ -41,6 +41,7 @@ public class JasyptPasswordEncryptor imp
         org.slf4j.LoggerFactory.getLogger(JasyptPasswordEncryptor.class);
     
     private final StandardPBEStringEncryptor passwordEncryptor;
+    private CallbackHandler callbackHandler;
     
     public JasyptPasswordEncryptor(String masterPassword) {
         this(masterPassword, DEFAULT_ALGORITHM);
@@ -59,19 +60,7 @@ public class JasyptPasswordEncryptor imp
     public JasyptPasswordEncryptor(CallbackHandler callbackHandler, String algorithm) {
         passwordEncryptor = new StandardPBEStringEncryptor();
         passwordEncryptor.setAlgorithm(algorithm);
-        
-        WSPasswordCallback pwCb = 
-            new WSPasswordCallback("", WSPasswordCallback.PASSWORD_ENCRYPTOR_PASSWORD);
-        try {
-            callbackHandler.handle(new Callback[]{pwCb});
-        } catch (IOException e) {
-            LOG.debug("Error in getting master password: ", e);
-        } catch (UnsupportedCallbackException e) {
-            LOG.debug("Error in getting master password: ", e);
-        }
-        if (pwCb.getPassword() != null) {
-            passwordEncryptor.setPassword(pwCb.getPassword());
-        }
+        this.callbackHandler = callbackHandler;
     }
 
     /**
@@ -80,6 +69,20 @@ public class JasyptPasswordEncryptor imp
      * @return the encrypted password
      */
     public String encrypt(String password) {
+        if (callbackHandler != null) {
+            WSPasswordCallback pwCb = 
+                new WSPasswordCallback("", WSPasswordCallback.PASSWORD_ENCRYPTOR_PASSWORD);
+            try {
+                callbackHandler.handle(new Callback[]{pwCb});
+            } catch (IOException e) {
+                LOG.debug("Error in getting master password: ", e);
+            } catch (UnsupportedCallbackException e) {
+                LOG.debug("Error in getting master password: ", e);
+            }
+            if (pwCb.getPassword() != null) {
+                passwordEncryptor.setPassword(pwCb.getPassword());
+            }
+        }
         return passwordEncryptor.encrypt(password);
     }
     
@@ -89,6 +92,20 @@ public class JasyptPasswordEncryptor imp
      * @return the decrypted password
      */
     public String decrypt(String encryptedPassword) {
+        if (callbackHandler != null) {
+            WSPasswordCallback pwCb = 
+                new WSPasswordCallback("", WSPasswordCallback.PASSWORD_ENCRYPTOR_PASSWORD);
+            try {
+                callbackHandler.handle(new Callback[]{pwCb});
+            } catch (IOException e) {
+                LOG.debug("Error in getting master password: ", e);
+            } catch (UnsupportedCallbackException e) {
+                LOG.debug("Error in getting master password: ", e);
+            }
+            if (pwCb.getPassword() != null) {
+                passwordEncryptor.setPassword(pwCb.getPassword());
+            }
+        }
         return passwordEncryptor.decrypt(encryptedPassword);
     }
     



Mime
View raw message