Search in sources :

Example 1 with CloudAuthenticationException

use of com.cloud.legacymodel.exceptions.CloudAuthenticationException in project cosmic by MissionCriticalCloud.

the class CallContext method register.

public static CallContext register(final long callingUserId, final long callingAccountId, final String contextId) throws CloudAuthenticationException {
    final Account account = s_entityMgr.findById(Account.class, callingAccountId);
    if (account == null) {
        throw new CloudAuthenticationException("The account is no longer current.").add(Account.class, Long.toString(callingAccountId));
    }
    final User user = s_entityMgr.findById(User.class, callingUserId);
    if (user == null) {
        throw new CloudAuthenticationException("The user is no longer current.").add(User.class, Long.toString(callingUserId));
    }
    return register(user, account, contextId);
}
Also used : Account(com.cloud.legacymodel.user.Account) User(com.cloud.legacymodel.user.User) CloudAuthenticationException(com.cloud.legacymodel.exceptions.CloudAuthenticationException)

Example 2 with CloudAuthenticationException

use of com.cloud.legacymodel.exceptions.CloudAuthenticationException in project cosmic by MissionCriticalCloud.

the class CallContext method register.

public static CallContext register(final long callingUserId, final long callingAccountId) throws CloudAuthenticationException {
    final Account account = s_entityMgr.findById(Account.class, callingAccountId);
    if (account == null) {
        throw new CloudAuthenticationException("The account is no longer current.").add(Account.class, Long.toString(callingAccountId));
    }
    final User user = s_entityMgr.findById(User.class, callingUserId);
    if (user == null) {
        throw new CloudAuthenticationException("The user is no longer current.").add(User.class, Long.toString(callingUserId));
    }
    return register(user, account);
}
Also used : Account(com.cloud.legacymodel.user.Account) User(com.cloud.legacymodel.user.User) CloudAuthenticationException(com.cloud.legacymodel.exceptions.CloudAuthenticationException)

Example 3 with CloudAuthenticationException

use of com.cloud.legacymodel.exceptions.CloudAuthenticationException in project cosmic by MissionCriticalCloud.

the class LogContext method register.

public static LogContext register(final String callingUserUuid, final String callingAccountUuid) {
    final Account account = s_entityMgr.findByUuid(Account.class, callingAccountUuid);
    if (account == null) {
        throw new CloudAuthenticationException("The account is no longer current.").add(Account.class, callingAccountUuid);
    }
    final User user = s_entityMgr.findByUuid(User.class, callingUserUuid);
    if (user == null) {
        throw new CloudAuthenticationException("The user is no longer current.").add(User.class, callingUserUuid);
    }
    return register(user, account);
}
Also used : Account(com.cloud.legacymodel.user.Account) User(com.cloud.legacymodel.user.User) CloudAuthenticationException(com.cloud.legacymodel.exceptions.CloudAuthenticationException)

Example 4 with CloudAuthenticationException

use of com.cloud.legacymodel.exceptions.CloudAuthenticationException in project cosmic by MissionCriticalCloud.

the class QueryManagerImpl method listDataCentersInternal.

