Skip to content

Commit 0b54c72

Browse files
author
Glover, Rene (rg9975)
committed
add config check when validating username rename
1 parent 730155c commit 0b54c72

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

server/src/main/java/com/cloud/user/AccountManagerImpl.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1589,7 +1589,16 @@ protected void validateAndUpdateUsernameIfNeeded(UpdateUserCmd updateUserCmd, Us
15891589
continue;
15901590
}
15911591

1592-
// users can't exist in same account
1592+
// duplicate usernames cannot exist in same domain unless explicitly configured
1593+
if (!userAllowMultipleAccounts.valueInDomain(account.getDomainId())) {
1594+
Account duplicatedUserAccountWithUserThatHasTheSameUserName = _accountDao.findById(duplicatedUser.getAccountId());
1595+
if (duplicatedUserAccountWithUserThatHasTheSameUserName.getDomainId() == account.getDomainId()) {
1596+
DomainVO domain = _domainDao.findById(duplicatedUserAccountWithUserThatHasTheSameUserName.getDomainId());
1597+
throw new InvalidParameterValueException(String.format("Username [%s] already exists in domain [id=%s,name=%s]", duplicatedUser.getUsername(), domain.getUuid(), domain.getName()));
1598+
}
1599+
}
1600+
1601+
// can't rename a username to an existing one in the same account
15931602
assertUserAlreadyInAccount(duplicatedUser, account);
15941603
}
15951604
user.setUsername(userName);

0 commit comments

Comments
 (0)