From 25e85e177ede708105549dcd8a0eb10f2c12b49e Mon Sep 17 00:00:00 2001 From: Alena Prokharchyk Date: Wed, 4 Apr 2012 12:53:55 -0700 Subject: [PATCH] bug 14589: don't accept empty username/firstname/lastname in update/createUser apis --- .../com/cloud/user/AccountManagerImpl.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/server/src/com/cloud/user/AccountManagerImpl.java b/server/src/com/cloud/user/AccountManagerImpl.java index 40b16ae565d..fd9c9c2099e 100755 --- a/server/src/com/cloud/user/AccountManagerImpl.java +++ b/server/src/com/cloud/user/AccountManagerImpl.java @@ -683,6 +683,18 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag if (domainId == null) { domainId = DomainVO.ROOT_DOMAIN; } + + if (userName.isEmpty()) { + throw new InvalidParameterValueException("Username is empty"); + } + + if (firstName.isEmpty()) { + throw new InvalidParameterValueException("Firstname is empty"); + } + + if (lastName.isEmpty()) { + throw new InvalidParameterValueException("Lastname is empty"); + } // Validate domain Domain domain = _domainMgr.getDomain(domainId); @@ -796,12 +808,24 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag checkAccess(UserContext.current().getCaller(), null, true, account); if (firstName != null) { + if (firstName.isEmpty()) { + throw new InvalidParameterValueException("Firstname is empty"); + } + user.setFirstname(firstName); } if (lastName != null) { + if (lastName.isEmpty()) { + throw new InvalidParameterValueException("Lastname is empty"); + } + user.setLastname(lastName); } if (userName != null) { + if (userName.isEmpty()) { + throw new InvalidParameterValueException("Username is empty"); + } + // don't allow to have same user names in the same domain List duplicatedUsers = _userDao.findUsersByName(userName); for (UserVO duplicatedUser : duplicatedUsers) { @@ -815,6 +839,7 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag user.setUsername(userName); } + if (password != null) { user.setPassword(password); }