geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vamsic...@apache.org
Subject svn commit: r477213 - /geronimo/server/trunk/modules/geronimo-security/src/main/java/org/apache/geronimo/security/keystore/FileKeystoreInstance.java
Date Mon, 20 Nov 2006 15:00:20 GMT
Author: vamsic007
Date: Mon Nov 20 07:00:20 2006
New Revision: 477213

URL: http://svn.apache.org/viewvc?view=rev&rev=477213
Log:
GERONIMO-2587 FileKeystoreInstance.loadKeystoreData() results in inconsistent state if wrong
password is supplied

Modified:
    geronimo/server/trunk/modules/geronimo-security/src/main/java/org/apache/geronimo/security/keystore/FileKeystoreInstance.java

Modified: geronimo/server/trunk/modules/geronimo-security/src/main/java/org/apache/geronimo/security/keystore/FileKeystoreInstance.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-security/src/main/java/org/apache/geronimo/security/keystore/FileKeystoreInstance.java?view=diff&rev=477213&r1=477212&r2=477213
==============================================================================
--- geronimo/server/trunk/modules/geronimo-security/src/main/java/org/apache/geronimo/security/keystore/FileKeystoreInstance.java
(original)
+++ geronimo/server/trunk/modules/geronimo-security/src/main/java/org/apache/geronimo/security/keystore/FileKeystoreInstance.java
Mon Nov 20 07:00:20 2006
@@ -580,16 +580,18 @@
     // ==================== Internals =====================
 
     private void loadKeystoreData(char[] password) throws KeystoreException {
+        InputStream in = null;
         try {
-            keystoreReadDate = System.currentTimeMillis();
+            // Make sure the keystore is loadable using the provided password before resetting
the instance variables.
+            KeyStore tempKeystore = KeyStore.getInstance(JKS);
+            in = new BufferedInputStream(new FileInputStream(keystoreFile));
+            long readDate = System.currentTimeMillis();
+            tempKeystore.load(in, password);
+            // Keystore could be loaded successfully.  Initialize the instance variables
to reflect the new keystore.
+            keystore = tempKeystore;
+            keystoreReadDate = readDate;
             privateKeys.clear();
             trustCerts.clear();
-            if(keystore == null) {
-                keystore = KeyStore.getInstance(JKS);
-            }
-            InputStream in = new BufferedInputStream(new FileInputStream(keystoreFile));
-            keystore.load(in, password);
-            in.close();
             openPassword = password;
             Enumeration aliases = keystore.aliases();
             while (aliases.hasMoreElements()) {
@@ -608,6 +610,14 @@
             throw new KeystoreException("Unable to open keystore with provided password",
e);
         } catch (CertificateException e) {
             throw new KeystoreException("Unable to open keystore with provided password",
e);
+        } finally {
+            if(in != null) {
+                try {
+                    in.close();
+                } catch (IOException e) {
+                    log.error("Error while closing keystore file "+keystoreFile.getAbsolutePath(),
e);
+                }
+            }
         }
     }
 



Mime
View raw message