mirror of https://github.com/apache/cloudstack.git
bug 11709: saving encrypted password in db
status 11709: resolved fixed
This commit is contained in:
parent
d601313b35
commit
e6474ff85a
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in New Issue