private Pair<List<DataCenterJoinVO>, Integer> listDataCentersInternal(final ListZonesCmd cmd) {
    final Account account = CallContext.current().getCallingAccount();
    final Long domainId = cmd.getDomainId();
    final Long id = cmd.getId();
    final String keyword = cmd.getKeyword();
    final String name = cmd.getName();
    final String networkType = cmd.getNetworkType();
    final Map<String, String> resourceTags = cmd.getTags();
    final SearchBuilder<DataCenterJoinVO> sb = _dcJoinDao.createSearchBuilder();
    if (resourceTags != null && !resourceTags.isEmpty()) {
        final SearchBuilder<ResourceTagVO> tagSearch = _resourceTagDao.createSearchBuilder();
        for (int count = 0; count < resourceTags.size(); count++) {
            tagSearch.or().op("key" + String.valueOf(count), tagSearch.entity().getKey(), SearchCriteria.Op.EQ);
            tagSearch.and("value" + String.valueOf(count), tagSearch.entity().getValue(), SearchCriteria.Op.EQ);
            tagSearch.cp();
        }
        tagSearch.and("resourceType", tagSearch.entity().getResourceType(), SearchCriteria.Op.EQ);
        sb.groupBy(sb.entity().getId());
        sb.join("tagSearch", tagSearch, sb.entity().getId(), tagSearch.entity().getResourceId(), JoinBuilder.JoinType.INNER);
    }
    final Filter searchFilter = new Filter(DataCenterJoinVO.class, null, false, cmd.getStartIndex(), cmd.getPageSizeVal());
    final SearchCriteria<DataCenterJoinVO> sc = sb.create();
    if (networkType != null) {
        sc.addAnd("networkType", SearchCriteria.Op.EQ, networkType);
    }
    if (id != null) {
        sc.addAnd("id", SearchCriteria.Op.EQ, id);
    } else if (name != null) {
        sc.addAnd("name", SearchCriteria.Op.EQ, name);
    } else {
        if (keyword != null) {
            final SearchCriteria<DataCenterJoinVO> ssc = _dcJoinDao.createSearchCriteria();
            ssc.addOr("name", SearchCriteria.Op.LIKE, "%" + keyword + "%");
            ssc.addOr("description", SearchCriteria.Op.LIKE, "%" + keyword + "%");
            sc.addAnd("name", SearchCriteria.Op.SC, ssc);
        }
        /*
             * List all resources due to Explicit Dedication except the
             * dedicated resources of other account
             */
        if (domainId != null) {
            // 
            // for domainId != null // right now, we made the decision to
            // only list zones associated // with this domain, private zone
            sc.addAnd("domainId", SearchCriteria.Op.EQ, domainId);
            if (_accountMgr.isNormalUser(account.getId())) {
                // accountId == null (zones dedicated to a domain) or
                // accountId = caller
                final SearchCriteria<DataCenterJoinVO> sdc = _dcJoinDao.createSearchCriteria();
                sdc.addOr("accountId", SearchCriteria.Op.EQ, account.getId());
                sdc.addOr("accountId", SearchCriteria.Op.NULL);
                sc.addAnd("accountId", SearchCriteria.Op.SC, sdc);
            }
        } else if (_accountMgr.isNormalUser(account.getId())) {
            // it was decided to return all zones for the user's domain, and
            // everything above till root
            // list all zones belonging to this domain, and all of its
            // parents
            // check the parent, if not null, add zones for that parent to
            // list
            // find all domain Id up to root domain for this account
            final List<Long> domainIds = new ArrayList<>();
            DomainVO domainRecord = _domainDao.findById(account.getDomainId());
            if (domainRecord == null) {
                s_logger.error("Could not find the domainId for account:" + account.getAccountName());
                throw new CloudAuthenticationException("Could not find the domainId for account:" + account.getAccountName());
            }
            domainIds.add(domainRecord.getId());
            while (domainRecord.getParent() != null) {
                domainRecord = _domainDao.findById(domainRecord.getParent());
                domainIds.add(domainRecord.getId());
            }
            // domainId == null (public zones) or domainId IN [all domain id
            // up to root domain]
            final SearchCriteria<DataCenterJoinVO> sdc = _dcJoinDao.createSearchCriteria();
            sdc.addOr("domainId", SearchCriteria.Op.IN, domainIds.toArray());
            sdc.addOr("domainId", SearchCriteria.Op.NULL);
            sc.addAnd("domainId", SearchCriteria.Op.SC, sdc);
            // remove disabled zones
            sc.addAnd("allocationState", SearchCriteria.Op.NEQ, AllocationState.Disabled);
            // accountId == null (zones dedicated to a domain) or
            // accountId = caller
            final SearchCriteria<DataCenterJoinVO> sdc2 = _dcJoinDao.createSearchCriteria();
            sdc2.addOr("accountId", SearchCriteria.Op.EQ, account.getId());
            sdc2.addOr("accountId", SearchCriteria.Op.NULL);
            sc.addAnd("accountId", SearchCriteria.Op.SC, sdc2);
            // remove Dedicated zones not dedicated to this domainId or
            // subdomainId
            final List<Long> dedicatedZoneIds = removeDedicatedZoneNotSuitabe(domainIds);
            if (!dedicatedZoneIds.isEmpty()) {
                sdc.addAnd("id", SearchCriteria.Op.NIN, dedicatedZoneIds.toArray(new Object[dedicatedZoneIds.size()]));
            }
        } else if (_accountMgr.isDomainAdmin(account.getId()) || account.getType() == Account.ACCOUNT_TYPE_RESOURCE_DOMAIN_ADMIN) {
            // it was decided to return all zones for the domain admin, and
            // everything above till root, as well as zones till the domain
            // leaf
            final List<Long> domainIds = new ArrayList<>();
            DomainVO domainRecord = _domainDao.findById(account.getDomainId());
            if (domainRecord == null) {
                s_logger.error("Could not find the domainId for account:" + account.getAccountName());
                throw new CloudAuthenticationException("Could not find the domainId for account:" + account.getAccountName());
            }
            domainIds.add(domainRecord.getId());
            // find all domain Ids till leaf
            final List<DomainVO> allChildDomains = _domainDao.findAllChildren(domainRecord.getPath(), domainRecord.getId());
            for (final DomainVO domain : allChildDomains) {
                domainIds.add(domain.getId());
            }
            // then find all domain Id up to root domain for this account
            while (domainRecord.getParent() != null) {
                domainRecord = _domainDao.findById(domainRecord.getParent());
                domainIds.add(domainRecord.getId());
            }
            // domainId == null (public zones) or domainId IN [all domain id
            // up to root domain]
            final SearchCriteria<DataCenterJoinVO> sdc = _dcJoinDao.createSearchCriteria();
            sdc.addOr("domainId", SearchCriteria.Op.IN, domainIds.toArray());
            sdc.addOr("domainId", SearchCriteria.Op.NULL);
            sc.addAnd("domainId", SearchCriteria.Op.SC, sdc);
            // remove disabled zones
            sc.addAnd("allocationState", SearchCriteria.Op.NEQ, AllocationState.Disabled);
            // remove Dedicated zones not dedicated to this domainId or
            // subdomainId
            final List<Long> dedicatedZoneIds = removeDedicatedZoneNotSuitabe(domainIds);
            if (!dedicatedZoneIds.isEmpty()) {
                sdc.addAnd("id", SearchCriteria.Op.NIN, dedicatedZoneIds.toArray(new Object[dedicatedZoneIds.size()]));
            }
        }
        // handle available=FALSE option, only return zones with at least
        // one VM running there
        final Boolean available = cmd.isAvailable();
        if (account != null) {
            if (available != null && Boolean.FALSE.equals(available)) {
                // data centers with
                final Set<Long> dcIds = new HashSet<>();
                // at least one VM
                // running
                final List<DomainRouterVO> routers = _routerDao.listBy(account.getId());
                for (final DomainRouterVO router : routers) {
                    dcIds.add(router.getDataCenterId());
                }
                if (dcIds.size() == 0) {
                    return new Pair<>(new ArrayList<>(), 0);
                } else {
                    sc.addAnd("id", SearchCriteria.Op.IN, dcIds.toArray());
                }
            }
        }
    }
    if (resourceTags != null && !resourceTags.isEmpty()) {
        int count = 0;
        sc.setJoinParameters("tagSearch", "resourceType", ResourceObjectType.Zone.toString());
        for (final Map.Entry<String, String> entry : resourceTags.entrySet()) {
            sc.setJoinParameters("tagSearch", "key" + String.valueOf(count), entry.getKey());
            sc.setJoinParameters("tagSearch", "value" + String.valueOf(count), entry.getValue());
            count++;
        }
    }
    return _dcJoinDao.searchAndCount(sc, searchFilter);
}
Also used : DataCenterJoinVO(com.cloud.api.query.vo.DataCenterJoinVO) Account(com.cloud.legacymodel.user.Account) HashSet(java.util.HashSet) Set(java.util.Set) CloudAuthenticationException(com.cloud.legacymodel.exceptions.CloudAuthenticationException) ArrayList(java.util.ArrayList) ResourceTagVO(com.cloud.tags.ResourceTagVO) ArrayList(java.util.ArrayList) List(java.util.List) SearchCriteria(com.cloud.utils.db.SearchCriteria) DomainVO(com.cloud.domain.DomainVO) Filter(com.cloud.utils.db.Filter) TemplateFilter(com.cloud.legacymodel.storage.VirtualMachineTemplate.TemplateFilter) Map(java.util.Map) DomainRouterVO(com.cloud.vm.DomainRouterVO)

