bug 11709: saving encrypted password in db

status 11709: resolved fixed
This commit is contained in:
Abhinandan Prateek 2011-11-02 16:47:42 +05:30
parent d601313b35
commit e6474ff85a
1 changed files with 14 additions and 1 deletions

View File

@ -364,12 +364,13 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
Long userId = UserContext.current().getCallerUserId();
Long vmId = cmd.getId();
UserVmVO userVm = _vmDao.findById(cmd.getId());
_vmDao.loadDetails(userVm);
// Do parameters input validation
if (userVm == null) {
throw new InvalidParameterValueException("unable to find a virtual machine with id " + cmd.getId());
}
VMTemplateVO template = _templateDao.findByIdIncludingRemoved(userVm.getTemplateId());
if (template == null || !template.getEnablePassword()) {
throw new InvalidParameterValueException("Fail to reset password for the virtual machine, the template is not password enabled");
@ -386,6 +387,18 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
if (result) {
userVm.setPassword(password);
//update the password in vm_details table too
// Check if an SSH key pair was selected for the instance and if so use it to encrypt & save the vm password
String sshPublicKey = userVm.getDetail("SSH.PublicKey");
if (sshPublicKey != null && !sshPublicKey.equals("") && password != null && !password.equals("saved_password")) {
String encryptedPasswd = RSAHelper.encryptWithSSHPublicKey(sshPublicKey, password);
if (encryptedPasswd == null) {
throw new CloudRuntimeException("Error encrypting password");
}
userVm.setDetail("Encrypted.Password", encryptedPasswd);
_vmDao.saveDetails(userVm);
}
}
return userVm;