diff options
author | Robert Gemmell <robbie@apache.org> | 2009-08-17 15:50:59 +0000 |
---|---|---|
committer | Robert Gemmell <robbie@apache.org> | 2009-08-17 15:50:59 +0000 |
commit | 6064d7714f0745f618302982fb0df0509f70d6c4 (patch) | |
tree | faae32073c12820e73cb96da04dfb5fa26c0c906 | |
parent | f8d3c9d43f8a3f64acb029958030f2abd3b6b6a3 (diff) | |
download | qpid-python-6064d7714f0745f618302982fb0df0509f70d6c4.tar.gz |
QPID-2040: update the save process for the plain password file. Only attempt the move if the new file is created successfully. Check if the rename/move succeeds, and if not attempt a copy instead
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@805017 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r-- | qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/database/PlainPasswordFilePrincipalDatabase.java | 47 |
1 files changed, 39 insertions, 8 deletions
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/database/PlainPasswordFilePrincipalDatabase.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/database/PlainPasswordFilePrincipalDatabase.java index 5e4678a63b..6ec7cea4c0 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/database/PlainPasswordFilePrincipalDatabase.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/database/PlainPasswordFilePrincipalDatabase.java @@ -26,6 +26,7 @@ import org.apache.qpid.server.security.auth.sasl.UsernamePrincipal; import org.apache.qpid.server.security.auth.sasl.amqplain.AmqPlainInitialiser; import org.apache.qpid.server.security.auth.sasl.crammd5.CRAMMD5Initialiser; import org.apache.qpid.server.security.auth.sasl.plain.PlainInitialiser; +import org.apache.qpid.util.FileUtils; import javax.security.auth.callback.PasswordCallback; import javax.security.auth.login.AccountNotFoundException; @@ -395,6 +396,7 @@ public class PlainPasswordFilePrincipalDatabase implements PrincipalDatabase BufferedReader reader = null; PrintStream writer = null; File tmp = File.createTempFile(_passwordFile.getName(), ".tmp"); + tmp.deleteOnExit(); try { @@ -452,6 +454,11 @@ public class PlainPasswordFilePrincipalDatabase implements PrincipalDatabase } } } + catch(IOException e) + { + _logger.error("Unable to create the new password file: " + e); + throw new IOException("Unable to create the new password file" + e); + } finally { if (reader != null) @@ -463,17 +470,41 @@ public class PlainPasswordFilePrincipalDatabase implements PrincipalDatabase { writer.close(); } - - // Swap temp file to main password file. - File old = new File(_passwordFile.getAbsoluteFile() + ".old"); - if (old.exists()) + } + + // Swap temp file to main password file. + File old = new File(_passwordFile.getAbsoluteFile() + ".old"); + if (old.exists()) + { + old.delete(); + } + + try + { + if(!_passwordFile.renameTo(old)) { - old.delete(); + FileUtils.copyCheckedEx(_passwordFile, old); } - _passwordFile.renameTo(old); - tmp.renameTo(_passwordFile); - tmp.delete(); } + catch (IOException e) + { + _logger.error("Could not backup the existing password file: " +e); + throw new IOException("Could not backup the existing password file: " + e); + } + + try + { + if(!tmp.renameTo(_passwordFile)) + { + FileUtils.copyCheckedEx(tmp, _passwordFile); + } + } + catch (IOException e) + { + _logger.error("Could not copy the new password file into place: " +e); + throw new IOException("Could not copy the new password file into place: " + e); + } + } finally { |