@@ -1447,9 +1447,7 @@ public UserVO createUser(String userName, String password, String firstName, Str
14471447 List <UserVO > duplicatedUsers = _userDao .findUsersByName (userName );
14481448 for (UserVO duplicatedUser : duplicatedUsers ) {
14491449 // users can't exist in same account
1450- if (duplicatedUser .getAccountId () == account .getId ()) {
1451- throw new InvalidParameterValueException (String .format ("Username [%s] already exists in account [id=%s,name=%s]" , duplicatedUser .getUsername (), account .getUuid (), account .getAccountName ()));
1452- }
1450+ assertUserAlreadyInAccount (duplicatedUser , account );
14531451 }
14541452
14551453 UserVO user = null ;
@@ -1592,15 +1590,7 @@ protected void validateAndUpdateUsernameIfNeeded(UpdateUserCmd updateUserCmd, Us
15921590 }
15931591
15941592 // users can't exist in same account
1595- if (duplicatedUser .getAccountId () == account .getId ()) {
1596- throw new InvalidParameterValueException (String .format ("Username [%s] already exists in account [id=%s,name=%s]" , duplicatedUser .getUsername (), account .getUuid (), account .getAccountName ()));
1597- }
1598-
1599- /**Account duplicatedUserAccountWithUserThatHasTheSameUserName = _accountDao.findById(duplicatedUser.getAccountId());
1600- if (duplicatedUserAccountWithUserThatHasTheSameUserName.getDomainId() == account.getDomainId()) {
1601- DomainVO domain = _domainDao.findById(duplicatedUserAccountWithUserThatHasTheSameUserName.getDomainId());
1602- throw new InvalidParameterValueException(String.format("Username [%s] already exists in domain [id=%s,name=%s]", duplicatedUser.getUsername(), domain.getUuid(), domain.getName()));
1603- }*/
1593+ assertUserAlreadyInAccount (duplicatedUser , account );
16041594 }
16051595 user .setUsername (userName );
16061596 }
@@ -3522,4 +3512,10 @@ public UserAccount clearUserTwoFactorAuthenticationInSetupStateOnLogin(UserAccou
35223512 return userAccountVO ;
35233513 });
35243514 }
3515+
3516+ private void assertUserAlreadyInAccount (User user , Account account ) {
3517+ if (user .getAccountId () == account .getId ()) {
3518+ throw new InvalidParameterValueException (String .format ("Username [%s] already exists in account [id=%s,name=%s]" , user .getUsername (), account .getUuid (), account .getAccountName ()));
3519+ }
3520+ }
35253521}
0 commit comments