public static Account findAccountByNameDomain(String accountName, Long domainId) { return s_accountDao.findActiveAccount(accountName, domainId); }
@Override public Account getActiveAccountByName(String accountName, Long domainId) { if (accountName == null || domainId == null) { throw new InvalidParameterValueException("Both accountName and domainId are required for finding active account in the system"); } else { return _accountDao.findActiveAccount(accountName, domainId); } }
@Override public List<QuotaSummaryResponse> createQuotaSummaryResponse(final String accountName, final Long domainId) { List<QuotaSummaryResponse> result = new ArrayList<QuotaSummaryResponse>(); if (accountName != null && domainId != null) { Account account = _accountDao.findActiveAccount(accountName, domainId); QuotaSummaryResponse qr = getQuotaSummaryResponse(account); result.add(qr); } return result; }
public void checkCallerAccess(String accountName, Long domainId) { Account caller = CallContext.current().getCallingAccount(); Account owner = _accountDao.findActiveAccount(accountName, domainId); if (owner == null) { List<String> idList = new ArrayList<String>(); idList.add(ApiDBUtils.findDomainById(domainId).getUuid()); throw new InvalidParameterValueException("Unable to find account " + accountName + " in domain with specifed domainId"); } _accountMgr.checkAccess(caller, null, false, owner); }
@Override public void doInTransactionWithoutResult(TransactionStatus status) { for (String accountName : accountNamesFinal) { Account permittedAccount = _accountDao.findActiveAccount(accountName, domain.getId()); if (permittedAccount != null) { if (permittedAccount.getId() == caller.getId()) { continue; // don't grant permission to the template // owner, they implicitly have permission } accountIds.add(permittedAccount.getId()); LaunchPermissionVO existingPermission = _launchPermissionDao.findByTemplateAndAccount(id, permittedAccount.getId()); if (existingPermission == null) { LaunchPermissionVO launchPermission = new LaunchPermissionVO(id, permittedAccount.getId()); _launchPermissionDao.persist(launchPermission); } } else { throw new InvalidParameterValueException("Unable to grant a launch permission to account " + accountName + " in domain id=" + domain.getUuid() + ", account not found. " + "No permissions updated, please verify the account names and retry."); } } } });
@Override public LinkAccountToLdapResponse linkAccountToLdap(LinkAccountToLdapCmd cmd) { Validate.notNull(_ldapConfiguration.getBaseDn(cmd.getDomainId()), "can not link an account to ldap in a domain for which no basdn is configured"); Validate.notNull(cmd.getDomainId(), "domainId cannot be null."); Validate.notEmpty(cmd.getAccountName(), "accountName cannot be empty."); Validate.notEmpty(cmd.getLdapDomain(), "ldapDomain cannot be empty, please supply a GROUP or OU name"); Validate.notNull(cmd.getType(), "type cannot be null. It should either be GROUP or OU"); Validate.notEmpty(cmd.getLdapDomain(), "GROUP or OU name cannot be empty"); LinkType linkType = LdapManager.LinkType.valueOf(cmd.getType().toUpperCase()); Account account = accountDao.findActiveAccount(cmd.getAccountName(),cmd.getDomainId()); if (account == null) { account = new AccountVO(cmd.getAccountName(), cmd.getDomainId(), null, cmd.getAccountType(), UUID.randomUUID().toString()); accountDao.persist((AccountVO)account); } Long accountId = account.getAccountId(); LdapTrustMapVO vo = _ldapTrustMapDao.persist(new LdapTrustMapVO(cmd.getDomainId(), linkType, cmd.getLdapDomain(), cmd.getAccountType(), accountId)); DomainVO domain = domainDao.findById(vo.getDomainId()); String domainUuid = "<unknown>"; if (domain == null) { s_logger.error("no domain in database for id " + vo.getDomainId()); } else { domainUuid = domain.getUuid(); } LinkAccountToLdapResponse response = new LinkAccountToLdapResponse(domainUuid, vo.getType().toString(), vo.getName(), vo.getAccountType(), account.getUuid(), cmd.getAccountName()); return response; } }
Domain domain = null; if (domainId != null) { userAccount = _accountDao.findActiveAccount(accountName, domainId); domain = _domainDao.findById(domainId); } else { userAccount = _accountDao.findActiveAccount(accountName, caller.getDomainId()); domain = _domainDao.findById(caller.getDomainId());
@Override public Pair<List<? extends DedicatedResourceVO>, Integer> listDedicatedZones(ListDedicatedZonesCmd cmd) { Long zoneId = cmd.getZoneId(); Long domainId = cmd.getDomainId(); String accountName = cmd.getAccountName(); Long accountId = null; Long affinityGroupId = cmd.getAffinityGroupId(); Long startIndex = cmd.getStartIndex(); Long pageSize = cmd.getPageSizeVal(); if (accountName != null) { if (domainId != null) { Account account = _accountDao.findActiveAccount(accountName, domainId); if (account != null) { accountId = account.getId(); } } else { throw new InvalidParameterValueException("Please specify the domain id of the account: " + accountName); } } Filter searchFilter = new Filter(DedicatedResourceVO.class, "id", true, startIndex, pageSize); Pair<List<DedicatedResourceVO>, Integer> result = _dedicatedDao.searchDedicatedZones(zoneId, domainId, accountId, affinityGroupId, searchFilter); return new Pair<List<? extends DedicatedResourceVO>, Integer>(result.first(), result.second()); }
@Override public Pair<List<? extends DedicatedResourceVO>, Integer> listDedicatedPods(ListDedicatedPodsCmd cmd) { Long podId = cmd.getPodId(); Long domainId = cmd.getDomainId(); String accountName = cmd.getAccountName(); Long accountId = null; Long affinityGroupId = cmd.getAffinityGroupId(); Long startIndex = cmd.getStartIndex(); Long pageSize = cmd.getPageSizeVal(); if (accountName != null) { if (domainId != null) { Account account = _accountDao.findActiveAccount(accountName, domainId); if (account != null) { accountId = account.getId(); } } else { throw new InvalidParameterValueException("Please specify the domain id of the account: " + accountName); } } Filter searchFilter = new Filter(DedicatedResourceVO.class, "id", true, startIndex, pageSize); Pair<List<DedicatedResourceVO>, Integer> result = _dedicatedDao.searchDedicatedPods(podId, domainId, accountId, affinityGroupId, searchFilter); return new Pair<List<? extends DedicatedResourceVO>, Integer>(result.first(), result.second()); }
@Override public Pair<List<? extends DedicatedResourceVO>, Integer> listDedicatedClusters(ListDedicatedClustersCmd cmd) { Long clusterId = cmd.getClusterId(); Long domainId = cmd.getDomainId(); String accountName = cmd.getAccountName(); Long accountId = null; Long affinityGroupId = cmd.getAffinityGroupId(); Long startIndex = cmd.getStartIndex(); Long pageSize = cmd.getPageSizeVal(); if (accountName != null) { if (domainId != null) { Account account = _accountDao.findActiveAccount(accountName, domainId); if (account != null) { accountId = account.getId(); } } else { throw new InvalidParameterValueException("Please specify the domain id of the account: " + accountName); } } Filter searchFilter = new Filter(DedicatedResourceVO.class, "id", true, startIndex, pageSize); Pair<List<DedicatedResourceVO>, Integer> result = _dedicatedDao.searchDedicatedClusters(clusterId, domainId, accountId, affinityGroupId, searchFilter); return new Pair<List<? extends DedicatedResourceVO>, Integer>(result.first(), result.second()); }
@Override public Pair<List<? extends DedicatedResourceVO>, Integer> listDedicatedHosts(ListDedicatedHostsCmd cmd) { Long hostId = cmd.getHostId(); Long domainId = cmd.getDomainId(); String accountName = cmd.getAccountName(); Long affinityGroupId = cmd.getAffinityGroupId(); Long startIndex = cmd.getStartIndex(); Long pageSize = cmd.getPageSizeVal(); Long accountId = null; if (accountName != null) { if (domainId != null) { Account account = _accountDao.findActiveAccount(accountName, domainId); if (account != null) { accountId = account.getId(); } } else { throw new InvalidParameterValueException("Please specify the domain id of the account: " + accountName); } } Filter searchFilter = new Filter(DedicatedResourceVO.class, "id", true, startIndex, pageSize); Pair<List<DedicatedResourceVO>, Integer> result = _dedicatedDao.searchDedicatedHosts(hostId, domainId, accountId, affinityGroupId, searchFilter); return new Pair<List<? extends DedicatedResourceVO>, Integer>(result.first(), result.second()); }
Account existingAccount = _accountDao.findActiveAccount(newAccountName, domainId); if (existingAccount != null && existingAccount.getId() != account.getId()) { throw new InvalidParameterValueException("The account with the proposed name '" +
if (_accountDao.findActiveAccount(accountName, domainId) != null) { throw new InvalidParameterValueException("The specified account: " + accountName + " already exists");
Account owner = _accountDao.findActiveAccount(accountName, domainId); if (owner == null) { throw new InvalidParameterValueException("Unable to find account " + accountName + " in domain " + domainId);
@Override @ActionEvent(eventType = EventTypes.EVENT_ACCOUNT_DISABLE, eventDescription = "locking account", async = true) public AccountVO lockAccount(String accountName, Long domainId, Long accountId) { Account caller = getCurrentCallingAccount(); Account account = null; if (accountId != null) { account = _accountDao.findById(accountId); } else { account = _accountDao.findActiveAccount(accountName, domainId); } if (account == null || account.getType() == Account.ACCOUNT_TYPE_PROJECT) { throw new InvalidParameterValueException("Unable to find active account by accountId: " + accountId + " OR by name: " + accountName + " in domain " + domainId); } if (account.getId() == Account.ACCOUNT_ID_SYSTEM) { throw new PermissionDeniedException("Account id : " + accountId + " is a system account, lock is not allowed"); } checkAccess(caller, AccessType.OperateEntry, true, account); if (lockAccount(account.getId())) { CallContext.current().putContextParameter(Account.class, account.getUuid()); return _accountDao.findById(account.getId()); } else { throw new CloudRuntimeException("Unable to lock account by accountId: " + accountId + " OR by name: " + accountName + " in domain " + domainId); } }
@Override @ActionEvent(eventType = EventTypes.EVENT_ACCOUNT_DISABLE, eventDescription = "disabling account", async = true) public AccountVO disableAccount(String accountName, Long domainId, Long accountId) throws ConcurrentOperationException, ResourceUnavailableException { Account caller = getCurrentCallingAccount(); Account account = null; if (accountId != null) { account = _accountDao.findById(accountId); } else { account = _accountDao.findActiveAccount(accountName, domainId); } if (account == null || account.getType() == Account.ACCOUNT_TYPE_PROJECT) { throw new InvalidParameterValueException("Unable to find account by accountId: " + accountId + " OR by name: " + accountName + " in domain " + domainId); } if (account.getId() == Account.ACCOUNT_ID_SYSTEM) { throw new PermissionDeniedException("Account id : " + accountId + " is a system account, disable is not allowed"); } checkAccess(caller, AccessType.OperateEntry, true, account); if (disableAccount(account.getId())) { CallContext.current().putContextParameter(Account.class, account.getUuid()); return _accountDao.findById(account.getId()); } else { throw new CloudRuntimeException("Unable to update account by accountId: " + accountId + " OR by name: " + accountName + " in domain " + domainId); } }
@Override @ActionEvent(eventType = EventTypes.EVENT_ACCOUNT_ENABLE, eventDescription = "enabling account", async = true) public AccountVO enableAccount(String accountName, Long domainId, Long accountId) { // Check if account exists Account account = null; if (accountId != null) { account = _accountDao.findById(accountId); } else { account = _accountDao.findActiveAccount(accountName, domainId); } if (account == null || account.getType() == Account.ACCOUNT_TYPE_PROJECT) { throw new InvalidParameterValueException("Unable to find account by accountId: " + accountId + " OR by name: " + accountName + " in domain " + domainId); } if (account.getId() == Account.ACCOUNT_ID_SYSTEM) { throw new PermissionDeniedException("Account id : " + accountId + " is a system account, enable is not allowed"); } // Check if user performing the action is allowed to modify this account Account caller = getCurrentCallingAccount(); checkAccess(caller, AccessType.OperateEntry, true, account); boolean success = enableAccount(account.getId()); if (success) { CallContext.current().putContextParameter(Account.class, account.getUuid()); return _accountDao.findById(account.getId()); } else { throw new CloudRuntimeException("Unable to enable account by accountId: " + accountId + " OR by name: " + accountName + " in domain " + domainId); } }
vlanOwner = _accountDao.findActiveAccount(accountName, domainId); if (vlanOwner == null) { throw new InvalidParameterValueException("Unable to find account by name " + accountName);
throw new InvalidParameterValueException("Account and projectId can't be specified together"); Account account = _accountDao.findActiveAccount(accountName, domainId); if (account == null) { InvalidParameterValueException ex = new InvalidParameterValueException("Unable to find account " + accountName);
throw new InvalidParameterValueException("Account and projectId can't be specified together"); final Account account = _accountDao.findActiveAccount(accountName, domainId); if (account == null) { final InvalidParameterValueException ex = new InvalidParameterValueException("Unable to find account " + accountName + " in specified domain");