Example 5 with CloudAuthenticationException

use of com.cloud.legacymodel.exceptions.CloudAuthenticationException in project cosmic by MissionCriticalCloud.

the class CallContext method register.

public static CallContext register(final String callingUserUuid, final String callingAccountUuid) {
    final Account account = s_entityMgr.findByUuid(Account.class, callingAccountUuid);
    if (account == null) {
        throw new CloudAuthenticationException("The account is no longer current.").add(Account.class, callingAccountUuid);
    }
    final User user = s_entityMgr.findByUuid(User.class, callingUserUuid);
    if (user == null) {
        throw new CloudAuthenticationException("The user is no longer current.").add(User.class, callingUserUuid);
    }
    return register(user, account);
}
Also used : Account(com.cloud.legacymodel.user.Account) User(com.cloud.legacymodel.user.User) CloudAuthenticationException(com.cloud.legacymodel.exceptions.CloudAuthenticationException)

Aggregations

CloudAuthenticationException (com.cloud.legacymodel.exceptions.CloudAuthenticationException)13 Account (com.cloud.legacymodel.user.Account)11 User (com.cloud.legacymodel.user.User)7 DomainVO (com.cloud.domain.DomainVO)5 TemplateFilter (com.cloud.legacymodel.storage.VirtualMachineTemplate.TemplateFilter)3 UserAccount (com.cloud.legacymodel.user.UserAccount)3 Filter (com.cloud.utils.db.Filter)3 Domain (com.cloud.legacymodel.domain.Domain)2 InvalidParameterValueException (com.cloud.legacymodel.exceptions.InvalidParameterValueException)2 PermissionDeniedException (com.cloud.legacymodel.exceptions.PermissionDeniedException)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 List (java.util.List)2 ServerApiException (com.cloud.api.ServerApiException)1 DataCenterJoinVO (com.cloud.api.query.vo.DataCenterJoinVO)1 DiskOfferingJoinVO (com.cloud.api.query.vo.DiskOfferingJoinVO)1 ServiceOfferingJoinVO (com.cloud.api.query.vo.ServiceOfferingJoinVO)1 UserAuthenticator (com.cloud.server.auth.UserAuthenticator)1 ActionOnFailedAuthentication (com.cloud.server.auth.UserAuthenticator.ActionOnFailedAuthentication)1 ServiceOfferingVO (com.cloud.service.ServiceOfferingVO)1