[jboss-cvs] JBossAS SVN: r59904 - branches/Branch_4_2/security/src/main/org/jboss/security/plugins.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Jan 22 03:05:05 EST 2007


Author: scott.stark at jboss.org
Date: 2007-01-22 03:05:05 -0500 (Mon, 22 Jan 2007)
New Revision: 59904

Modified:
   branches/Branch_4_2/security/src/main/org/jboss/security/plugins/TmpFilePassword.java
Log:
Allow for a timeout

Modified: branches/Branch_4_2/security/src/main/org/jboss/security/plugins/TmpFilePassword.java
===================================================================
--- branches/Branch_4_2/security/src/main/org/jboss/security/plugins/TmpFilePassword.java	2007-01-22 04:43:13 UTC (rev 59903)
+++ branches/Branch_4_2/security/src/main/org/jboss/security/plugins/TmpFilePassword.java	2007-01-22 08:05:05 UTC (rev 59904)
@@ -25,6 +25,7 @@
 import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.CharArrayWriter;
+import java.io.InterruptedIOException;
 import java.io.RandomAccessFile;
 
 import org.jboss.logging.Logger;
@@ -46,10 +47,31 @@
 {
    private static Logger log = Logger.getLogger(TmpFilePassword.class);
    private File passwordFile;
+   private long timeoutSystemTime;
 
+   /**
+    * Load a password file file. Invokes this(file, null).
+    * @param file - the file to load the password from.  
+    */
    public TmpFilePassword(String file)
    {
+      this(file, null);
+   }
+   /**
+    * Load a password from file.
+    * 
+    * @param file - the file to load the password from.  
+    * @param timeout - the timeout in milliseconds. If null, no
+    * timeout will be used.
+    */
+   public TmpFilePassword(String file, String timeout)
+   {
       passwordFile = new File(file);
+      if( timeout != null )
+      {
+         long ms = Long.parseLong(timeout);
+         timeoutSystemTime = System.currentTimeMillis() + ms;
+      }
    }
 
    public char[] toCharArray()
@@ -67,6 +89,9 @@
             log.info("Exiting wait on InterruptedException");
             break;
          }
+         long now = System.currentTimeMillis();
+         if( now > timeoutSystemTime )
+            throw new InterruptedIOException("Timed out waiting for: "+passwordFile.getAbsolutePath());
       }
       FileInputStream fis = new FileInputStream(passwordFile);
       CharArrayWriter writer = new CharArrayWriter();




More information about the jboss-cvs-commits mailing list