throws Exception {
/* get old password from user */
char [] oldPassword = getOldPassword() ;
UserManager userMgr = UserManager.getInstance() ;
User user = userMgr.verifyUsernamePassword(AuthConstants.USER_ADMIN,oldPassword);
if(user == null) {
System.out.println("\nInvalid password") ;
return ;
}
/* get new password from user */
char[] newPassword = getPassword();
if(newPassword == null){
return;
}
/* Get list of configured applications */
Crypto.init(oldPassword) ;
Config config = ConfigReader.getInstance().read() ;
if(config == null) {
System.out.println("\nError in reading application passwords") ;
return ;
}
/* Write new key to file */
EncryptedKey encryptedKey = new EncryptedKey(newPassword);
KeyManager.writeKey(encryptedKey);
/* Change admin password */
UserManager.getInstance().deleteUser(AuthConstants.USER_ADMIN);
List roles = new ArrayList(1); // TODO: Shouldn't this be zero ? -rk
UserManager.getInstance().addUser(new User(AuthConstants.USER_ADMIN,
Crypto.hash(newPassword), roles, User.STATUS_ACTIVE, 0));
Crypto.init(newPassword);
ConfigWriter.getInstance().write(config);
System.out.println("New key has been written to key file successfully..");
}