You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by da...@apache.org on 2020/10/29 08:43:27 UTC

[cloudstack] branch 4.14 updated: Failed to update host password if username/password is not saved in db (#4359)

This is an automated email from the ASF dual-hosted git repository.

dahn pushed a commit to branch 4.14
in repository https://gitbox.apache.org/repos/asf/cloudstack.git


The following commit(s) were added to refs/heads/4.14 by this push:
     new 8b99411  Failed to update host password if username/password is not saved in db (#4359)
8b99411 is described below

commit 8b994113ff11fc08e2418f694796c68576de5975
Author: Rakesh <ra...@gmail.com>
AuthorDate: Thu Oct 29 09:43:05 2020 +0100

    Failed to update host password if username/password is not saved in db (#4359)
---
 .../com/cloud/server/ManagementServerImpl.java     | 25 ++++++++++++++++++++--
 1 file changed, 23 insertions(+), 2 deletions(-)

diff --git a/server/src/main/java/com/cloud/server/ManagementServerImpl.java b/server/src/main/java/com/cloud/server/ManagementServerImpl.java
index 926aca9..1b1debb 100644
--- a/server/src/main/java/com/cloud/server/ManagementServerImpl.java
+++ b/server/src/main/java/com/cloud/server/ManagementServerImpl.java
@@ -3929,6 +3929,11 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
         // get all the hosts in this cluster
         final List<HostVO> hosts = _resourceMgr.listAllHostsInCluster(command.getClusterId());
 
+        String userNameWithoutSpaces = StringUtils.deleteWhitespace(command.getUsername());
+        if (StringUtils.isBlank(userNameWithoutSpaces)) {
+            throw new InvalidParameterValueException("Username should be non empty string");
+        }
+
         Transaction.execute(new TransactionCallbackNoReturn() {
             @Override
             public void doInTransactionWithoutResult(final TransactionStatus status) {
@@ -3938,7 +3943,12 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
                     }
                     // update password for this host
                     final DetailVO nv = _detailsDao.findDetail(h.getId(), ApiConstants.USERNAME);
-                    if (nv.getValue().equals(command.getUsername())) {
+                    if (nv == null) {
+                        final DetailVO nvu = new DetailVO(h.getId(), ApiConstants.USERNAME, userNameWithoutSpaces);
+                        _detailsDao.persist(nvu);
+                        final DetailVO nvp = new DetailVO(h.getId(), ApiConstants.PASSWORD, DBEncryptionUtil.encrypt(command.getPassword()));
+                        _detailsDao.persist(nvp);
+                    } else if (nv.getValue().equals(userNameWithoutSpaces)) {
                         final DetailVO nvp = _detailsDao.findDetail(h.getId(), ApiConstants.PASSWORD);
                         nvp.setValue(DBEncryptionUtil.encrypt(command.getPassword()));
                         _detailsDao.persist(nvp);
@@ -3986,6 +3996,12 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
         if (!supportedHypervisors.contains(host.getHypervisorType())) {
             throw new InvalidParameterValueException("This operation is not supported for this hypervisor type");
         }
+
+        String userNameWithoutSpaces = StringUtils.deleteWhitespace(cmd.getUsername());
+        if (StringUtils.isBlank(userNameWithoutSpaces)) {
+            throw new InvalidParameterValueException("Username should be non empty string");
+        }
+
         Transaction.execute(new TransactionCallbackNoReturn() {
             @Override
             public void doInTransactionWithoutResult(final TransactionStatus status) {
@@ -3994,7 +4010,12 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
                 }
                 // update password for this host
                 final DetailVO nv = _detailsDao.findDetail(host.getId(), ApiConstants.USERNAME);
-                if (nv.getValue().equals(cmd.getUsername())) {
+                if (nv == null) {
+                    final DetailVO nvu = new DetailVO(host.getId(), ApiConstants.USERNAME, userNameWithoutSpaces);
+                    _detailsDao.persist(nvu);
+                    final DetailVO nvp = new DetailVO(host.getId(), ApiConstants.PASSWORD, DBEncryptionUtil.encrypt(cmd.getPassword()));
+                    _detailsDao.persist(nvp);
+                } else if (nv.getValue().equals(userNameWithoutSpaces)) {
                     final DetailVO nvp = _detailsDao.findDetail(host.getId(), ApiConstants.PASSWORD);
                     nvp.setValue(DBEncryptionUtil.encrypt(cmd.getPassword()));
                     _detailsDao.persist(nvp);