diff --git a/server/src/com/cloud/user/AccountManagerImpl.java b/server/src/com/cloud/user/AccountManagerImpl.java index f584aa1aef1..4a8a4c4c436 100755 --- a/server/src/com/cloud/user/AccountManagerImpl.java +++ b/server/src/com/cloud/user/AccountManagerImpl.java @@ -1421,32 +1421,42 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag checkAccess(UserContext.current().getCaller(), account); - if (firstName == null) { - firstName = user.getFirstname(); + if (firstName != null) { + user.setFirstname(firstName); } - if (lastName == null) { - lastName = user.getLastname(); + if (lastName != null) { + user.setLastname(lastName); } - if (userName == null) { - userName = user.getUsername(); + if (userName != null) { + //don't allow to have same user names in the same domain + List duplicatedUsers = _userDao.findUsersLike(userName); + for (UserVO duplicatedUser : duplicatedUsers) { + if (duplicatedUser.getId() != user.getId()) { + Account duplicatedUserAccount = _accountDao.findById(duplicatedUser.getAccountId()); + if (duplicatedUserAccount.getDomainId() == account.getDomainId()) { + throw new InvalidParameterValueException("User with name " + userName + " already exists in domain " + duplicatedUserAccount.getDomainId()); + } + } + } + + user.setUsername(userName); } - if (password == null) { - password = user.getPassword(); + if (password != null) { + user.setPassword(password); } - if (email == null) { - email = user.getEmail(); + if (email != null) { + user.setEmail(email); } - if (timeZone == null) { - timeZone = user.getTimezone(); + if (timeZone != null) { + user.setTimezone(timeZone); } - if (apiKey == null) { - apiKey = user.getApiKey(); + if (apiKey != null) { + user.setApiKey(apiKey); } - if (secretKey == null) { - secretKey = user.getSecretKey(); + if (secretKey != null) { + user.setSecretKey(secretKey); } - Long accountId = user.getAccountId(); if (s_logger.isDebugEnabled()) { s_logger.debug("updating user with id: " + id); @@ -1465,8 +1475,8 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag } } } - - _userDao.update(id, userName, password, firstName, lastName, email, accountId, timeZone, apiKey, secretKey); + + _userDao.update(id, user); } catch (Throwable th) { s_logger.error("error updating user", th); throw new CloudRuntimeException("Unable to update user " + id); diff --git a/server/src/com/cloud/user/dao/UserDao.java b/server/src/com/cloud/user/dao/UserDao.java index 4ee3a12a85b..1ec7eb21469 100644 --- a/server/src/com/cloud/user/dao/UserDao.java +++ b/server/src/com/cloud/user/dao/UserDao.java @@ -33,21 +33,6 @@ public interface UserDao extends GenericDao{ UserVO getUser(long userId); List findUsersLike(String username); - /** - * updates a user with the new username, password, firstname, lastname, email,accountId, timezone - * @param id - * @param username - * @param password - * @param firstname - * @param lastname - * @param email - * @param accountId - * @param timezone - * @param apikey - * @param secretkey - */ - void update(long id, String username, String password, String firstname, String lastname, String email, Long accountId, String timezone, String apiKey, String secretKey); - List listByAccount(long accountId); /** diff --git a/server/src/com/cloud/user/dao/UserDaoImpl.java b/server/src/com/cloud/user/dao/UserDaoImpl.java index 9fba2b19d9a..7af8ec7d9b9 100644 --- a/server/src/com/cloud/user/dao/UserDaoImpl.java +++ b/server/src/com/cloud/user/dao/UserDaoImpl.java @@ -26,7 +26,6 @@ import com.cloud.user.UserVO; import com.cloud.utils.db.GenericDaoBase; import com.cloud.utils.db.SearchBuilder; import com.cloud.utils.db.SearchCriteria; -import com.cloud.utils.exception.CloudRuntimeException; /** * Implementation of the UserDao @@ -116,29 +115,6 @@ public class UserDaoImpl extends GenericDaoBase implements UserDao SearchCriteria sc = SecretKeySearch.create(); sc.setParameters("secretKey", secretKey); return findOneBy(sc); - } - - @Override - public void update(long id, String username, String password, String firstname, String lastname, String email, Long accountId, String timezone, String apiKey, String secretKey) - { - UserVO dbUser = getUser(username); - if ((dbUser == null) || (dbUser.getId() == id)) { - UserVO ub = createForUpdate(); - ub.setUsername(username); - ub.setPassword(password); - ub.setFirstname(firstname); - ub.setLastname(lastname); - ub.setEmail(email); - ub.setAccountId(accountId); - ub.setTimezone(timezone); - ub.setApiKey(apiKey); - ub.setSecretKey(secretKey); - update(id, ub); - } - else - { - throw new CloudRuntimeException("unable to update user -- a user with that name exists"); - } } @Override