@@ -3987,6 +3987,11 @@ private boolean updateHostsInCluster(final UpdateHostPasswordCmd command) {
39873987 // get all the hosts in this cluster
39883988 final List <HostVO > hosts = _resourceMgr .listAllHostsInCluster (command .getClusterId ());
39893989
3990+ String userNameWithoutSpaces = StringUtils .deleteWhitespace (command .getUsername ());
3991+ if (StringUtils .isBlank (userNameWithoutSpaces )) {
3992+ throw new InvalidParameterValueException ("Username should be non empty string" );
3993+ }
3994+
39903995 Transaction .execute (new TransactionCallbackNoReturn () {
39913996 @ Override
39923997 public void doInTransactionWithoutResult (final TransactionStatus status ) {
@@ -3996,7 +4001,12 @@ public void doInTransactionWithoutResult(final TransactionStatus status) {
39964001 }
39974002 // update password for this host
39984003 final DetailVO nv = _detailsDao .findDetail (h .getId (), ApiConstants .USERNAME );
3999- if (nv .getValue ().equals (command .getUsername ())) {
4004+ if (nv == null ) {
4005+ final DetailVO nvu = new DetailVO (h .getId (), ApiConstants .USERNAME , userNameWithoutSpaces );
4006+ _detailsDao .persist (nvu );
4007+ final DetailVO nvp = new DetailVO (h .getId (), ApiConstants .PASSWORD , DBEncryptionUtil .encrypt (command .getPassword ()));
4008+ _detailsDao .persist (nvp );
4009+ } else if (nv .getValue ().equals (userNameWithoutSpaces )) {
40004010 final DetailVO nvp = _detailsDao .findDetail (h .getId (), ApiConstants .PASSWORD );
40014011 nvp .setValue (DBEncryptionUtil .encrypt (command .getPassword ()));
40024012 _detailsDao .persist (nvp );
@@ -4044,6 +4054,12 @@ public boolean updateHostPassword(final UpdateHostPasswordCmd cmd) {
40444054 if (!supportedHypervisors .contains (host .getHypervisorType ())) {
40454055 throw new InvalidParameterValueException ("This operation is not supported for this hypervisor type" );
40464056 }
4057+
4058+ String userNameWithoutSpaces = StringUtils .deleteWhitespace (cmd .getUsername ());
4059+ if (StringUtils .isBlank (userNameWithoutSpaces )) {
4060+ throw new InvalidParameterValueException ("Username should be non empty string" );
4061+ }
4062+
40474063 Transaction .execute (new TransactionCallbackNoReturn () {
40484064 @ Override
40494065 public void doInTransactionWithoutResult (final TransactionStatus status ) {
@@ -4052,7 +4068,12 @@ public void doInTransactionWithoutResult(final TransactionStatus status) {
40524068 }
40534069 // update password for this host
40544070 final DetailVO nv = _detailsDao .findDetail (host .getId (), ApiConstants .USERNAME );
4055- if (nv .getValue ().equals (cmd .getUsername ())) {
4071+ if (nv == null ) {
4072+ final DetailVO nvu = new DetailVO (host .getId (), ApiConstants .USERNAME , userNameWithoutSpaces );
4073+ _detailsDao .persist (nvu );
4074+ final DetailVO nvp = new DetailVO (host .getId (), ApiConstants .PASSWORD , DBEncryptionUtil .encrypt (cmd .getPassword ()));
4075+ _detailsDao .persist (nvp );
4076+ } else if (nv .getValue ().equals (userNameWithoutSpaces )) {
40564077 final DetailVO nvp = _detailsDao .findDetail (host .getId (), ApiConstants .PASSWORD );
40574078 nvp .setValue (DBEncryptionUtil .encrypt (cmd .getPassword ()));
40584079 _detailsDao .persist (nvp );
0 commit comments