AccountManagerImpl extends ManagerBase implements AccountManager, Manager { @Override public boolean disableAccount(final long accountId) throws ConcurrentOperationException, ResourceUnavailableException { boolean success = false; if (accountId <= 2) { if (s_logger.isInfoEnabled()) { s_logger.info("disableAccount -- invalid account id: " + accountId); } return false; } final AccountVO account = _accountDao.findById(accountId); if ((account == null) || (account.getState().equals(State.disabled) && !account.getNeedsCleanup())) { success = true; } else { AccountVO acctForUpdate = _accountDao.createForUpdate(); acctForUpdate.setState(State.disabled); success = _accountDao.update(Long.valueOf(accountId), acctForUpdate); if (success) { boolean disableAccountResult = false; try { disableAccountResult = doDisableAccount(accountId); } finally { if (!disableAccountResult) { s_logger.warn("Failed to disable account " + account + " resources as a part of disableAccount call, marking the account for cleanup"); _accountDao.markForCleanup(accountId); } else { acctForUpdate = _accountDao.createForUpdate(); account.setNeedsCleanup(false); _accountDao.update(accountId, account); } } } } return success; }  List<UserAuthenticator> getUserAuthenticators(); void setUserAuthenticators(final List<UserAuthenticator> authenticators); List<UserAuthenticator> getUserPasswordEncoders(); void setUserPasswordEncoders(final List<UserAuthenticator> encoders); List<SecurityChecker> getSecurityCheckers(); void setSecurityCheckers(final List<SecurityChecker> securityCheckers); List<QuerySelector> getQuerySelectors(); void setQuerySelectors(final List<QuerySelector> querySelectors); @Override boolean configure(final String name, final Map<String, Object> params); @Override UserVO getSystemUser(); @Override boolean start(); @Override boolean stop(); @Override AccountVO getSystemAccount(); @Override boolean isAdmin(final Long accountId); @Override boolean isRootAdmin(final Long accountId); @Override boolean isDomainAdmin(final Long accountId); @Override boolean isNormalUser(final long accountId); boolean isResourceDomainAdmin(final Long accountId); boolean isInternalAccount(final long accountId); @Override void checkAccess(final Account caller, final Domain domain); @Override void checkAccess(final Account caller, final AccessType accessType, final boolean sameOwner, final ControlledEntity... entities); @Override void checkAccess(final Account caller, final AccessType accessType, final boolean sameOwner, final String apiName, final ControlledEntity... entities); @Override Long checkAccessAndSpecifyAuthority(final Account caller, final Long zoneId); @DB void updateLoginAttempts(final Long id, final int attempts, final boolean toDisable); @Override boolean enableAccount(final long accountId); @Override boolean deleteAccount(final AccountVO account, final long callerUserId, final Account caller); @Override boolean disableAccount(final long accountId); @Override @ActionEvents({ @ActionEvent(eventType = EventTypes.EVENT_ACCOUNT_CREATE, eventDescription = "creating Account"), @ActionEvent(eventType = EventTypes.EVENT_USER_CREATE, eventDescription = "creating User") }) UserAccount createUserAccount(final String userName, final String password, final String firstName, final String lastName, final String email, final String timezone,
                                         final String accountName, final short accountType, final Long domainId, final String networkDomain, final Map<String, String> details, final String accountUUID, final String userUUID); @Override @DB @ActionEvents({ @ActionEvent(eventType = EventTypes.EVENT_ACCOUNT_CREATE, eventDescription = "creating Account"), @ActionEvent(eventType = EventTypes.EVENT_USER_CREATE, eventDescription = "creating User") }) UserAccount createUserAccount(final String userName, final String password, final String firstName, final String lastName, final String email,
                                         final String timezone, String accountName, final short accountType, Long domainId, final String networkDomain, final Map<String, String> details,
                                         final String accountUUID, final String userUUID, final User.Source source); @Override @ActionEvent(eventType = EventTypes.EVENT_USER_CREATE, eventDescription = "creating User") UserVO createUser(final String userName, final String password, final String firstName, final String lastName, final String email, final String timeZone, final String accountName, Long domainId,
                             final String userUUID, final User.Source source); @Override @ActionEvent(eventType = EventTypes.EVENT_USER_CREATE, eventDescription = "creating User") UserVO createUser(final String userName, final String password, final String firstName, final String lastName, final String email, final String timeZone, final String accountName, final Long domainId,
                             final String userUUID); @Override @ActionEvent(eventType = EventTypes.EVENT_USER_UPDATE, eventDescription = "updating User") UserAccount updateUser(final Long userId, final String firstName, final String lastName, final String email, final String userName, final String password, final String apiKey, final String secretKey, final String timeZone); @Override @ActionEvent(eventType = EventTypes.EVENT_USER_UPDATE, eventDescription = "updating User") UserAccount updateUser(final UpdateUserCmd cmd); @Override @ActionEvent(eventType = EventTypes.EVENT_USER_DISABLE, eventDescription = "disabling User", async = true) UserAccount disableUser(final long userId); @Override @DB @ActionEvent(eventType = EventTypes.EVENT_USER_ENABLE, eventDescription = "enabling User") UserAccount enableUser(final long userId); @Override @ActionEvent(eventType = EventTypes.EVENT_USER_LOCK, eventDescription = "locking User") UserAccount lockUser(final long userId); @Override @ActionEvent(eventType = EventTypes.EVENT_ACCOUNT_DELETE, eventDescription = "deleting account", async = true) // This method deletes the account boolean deleteUserAccount(final long accountId); @Override @ActionEvent(eventType = EventTypes.EVENT_ACCOUNT_ENABLE, eventDescription = "enabling account", async = true) AccountVO enableAccount(final String accountName, final Long domainId, final Long accountId); @Override @ActionEvent(eventType = EventTypes.EVENT_ACCOUNT_DISABLE, eventDescription = "locking account", async = true) AccountVO lockAccount(final String accountName, final Long domainId, final Long accountId); @Override @ActionEvent(eventType = EventTypes.EVENT_ACCOUNT_DISABLE, eventDescription = "disabling account", async = true) AccountVO disableAccount(final String accountName, final Long domainId, final Long accountId); @Override @DB @ActionEvent(eventType = EventTypes.EVENT_ACCOUNT_UPDATE, eventDescription = "updating account", async = true) AccountVO updateAccount(final UpdateAccountCmd cmd); @Override @ActionEvent(eventType = EventTypes.EVENT_USER_DELETE, eventDescription = "deleting User") boolean deleteUser(final DeleteUserCmd deleteUserCmd); @Override Account finalizeOwner(final Account caller, final String accountName, final Long domainId, final Long projectId); @Override Account getActiveAccountByName(final String accountName, final Long domainId); @Override UserAccount getActiveUserAccount(final String username, final Long domainId); @Override Account getActiveAccountById(final long accountId); @Override Account getAccount(final long accountId); @Override RoleType getRoleType(final Account account); @Override User getActiveUser(final long userId); @Override User getUserIncludingRemoved(final long userId); @Override User getActiveUserByRegistrationToken(final String registrationToken); @Override void markUserRegistered(final long userId); @Override @DB AccountVO createAccount(final String accountName, final short accountType, final Long domainId, final String networkDomain, final Map<String, String> details,
                                   final String uuid); @Override void logoutUser(final long userId); @Override UserAccount authenticateUser(final String username, final String password, final Long domainId, final InetAddress loginIpAddress, final Map<String, Object[]> requestParameters); @Override Pair<User, Account> findUserByApiKey(final String apiKey); @Override @DB @ActionEvent(eventType = EventTypes.EVENT_REGISTER_FOR_SECRET_API_KEY, eventDescription = "register for the developer API keys") String[] createApiKeyAndSecretKey(final RegisterCmd cmd); @Override @DB @ActionEvent(eventType = EventTypes.EVENT_REGISTER_FOR_SECRET_API_KEY, eventDescription = "register for the developer API keys") String[] createApiKeyAndSecretKey(final long userId); @Override void buildACLSearchBuilder(final SearchBuilder<? extends ControlledEntity> sb,
                                      final Long domainId, final boolean isRecursive, final List<Long> permittedAccounts, final ListProjectResourcesCriteria listProjectResourcesCriteria); @Override void buildACLSearchCriteria(final SearchCriteria<? extends ControlledEntity> sc,
                                       final Long domainId, final boolean isRecursive, final List<Long> permittedAccounts, final ListProjectResourcesCriteria listProjectResourcesCriteria); @Override void buildACLSearchParameters(final Account caller, final Long id, final String accountName, final Long projectId, final List<Long> permittedAccounts,
                                         final Ternary<Long, Boolean, ListProjectResourcesCriteria> domainIdRecursiveListProject, final boolean listAll, final boolean forProjectInvitation); @Override void buildACLViewSearchBuilder(final SearchBuilder<? extends ControlledViewEntity> sb, final Long domainId,
                                          final boolean isRecursive, final List<Long> permittedAccounts, final ListProjectResourcesCriteria listProjectResourcesCriteria); @Override void buildACLViewSearchCriteria(final SearchCriteria<? extends ControlledViewEntity> sc,
                                           final Long domainId, final boolean isRecursive, final List<Long> permittedAccounts, final ListProjectResourcesCriteria listProjectResourcesCriteria); @Override UserAccount getUserByApiKey(final String apiKey); @Override List<String> listAclGroupsByAccount(final Long accountId); @Override Long finalyzeAccountId(final String accountName, final Long domainId, final Long projectId, final boolean enabledOnly); @Override UserAccount getUserAccountById(final Long userId); @Override void checkAccess(final Account account, final ServiceOffering so); @Override void checkAccess(final Account account, final DiskOffering dof); static final Logger s_logger; @Inject
    public com.cloud.region.ha.GlobalLoadBalancingRulesService _gslbService; }
