You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ri...@apache.org on 2007/04/11 18:09:55 UTC
svn commit: r527558 -
/incubator/qpid/branches/M2/java/broker/src/main/java/org/apache/qpid/server/security/auth/database/Base64MD5PasswordFilePrincipalDatabase.java
Author: ritchiem
Date: Wed Apr 11 09:09:54 2007
New Revision: 527558
URL: http://svn.apache.org/viewvc?view=rev&rev=527558
Log:
QpiQPID-446 Update to ensure qpid.password file is correctly written in savePasswordFile
Modified:
incubator/qpid/branches/M2/java/broker/src/main/java/org/apache/qpid/server/security/auth/database/Base64MD5PasswordFilePrincipalDatabase.java
Modified: incubator/qpid/branches/M2/java/broker/src/main/java/org/apache/qpid/server/security/auth/database/Base64MD5PasswordFilePrincipalDatabase.java
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/M2/java/broker/src/main/java/org/apache/qpid/server/security/auth/database/Base64MD5PasswordFilePrincipalDatabase.java?view=diff&rev=527558&r1=527557&r2=527558
==============================================================================
--- incubator/qpid/branches/M2/java/broker/src/main/java/org/apache/qpid/server/security/auth/database/Base64MD5PasswordFilePrincipalDatabase.java (original)
+++ incubator/qpid/branches/M2/java/broker/src/main/java/org/apache/qpid/server/security/auth/database/Base64MD5PasswordFilePrincipalDatabase.java Wed Apr 11 09:09:54 2007
@@ -201,7 +201,7 @@
for (byte b : passwdBytes)
{
- passwd[index] = (char) b;
+ passwd[index++] = (char) b;
}
return passwd;
@@ -311,6 +311,7 @@
}
User user = new User(result);
+ _logger.info("Created user:" + user);
_users.put(user.getName(), user);
}
}
@@ -328,6 +329,10 @@
BufferedReader reader = null;
PrintStream writer = null;
File tmp = new File(_passwordFile.getAbsolutePath() + ".tmp");
+ if (tmp.exists())
+ {
+ tmp.delete();
+ }
try
{
writer = new PrintStream(tmp);
@@ -348,12 +353,14 @@
if (user == null)
{
writer.write(line.getBytes(DEFAULT_ENCODING));
+ writer.println();
}
else if (!user.isDeleted())
{
if (!user.isModified())
{
writer.write(line.getBytes(DEFAULT_ENCODING));
+ writer.println();
}
else
{
@@ -363,16 +370,38 @@
writer.write((user.getName() + ":").getBytes(DEFAULT_ENCODING));
writer.write(encodedPassword);
+ writer.println();
+
+ user.saved();
}
catch (EncoderException e)
{
_logger.warn("Unable to encode new password reverting to old password.");
writer.write(line.getBytes(DEFAULT_ENCODING));
+ writer.println();
}
}
}
+ }
-
+ for (User user : _users.values())
+ {
+ if (user.isModified())
+ {
+ byte[] encodedPassword;
+ try
+ {
+ encodedPassword = user.getEncodePassword();
+ writer.write((user.getName() + ":").getBytes(DEFAULT_ENCODING));
+ writer.write(encodedPassword);
+ writer.println();
+ user.saved();
+ }
+ catch (EncoderException e)
+ {
+ _logger.warn("Unable to get Encoded password for user'" + user.getName() + "' password not saved");
+ }
+ }
}
}
finally
@@ -388,7 +417,14 @@
}
// Swap temp file to main password file.
+ File old = new File(_passwordFile.getAbsoluteFile() + ".old");
+ if (old.exists())
+ {
+ old.delete();
+ }
+ _passwordFile.renameTo(old);
tmp.renameTo(_passwordFile);
+ tmp.delete();
}
}
@@ -436,6 +472,11 @@
return _name;
}
+ public String toString()
+ {
+ return getName() + ((_encodedPassword == null) ? "" : ":" + _encodedPassword);
+ }
+
char[] getPassword()
{
return _password;
@@ -477,6 +518,11 @@
public void delete()
{
_deleted = true;
+ }
+
+ public void saved()
+ {
+ _modified = false;
}
}
}