@Test public void disableAccountNotexisting() throws ConcurrentOperationException, ResourceUnavailableException { Mockito.when(_accountDao.findById(42l)).thenReturn(null); Assert.assertTrue(accountManager.disableAccount(42)); }
@Test public void disableAccountDisabled() throws ConcurrentOperationException, ResourceUnavailableException { AccountVO disabledAccount = new AccountVO(); disabledAccount.setState(State.disabled); Mockito.when(_accountDao.findById(42l)).thenReturn(disabledAccount); Assert.assertTrue(accountManager.disableAccount(42)); }
@Test public void disableAccount() throws ConcurrentOperationException, ResourceUnavailableException { AccountVO account = new AccountVO(); account.setState(State.enabled); Mockito.when(_accountDao.findById(42l)).thenReturn(account); Mockito.when(_accountDao.createForUpdate()).thenReturn(new AccountVO()); Mockito.when( _accountDao.update(Mockito.eq(42l), Mockito.any(AccountVO.class))).thenReturn(true); Mockito.when(_vmDao.listByAccountId(42l)).thenReturn( Arrays.asList(Mockito.mock(VMInstanceVO.class))); Assert.assertTrue(accountManager.disableAccount(42)); Mockito.verify(_accountDao, Mockito.atLeastOnce()).update( Mockito.eq(42l), Mockito.any(AccountVO.class)); }