Search in sources :

Example 51 with Domain

use of com.cloud.legacymodel.domain.Domain in project cosmic by MissionCriticalCloud.

the class AccountManagerImpl method getUserAccount.

private UserAccount getUserAccount(final String username, final String password, final Long domainId, final Map<String, Object[]> requestParameters) {
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("Attempting to log in user: " + username + " in domain " + domainId);
    }
    UserAccount userAccount = _userAccountDao.getUserAccount(username, domainId);
    boolean authenticated = false;
    final HashSet<ActionOnFailedAuthentication> actionsOnFailedAuthenticaion = new HashSet<>();
    final User.Source userSource = userAccount != null ? userAccount.getSource() : User.Source.UNKNOWN;
    for (final UserAuthenticator authenticator : _userAuthenticators) {
        if (userSource != User.Source.UNKNOWN) {
            if (!authenticator.getName().equalsIgnoreCase(userSource.name())) {
                continue;
            }
        }
        final Pair<Boolean, ActionOnFailedAuthentication> result = authenticator.authenticate(username, password, domainId, requestParameters);
        if (result.first()) {
            authenticated = true;
            break;
        } else if (result.second() != null) {
            actionsOnFailedAuthenticaion.add(result.second());
        }
    }
    final boolean updateIncorrectLoginCount = actionsOnFailedAuthenticaion.contains(ActionOnFailedAuthentication.INCREMENT_INCORRECT_LOGIN_ATTEMPT_COUNT);
    if (authenticated) {
        final Domain domain = _domainMgr.getDomain(domainId);
        String domainName = null;
        if (domain != null) {
            domainName = domain.getName();
        }
        userAccount = _userAccountDao.getUserAccount(username, domainId);
        if (!userAccount.getState().equalsIgnoreCase(Account.State.enabled.toString()) || !userAccount.getAccountState().equalsIgnoreCase(Account.State.enabled.toString())) {
            if (s_logger.isInfoEnabled()) {
                s_logger.info("User " + username + " in domain " + domainName + " is disabled/locked (or account is disabled/locked)");
            }
            throw new CloudAuthenticationException("User " + username + " (or their account) in domain " + domainName + " is disabled/locked. Please contact the " + "administrator.");
        }
        // Whenever the user is able to log in successfully, reset the login attempts to zero
        if (!isInternalAccount(userAccount.getId())) {
            updateLoginAttempts(userAccount.getId(), 0, false);
        }
        return userAccount;
    } else {
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("Unable to authenticate user with username " + username + " in domain " + domainId);
        }
        if (userAccount == null) {
            s_logger.warn("Unable to find an user with username " + username + " in domain " + domainId);
            return null;
        }
        if (userAccount.getState().equalsIgnoreCase(Account.State.enabled.toString())) {
            if (!isInternalAccount(userAccount.getId())) {
                // Internal accounts are not disabled
                final int attemptsMade = userAccount.getLoginAttempts() + 1;
                if (updateIncorrectLoginCount) {
                    if (attemptsMade < _allowedLoginAttempts) {
                        updateLoginAttempts(userAccount.getId(), attemptsMade, false);
                        s_logger.warn("Login attempt failed. You have " + (_allowedLoginAttempts - attemptsMade) + " attempt(s) remaining");
                    } else {
                        updateLoginAttempts(userAccount.getId(), _allowedLoginAttempts, true);
                        s_logger.warn("User " + userAccount.getUsername() + " has been disabled due to multiple failed login attempts." + " Please contact admin.");
                    }
                }
            }
        } else {
            s_logger.info("User " + userAccount.getUsername() + " is disabled/locked");
        }
        return null;
    }
}
Also used : User(com.cloud.legacymodel.user.User) CloudAuthenticationException(com.cloud.legacymodel.exceptions.CloudAuthenticationException) UserAuthenticator(com.cloud.server.auth.UserAuthenticator) ActionOnFailedAuthentication(com.cloud.server.auth.UserAuthenticator.ActionOnFailedAuthentication) Domain(com.cloud.legacymodel.domain.Domain) UserAccount(com.cloud.legacymodel.user.UserAccount) HashSet(java.util.HashSet)

Example 52 with Domain

use of com.cloud.legacymodel.domain.Domain in project cosmic by MissionCriticalCloud.

the class QueryManagerImpl method listWhoHasThisIp.

@Override
public ListResponse<WhoHasThisAddressResponse> listWhoHasThisIp(final ListWhoHasThisIpCmd cmd) {
    final ListResponse<WhoHasThisAddressResponse> whoHasThisIpList = new ListResponse<>();
    final List<WhoHasThisAddressResponse> responsesList = new ArrayList<>();
    final String cleanedIpAddress = StringUtils.deleteWhitespace(cmd.getIpAddress());
    final List<IPAddressVO> ipAddresses = _ipAddressDao.listByIpAddress(cleanedIpAddress);
    ipAddresses.forEach(ipAddress -> {
        final WhoHasThisAddressResponse response = new WhoHasThisAddressResponse();
        response.setObjectName("whohasthisip");
        response.setIpAddress(ipAddress.getAddress().toString());
        response.setUuid(ipAddress.getUuid());
        response.setState(ipAddress.getState().toString());
        final Domain domain = _domainDao.findById(ipAddress.getDomainId());
        if (domain != null) {
            response.setDomainName(domain.getName());
            response.setDomainUuid(domain.getUuid());
        }
        final Network network = _networkDao.findById(ipAddress.getNetworkId());
        if (network != null) {
            response.setNetworkUuid(network.getUuid());
            response.setCreated(ipAddress.getAllocatedTime());
            response.setMode(network.getMode());
        }
        if (ipAddress.getVpcId() != null) {
            final Vpc vpc = _vpcDao.findById(ipAddress.getVpcId());
            if (vpc != null) {
                response.setNetworkName(vpc.getName());
                response.setVpcName(vpc.getName());
                response.setVpcUuid(vpc.getUuid());
            }
        } else if (network != null && !StringUtils.isEmpty(network.getName())) {
            response.setNetworkName(network.getName());
        }
        final Network associatedNetwork = _networkDao.findById(ipAddress.getAssociatedWithNetworkId());
        if (associatedNetwork != null) {
            response.setAssociatedNetworkName(associatedNetwork.getName());
            response.setAssociatedNetworkUuid(associatedNetwork.getUuid());
        }
        responsesList.add(response);
    });
    final List<NicVO> nics = _nicDao.listByIpAddress(cleanedIpAddress);
    nics.forEach(nic -> {
        final WhoHasThisAddressResponse response = new WhoHasThisAddressResponse();
        response.setObjectName("whohasthisip");
        queryNicsTableResponse(responsesList, nic, response);
    });
    final List<NicSecondaryIpVO> nicSecondaryIps = _nicSecondaryIpDao.listByIpAddress(cleanedIpAddress);
    nicSecondaryIps.forEach(nicSecondaryIp -> {
        final WhoHasThisAddressResponse response = new WhoHasThisAddressResponse();
        response.setObjectName("whohasthisip");
        response.setIpAddress(nicSecondaryIp.getIp4Address());
        response.setUuid(nicSecondaryIp.getUuid());
        response.setCreated(nicSecondaryIp.getCreated());
        final NicVO nicVO = _nicDao.findById(nicSecondaryIp.getNicId());
        if (nicVO != null) {
            response.setMode(nicVO.getMode());
            response.setBroadcastUri(nicVO.getBroadcastUri());
            response.setNetmask(nicVO.getIPv4Netmask());
            response.setMacAddress(nicVO.getMacAddress());
            response.setState(nicVO.getState().toString());
        }
        final Network network = _networkDao.findById(nicSecondaryIp.getNetworkId());
        if (network != null) {
            response.setNetworkUuid(network.getUuid());
            if (!StringUtils.isEmpty(network.getName())) {
                response.setNetworkName(network.getName());
            }
        }
        final VMInstanceVO vm = _vmInstanceDao.findById(nicSecondaryIp.getVmId());
        getVMInfo(response, nicVO, vm);
        responsesList.add(response);
    });
    final Account account = CallContext.current().getCallingAccount();
    final Domain domain = _domainDao.findById(account.getDomainId());
    final List<WhoHasThisAddressResponse> filteredResponsesList = responsesList.stream().filter(response -> ((account.getDomainId() == Domain.ROOT_DOMAIN || domain.getUuid().equals(response.getDomainUuid())) && (StringUtils.isEmpty(cmd.getUuid()) || (!StringUtils.isEmpty(cmd.getUuid()) && response.getUuid().equals(cmd.getUuid()))))).skip(cmd.getStartIndex()).limit(cmd.getPageSizeVal()).collect(Collectors.toList());
    whoHasThisIpList.setResponses(filteredResponsesList);
    return whoHasThisIpList;
}
Also used : WhoHasThisAddressResponse(com.cloud.api.response.WhoHasThisAddressResponse) ServiceOfferingJoinVO(com.cloud.api.query.vo.ServiceOfferingJoinVO) ListDiskOfferingsCmd(com.cloud.api.command.user.offering.ListDiskOfferingsCmd) StringUtils(org.apache.commons.lang.StringUtils) HostDao(com.cloud.host.dao.HostDao) ListHostsCmd(com.cloud.api.command.admin.host.ListHostsCmd) HostTagVO(com.cloud.api.query.vo.HostTagVO) ListProjectResourcesCriteria(com.cloud.projects.Project.ListProjectResourcesCriteria) DomainManager(com.cloud.user.DomainManager) PermissionDeniedException(com.cloud.legacymodel.exceptions.PermissionDeniedException) Map(java.util.Map) AllocationState(com.cloud.model.enumeration.AllocationState) UserResponse(com.cloud.api.response.UserResponse) ProjectAccountJoinVO(com.cloud.api.query.vo.ProjectAccountJoinVO) ACLType(com.cloud.legacymodel.acl.ControlledEntity.ACLType) ListUsersCmd(com.cloud.api.command.admin.user.ListUsersCmd) ProjectInvitation(com.cloud.projects.ProjectInvitation) ProjectManager(com.cloud.projects.ProjectManager) ResourceTagVO(com.cloud.tags.ResourceTagVO) Project(com.cloud.projects.Project) ServiceOfferingVO(com.cloud.service.ServiceOfferingVO) ListAccountsCmd(com.cloud.api.command.user.account.ListAccountsCmd) ListVMsCmdByAdmin(com.cloud.api.command.admin.vm.ListVMsCmdByAdmin) ProjectInvitationJoinVO(com.cloud.api.query.vo.ProjectInvitationJoinVO) ManagerBase(com.cloud.utils.component.ManagerBase) TemplateState(com.cloud.engine.subsystem.api.storage.TemplateState) VMTemplateDao(com.cloud.storage.dao.VMTemplateDao) QueryService(com.cloud.query.QueryService) DataCenterJoinVO(com.cloud.api.query.vo.DataCenterJoinVO) ListVMGroupsCmd(com.cloud.api.command.user.vmgroup.ListVMGroupsCmd) ResourceMetaDataService(com.cloud.server.ResourceMetaDataService) AffinityGroupVMMapDao(com.cloud.affinity.dao.AffinityGroupVMMapDao) ImageStoreJoinVO(com.cloud.api.query.vo.ImageStoreJoinVO) SearchCriteria(com.cloud.utils.db.SearchCriteria) DomainRouterVO(com.cloud.vm.DomainRouterVO) DomainRouterJoinDao(com.cloud.api.query.dao.DomainRouterJoinDao) ProjectAccountResponse(com.cloud.api.response.ProjectAccountResponse) ListVMsCmd(com.cloud.api.command.user.vm.ListVMsCmd) ResourceTag(com.cloud.server.ResourceTag) ListTemplatesCmdByAdmin(com.cloud.api.command.admin.template.ListTemplatesCmdByAdmin) HostJoinVO(com.cloud.api.query.vo.HostJoinVO) HAWorkerResponse(com.cloud.api.response.HAWorkerResponse) HighAvailabilityManager(com.cloud.ha.HighAvailabilityManager) ListVolumesCmd(com.cloud.api.command.user.volume.ListVolumesCmd) DomainJoinDao(com.cloud.api.query.dao.DomainJoinDao) UserVmDao(com.cloud.vm.dao.UserVmDao) NicDao(com.cloud.vm.dao.NicDao) ProjectResponse(com.cloud.api.response.ProjectResponse) Volume(com.cloud.legacymodel.storage.Volume) Date(java.util.Date) StorageTagVO(com.cloud.api.query.vo.StorageTagVO) UserVmJoinVO(com.cloud.api.query.vo.UserVmJoinVO) StorageTagResponse(com.cloud.api.response.StorageTagResponse) ManagementServerHost(com.cloud.cluster.ManagementServerHost) ResourceObjectType(com.cloud.server.ResourceTag.ResourceObjectType) DiskOfferingResponse(com.cloud.api.response.DiskOfferingResponse) ListTagsCmd(com.cloud.api.command.user.tag.ListTagsCmd) InstanceGroupJoinVO(com.cloud.api.query.vo.InstanceGroupJoinVO) CloudAuthenticationException(com.cloud.legacymodel.exceptions.CloudAuthenticationException) VMInstanceVO(com.cloud.vm.VMInstanceVO) ListResourceDetailsCmd(com.cloud.api.command.user.volume.ListResourceDetailsCmd) NicVO(com.cloud.vm.NicVO) Collectors(java.util.stream.Collectors) HypervisorType(com.cloud.model.enumeration.HypervisorType) DiskOfferingVO(com.cloud.storage.DiskOfferingVO) DomainResponse(com.cloud.api.response.DomainResponse) ListIsosCmdByAdmin(com.cloud.api.command.admin.iso.ListIsosCmdByAdmin) HaWorkVO(com.cloud.ha.HaWorkVO) DedicatedResourceVO(com.cloud.dc.DedicatedResourceVO) HostTagDao(com.cloud.api.query.dao.HostTagDao) ProjectAccountJoinDao(com.cloud.api.query.dao.ProjectAccountJoinDao) AffinityGroupDomainMapDao(com.cloud.affinity.dao.AffinityGroupDomainMapDao) EventJoinDao(com.cloud.event.dao.EventJoinDao) NetworkDetailsDao(com.cloud.network.dao.NetworkDetailsDao) StoragePoolJoinDao(com.cloud.api.query.dao.StoragePoolJoinDao) TemplateType(com.cloud.legacymodel.storage.TemplateType) Inject(javax.inject.Inject) HashSet(java.util.HashSet) VolumeJoinVO(com.cloud.api.query.vo.VolumeJoinVO) ManagementServerHostDao(com.cloud.cluster.dao.ManagementServerHostDao) ListWhoHasThisMacCmd(com.cloud.api.command.admin.cloudops.ListWhoHasThisMacCmd) AsyncJobJoinVO(com.cloud.api.query.vo.AsyncJobJoinVO) AsyncJobJoinDao(com.cloud.api.query.dao.AsyncJobJoinDao) Ternary(com.cloud.legacymodel.utils.Ternary) IPAddressVO(com.cloud.network.dao.IPAddressVO) ListDomainsCmdByAdmin(com.cloud.api.command.admin.domain.ListDomainsCmdByAdmin) ServiceOfferingResponse(com.cloud.api.response.ServiceOfferingResponse) IPAddressDao(com.cloud.network.dao.IPAddressDao) ListWhoHasThisIpCmd(com.cloud.api.command.admin.cloudops.ListWhoHasThisIpCmd) WhoHasThisAddressResponse(com.cloud.api.response.WhoHasThisAddressResponse) VMTemplateVO(com.cloud.storage.VMTemplateVO) StorageTagDao(com.cloud.api.query.dao.StorageTagDao) Logger(org.slf4j.Logger) Pair(com.cloud.legacymodel.utils.Pair) ListIsosCmd(com.cloud.api.command.user.iso.ListIsosCmd) ListAsyncJobsCmd(com.cloud.api.command.user.job.ListAsyncJobsCmd) ListHAWorkersCmd(com.cloud.api.command.admin.cloudops.ListHAWorkersCmd) NicSecondaryIpVO(com.cloud.vm.dao.NicSecondaryIpVO) ListStorageTagsCmd(com.cloud.api.command.admin.storage.ListStorageTagsCmd) ListSecondaryStagingStoresCmd(com.cloud.api.command.admin.storage.ListSecondaryStagingStoresCmd) ConfigKey(com.cloud.framework.config.ConfigKey) UserVmJoinDao(com.cloud.api.query.dao.UserVmJoinDao) InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) ProjectJoinVO(com.cloud.api.query.vo.ProjectJoinVO) AccountResponse(com.cloud.api.response.AccountResponse) BaseListProjectAndAccountResourcesCmd(com.cloud.api.BaseListProjectAndAccountResourcesCmd) DataStore(com.cloud.engine.subsystem.api.storage.DataStore) ListServiceOfferingsCmd(com.cloud.api.command.user.offering.ListServiceOfferingsCmd) ServiceOfferingDao(com.cloud.service.dao.ServiceOfferingDao) ListTemplatesCmd(com.cloud.api.command.user.template.ListTemplatesCmd) Host(com.cloud.legacymodel.dc.Host) DataStoreDriver(com.cloud.engine.subsystem.api.storage.DataStoreDriver) AsyncJobResponse(com.cloud.api.response.AsyncJobResponse) EventJoinVO(com.cloud.api.query.vo.EventJoinVO) State(com.cloud.legacymodel.storage.VirtualMachineTemplate.State) ResourceManager(com.cloud.resource.ResourceManager) ListAffinityGroupsCmd(com.cloud.api.command.user.affinitygroup.ListAffinityGroupsCmd) HostJoinDao(com.cloud.api.query.dao.HostJoinDao) ProjectJoinDao(com.cloud.api.query.dao.ProjectJoinDao) ScopeType(com.cloud.storage.ScopeType) Set(java.util.Set) StoragePoolJoinVO(com.cloud.api.query.vo.StoragePoolJoinVO) ResponseView(com.cloud.api.ResponseObject.ResponseView) DataStoreCapabilities(com.cloud.engine.subsystem.api.storage.DataStoreCapabilities) DomainJoinVO(com.cloud.api.query.vo.DomainJoinVO) ImageStoreJoinDao(com.cloud.api.query.dao.ImageStoreJoinDao) ServiceOfferingJoinDao(com.cloud.api.query.dao.ServiceOfferingJoinDao) AccountDao(com.cloud.user.dao.AccountDao) StoragePoolResponse(com.cloud.api.response.StoragePoolResponse) ZoneResponse(com.cloud.api.response.ZoneResponse) ResourceDetailResponse(com.cloud.api.response.ResourceDetailResponse) ResourceTagResponse(com.cloud.api.response.ResourceTagResponse) VirtualMachine(com.cloud.legacymodel.vm.VirtualMachine) CallContext(com.cloud.context.CallContext) ListEventsCmd(com.cloud.api.command.user.event.ListEventsCmd) ListProjectsCmd(com.cloud.api.command.user.project.ListProjectsCmd) DiskOfferingJoinDao(com.cloud.api.query.dao.DiskOfferingJoinDao) ArrayList(java.util.ArrayList) AffinityGroupJoinDao(com.cloud.api.query.dao.AffinityGroupJoinDao) ConfigurationDao(com.cloud.framework.config.dao.ConfigurationDao) AccountJoinDao(com.cloud.api.query.dao.AccountJoinDao) VolumeJoinDao(com.cloud.api.query.dao.VolumeJoinDao) ResourceDetail(com.cloud.api.ResourceDetail) VMInstanceDao(com.cloud.vm.dao.VMInstanceDao) DomainRouterDao(com.cloud.vm.dao.DomainRouterDao) ImageStoreResponse(com.cloud.api.response.ImageStoreResponse) Op(com.cloud.utils.db.SearchCriteria.Op) AffinityGroupResponse(com.cloud.affinity.AffinityGroupResponse) ProjectDao(com.cloud.projects.dao.ProjectDao) InstanceGroupJoinDao(com.cloud.api.query.dao.InstanceGroupJoinDao) DiskOfferingJoinVO(com.cloud.api.query.vo.DiskOfferingJoinVO) ListZonesCmdByAdmin(com.cloud.api.command.admin.zone.ListZonesCmdByAdmin) ResourceTagDao(com.cloud.tags.dao.ResourceTagDao) ListResponse(com.cloud.api.response.ListResponse) AffinityGroupDomainMapVO(com.cloud.affinity.AffinityGroupDomainMapVO) AffinityGroupJoinVO(com.cloud.api.query.vo.AffinityGroupJoinVO) EventResponse(com.cloud.api.response.EventResponse) ProjectAccountDao(com.cloud.projects.dao.ProjectAccountDao) InstanceGroupResponse(com.cloud.api.response.InstanceGroupResponse) HostTagResponse(com.cloud.api.response.HostTagResponse) AccountManager(com.cloud.user.AccountManager) DataCenterDetailsDao(com.cloud.dc.dao.DataCenterDetailsDao) NicSecondaryIpDao(com.cloud.vm.dao.NicSecondaryIpDao) ListRoutersCmd(com.cloud.api.command.admin.router.ListRoutersCmd) LoggerFactory(org.slf4j.LoggerFactory) ListAccountsCmdByAdmin(com.cloud.api.command.admin.account.ListAccountsCmdByAdmin) Func(com.cloud.utils.db.SearchCriteria.Func) Filter(com.cloud.utils.db.Filter) UserAccountJoinDao(com.cloud.api.query.dao.UserAccountJoinDao) JoinBuilder(com.cloud.utils.db.JoinBuilder) DataStoreRole(com.cloud.model.enumeration.DataStoreRole) DomainDao(com.cloud.domain.dao.DomainDao) ResourceTagJoinDao(com.cloud.api.query.dao.ResourceTagJoinDao) ProjectInvitationResponse(com.cloud.api.response.ProjectInvitationResponse) TemplateResponse(com.cloud.api.response.TemplateResponse) ListStoragePoolsCmd(com.cloud.api.command.admin.storage.ListStoragePoolsCmd) DedicatedResourceDao(com.cloud.dc.dao.DedicatedResourceDao) DataStoreManager(com.cloud.engine.subsystem.api.storage.DataStoreManager) DataCenterJoinDao(com.cloud.api.query.dao.DataCenterJoinDao) DomainRouterResponse(com.cloud.api.response.DomainRouterResponse) List(java.util.List) ImageFormat(com.cloud.model.enumeration.ImageFormat) TaggedResourceService(com.cloud.server.TaggedResourceService) ListProjectInvitationsCmd(com.cloud.api.command.user.project.ListProjectInvitationsCmd) VolumeResponse(com.cloud.api.response.VolumeResponse) ListDomainsCmd(com.cloud.api.command.admin.domain.ListDomainsCmd) SearchBuilder(com.cloud.utils.db.SearchBuilder) UserAccountJoinVO(com.cloud.api.query.vo.UserAccountJoinVO) Configurable(com.cloud.framework.config.Configurable) NetworkDao(com.cloud.network.dao.NetworkDao) Domain(com.cloud.legacymodel.domain.Domain) HostResponse(com.cloud.api.response.HostResponse) TemplateJoinVO(com.cloud.api.query.vo.TemplateJoinVO) UserVmDetailsDao(com.cloud.vm.dao.UserVmDetailsDao) ListZonesCmd(com.cloud.api.command.user.zone.ListZonesCmd) AffinityGroupVMMapVO(com.cloud.affinity.AffinityGroupVMMapVO) ListProjectAccountsCmd(com.cloud.api.command.user.account.ListProjectAccountsCmd) Network(com.cloud.legacymodel.network.Network) ResourceTagJoinVO(com.cloud.api.query.vo.ResourceTagJoinVO) DomainRouterJoinVO(com.cloud.api.query.vo.DomainRouterJoinVO) ListImageStoresCmd(com.cloud.api.command.admin.storage.ListImageStoresCmd) Account(com.cloud.legacymodel.user.Account) UserVmResponse(com.cloud.api.response.UserVmResponse) DateUtil(com.cloud.utils.DateUtil) TemplateJoinDao(com.cloud.api.query.dao.TemplateJoinDao) UserVmVO(com.cloud.vm.UserVmVO) Component(org.springframework.stereotype.Component) ListHostTagsCmd(com.cloud.api.command.admin.host.ListHostTagsCmd) ListVolumesCmdByAdmin(com.cloud.api.command.admin.volume.ListVolumesCmdByAdmin) ProjectInvitationJoinDao(com.cloud.api.query.dao.ProjectInvitationJoinDao) VpcDao(com.cloud.network.vpc.dao.VpcDao) AccountJoinVO(com.cloud.api.query.vo.AccountJoinVO) DomainVO(com.cloud.domain.DomainVO) Vpc(com.cloud.legacymodel.network.vpc.Vpc) HighAvailabilityDao(com.cloud.ha.dao.HighAvailabilityDao) TemplateFilter(com.cloud.legacymodel.storage.VirtualMachineTemplate.TemplateFilter) Account(com.cloud.legacymodel.user.Account) ListResponse(com.cloud.api.response.ListResponse) ArrayList(java.util.ArrayList) Vpc(com.cloud.legacymodel.network.vpc.Vpc) VMInstanceVO(com.cloud.vm.VMInstanceVO) NicSecondaryIpVO(com.cloud.vm.dao.NicSecondaryIpVO) Network(com.cloud.legacymodel.network.Network) IPAddressVO(com.cloud.network.dao.IPAddressVO) Domain(com.cloud.legacymodel.domain.Domain) NicVO(com.cloud.vm.NicVO)

Example 53 with Domain

use of com.cloud.legacymodel.domain.Domain in project cosmic by MissionCriticalCloud.

the class QueryManagerImpl method listWhoHasThisMac.

public ListResponse<WhoHasThisAddressResponse> listWhoHasThisMac(final ListWhoHasThisMacCmd cmd) {
    final ListResponse<WhoHasThisAddressResponse> whoHasThisIpList = new ListResponse<>();
    final List<WhoHasThisAddressResponse> responsesList = new ArrayList<>();
    final String cleanedMacAddress = StringUtils.deleteWhitespace(cmd.getMacAddress());
    final List<NicVO> nics = _nicDao.listByMacAddress(cleanedMacAddress);
    nics.forEach(nic -> {
        final WhoHasThisAddressResponse response = new WhoHasThisAddressResponse();
        response.setObjectName("whohasthismac");
        queryNicsTableResponse(responsesList, nic, response);
    });
    final Account account = CallContext.current().getCallingAccount();
    final Domain domain = _domainDao.findById(account.getDomainId());
    final List<WhoHasThisAddressResponse> filteredResponsesList = responsesList.stream().filter(response -> ((account.getDomainId() == Domain.ROOT_DOMAIN || domain.getUuid().equals(response.getDomainUuid())) && (StringUtils.isEmpty(cmd.getUuid()) || (!StringUtils.isEmpty(cmd.getUuid()) && response.getUuid().equals(cmd.getUuid()))))).skip(cmd.getStartIndex()).limit(cmd.getPageSizeVal()).collect(Collectors.toList());
    whoHasThisIpList.setResponses(filteredResponsesList);
    return whoHasThisIpList;
}
Also used : WhoHasThisAddressResponse(com.cloud.api.response.WhoHasThisAddressResponse) ServiceOfferingJoinVO(com.cloud.api.query.vo.ServiceOfferingJoinVO) ListDiskOfferingsCmd(com.cloud.api.command.user.offering.ListDiskOfferingsCmd) StringUtils(org.apache.commons.lang.StringUtils) HostDao(com.cloud.host.dao.HostDao) ListHostsCmd(com.cloud.api.command.admin.host.ListHostsCmd) HostTagVO(com.cloud.api.query.vo.HostTagVO) ListProjectResourcesCriteria(com.cloud.projects.Project.ListProjectResourcesCriteria) DomainManager(com.cloud.user.DomainManager) PermissionDeniedException(com.cloud.legacymodel.exceptions.PermissionDeniedException) Map(java.util.Map) AllocationState(com.cloud.model.enumeration.AllocationState) UserResponse(com.cloud.api.response.UserResponse) ProjectAccountJoinVO(com.cloud.api.query.vo.ProjectAccountJoinVO) ACLType(com.cloud.legacymodel.acl.ControlledEntity.ACLType) ListUsersCmd(com.cloud.api.command.admin.user.ListUsersCmd) ProjectInvitation(com.cloud.projects.ProjectInvitation) ProjectManager(com.cloud.projects.ProjectManager) ResourceTagVO(com.cloud.tags.ResourceTagVO) Project(com.cloud.projects.Project) ServiceOfferingVO(com.cloud.service.ServiceOfferingVO) ListAccountsCmd(com.cloud.api.command.user.account.ListAccountsCmd) ListVMsCmdByAdmin(com.cloud.api.command.admin.vm.ListVMsCmdByAdmin) ProjectInvitationJoinVO(com.cloud.api.query.vo.ProjectInvitationJoinVO) ManagerBase(com.cloud.utils.component.ManagerBase) TemplateState(com.cloud.engine.subsystem.api.storage.TemplateState) VMTemplateDao(com.cloud.storage.dao.VMTemplateDao) QueryService(com.cloud.query.QueryService) DataCenterJoinVO(com.cloud.api.query.vo.DataCenterJoinVO) ListVMGroupsCmd(com.cloud.api.command.user.vmgroup.ListVMGroupsCmd) ResourceMetaDataService(com.cloud.server.ResourceMetaDataService) AffinityGroupVMMapDao(com.cloud.affinity.dao.AffinityGroupVMMapDao) ImageStoreJoinVO(com.cloud.api.query.vo.ImageStoreJoinVO) SearchCriteria(com.cloud.utils.db.SearchCriteria) DomainRouterVO(com.cloud.vm.DomainRouterVO) DomainRouterJoinDao(com.cloud.api.query.dao.DomainRouterJoinDao) ProjectAccountResponse(com.cloud.api.response.ProjectAccountResponse) ListVMsCmd(com.cloud.api.command.user.vm.ListVMsCmd) ResourceTag(com.cloud.server.ResourceTag) ListTemplatesCmdByAdmin(com.cloud.api.command.admin.template.ListTemplatesCmdByAdmin) HostJoinVO(com.cloud.api.query.vo.HostJoinVO) HAWorkerResponse(com.cloud.api.response.HAWorkerResponse) HighAvailabilityManager(com.cloud.ha.HighAvailabilityManager) ListVolumesCmd(com.cloud.api.command.user.volume.ListVolumesCmd) DomainJoinDao(com.cloud.api.query.dao.DomainJoinDao) UserVmDao(com.cloud.vm.dao.UserVmDao) NicDao(com.cloud.vm.dao.NicDao) ProjectResponse(com.cloud.api.response.ProjectResponse) Volume(com.cloud.legacymodel.storage.Volume) Date(java.util.Date) StorageTagVO(com.cloud.api.query.vo.StorageTagVO) UserVmJoinVO(com.cloud.api.query.vo.UserVmJoinVO) StorageTagResponse(com.cloud.api.response.StorageTagResponse) ManagementServerHost(com.cloud.cluster.ManagementServerHost) ResourceObjectType(com.cloud.server.ResourceTag.ResourceObjectType) DiskOfferingResponse(com.cloud.api.response.DiskOfferingResponse) ListTagsCmd(com.cloud.api.command.user.tag.ListTagsCmd) InstanceGroupJoinVO(com.cloud.api.query.vo.InstanceGroupJoinVO) CloudAuthenticationException(com.cloud.legacymodel.exceptions.CloudAuthenticationException) VMInstanceVO(com.cloud.vm.VMInstanceVO) ListResourceDetailsCmd(com.cloud.api.command.user.volume.ListResourceDetailsCmd) NicVO(com.cloud.vm.NicVO) Collectors(java.util.stream.Collectors) HypervisorType(com.cloud.model.enumeration.HypervisorType) DiskOfferingVO(com.cloud.storage.DiskOfferingVO) DomainResponse(com.cloud.api.response.DomainResponse) ListIsosCmdByAdmin(com.cloud.api.command.admin.iso.ListIsosCmdByAdmin) HaWorkVO(com.cloud.ha.HaWorkVO) DedicatedResourceVO(com.cloud.dc.DedicatedResourceVO) HostTagDao(com.cloud.api.query.dao.HostTagDao) ProjectAccountJoinDao(com.cloud.api.query.dao.ProjectAccountJoinDao) AffinityGroupDomainMapDao(com.cloud.affinity.dao.AffinityGroupDomainMapDao) EventJoinDao(com.cloud.event.dao.EventJoinDao) NetworkDetailsDao(com.cloud.network.dao.NetworkDetailsDao) StoragePoolJoinDao(com.cloud.api.query.dao.StoragePoolJoinDao) TemplateType(com.cloud.legacymodel.storage.TemplateType) Inject(javax.inject.Inject) HashSet(java.util.HashSet) VolumeJoinVO(com.cloud.api.query.vo.VolumeJoinVO) ManagementServerHostDao(com.cloud.cluster.dao.ManagementServerHostDao) ListWhoHasThisMacCmd(com.cloud.api.command.admin.cloudops.ListWhoHasThisMacCmd) AsyncJobJoinVO(com.cloud.api.query.vo.AsyncJobJoinVO) AsyncJobJoinDao(com.cloud.api.query.dao.AsyncJobJoinDao) Ternary(com.cloud.legacymodel.utils.Ternary) IPAddressVO(com.cloud.network.dao.IPAddressVO) ListDomainsCmdByAdmin(com.cloud.api.command.admin.domain.ListDomainsCmdByAdmin) ServiceOfferingResponse(com.cloud.api.response.ServiceOfferingResponse) IPAddressDao(com.cloud.network.dao.IPAddressDao) ListWhoHasThisIpCmd(com.cloud.api.command.admin.cloudops.ListWhoHasThisIpCmd) WhoHasThisAddressResponse(com.cloud.api.response.WhoHasThisAddressResponse) VMTemplateVO(com.cloud.storage.VMTemplateVO) StorageTagDao(com.cloud.api.query.dao.StorageTagDao) Logger(org.slf4j.Logger) Pair(com.cloud.legacymodel.utils.Pair) ListIsosCmd(com.cloud.api.command.user.iso.ListIsosCmd) ListAsyncJobsCmd(com.cloud.api.command.user.job.ListAsyncJobsCmd) ListHAWorkersCmd(com.cloud.api.command.admin.cloudops.ListHAWorkersCmd) NicSecondaryIpVO(com.cloud.vm.dao.NicSecondaryIpVO) ListStorageTagsCmd(com.cloud.api.command.admin.storage.ListStorageTagsCmd) ListSecondaryStagingStoresCmd(com.cloud.api.command.admin.storage.ListSecondaryStagingStoresCmd) ConfigKey(com.cloud.framework.config.ConfigKey) UserVmJoinDao(com.cloud.api.query.dao.UserVmJoinDao) InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) ProjectJoinVO(com.cloud.api.query.vo.ProjectJoinVO) AccountResponse(com.cloud.api.response.AccountResponse) BaseListProjectAndAccountResourcesCmd(com.cloud.api.BaseListProjectAndAccountResourcesCmd) DataStore(com.cloud.engine.subsystem.api.storage.DataStore) ListServiceOfferingsCmd(com.cloud.api.command.user.offering.ListServiceOfferingsCmd) ServiceOfferingDao(com.cloud.service.dao.ServiceOfferingDao) ListTemplatesCmd(com.cloud.api.command.user.template.ListTemplatesCmd) Host(com.cloud.legacymodel.dc.Host) DataStoreDriver(com.cloud.engine.subsystem.api.storage.DataStoreDriver) AsyncJobResponse(com.cloud.api.response.AsyncJobResponse) EventJoinVO(com.cloud.api.query.vo.EventJoinVO) State(com.cloud.legacymodel.storage.VirtualMachineTemplate.State) ResourceManager(com.cloud.resource.ResourceManager) ListAffinityGroupsCmd(com.cloud.api.command.user.affinitygroup.ListAffinityGroupsCmd) HostJoinDao(com.cloud.api.query.dao.HostJoinDao) ProjectJoinDao(com.cloud.api.query.dao.ProjectJoinDao) ScopeType(com.cloud.storage.ScopeType) Set(java.util.Set) StoragePoolJoinVO(com.cloud.api.query.vo.StoragePoolJoinVO) ResponseView(com.cloud.api.ResponseObject.ResponseView) DataStoreCapabilities(com.cloud.engine.subsystem.api.storage.DataStoreCapabilities) DomainJoinVO(com.cloud.api.query.vo.DomainJoinVO) ImageStoreJoinDao(com.cloud.api.query.dao.ImageStoreJoinDao) ServiceOfferingJoinDao(com.cloud.api.query.dao.ServiceOfferingJoinDao) AccountDao(com.cloud.user.dao.AccountDao) StoragePoolResponse(com.cloud.api.response.StoragePoolResponse) ZoneResponse(com.cloud.api.response.ZoneResponse) ResourceDetailResponse(com.cloud.api.response.ResourceDetailResponse) ResourceTagResponse(com.cloud.api.response.ResourceTagResponse) VirtualMachine(com.cloud.legacymodel.vm.VirtualMachine) CallContext(com.cloud.context.CallContext) ListEventsCmd(com.cloud.api.command.user.event.ListEventsCmd) ListProjectsCmd(com.cloud.api.command.user.project.ListProjectsCmd) DiskOfferingJoinDao(com.cloud.api.query.dao.DiskOfferingJoinDao) ArrayList(java.util.ArrayList) AffinityGroupJoinDao(com.cloud.api.query.dao.AffinityGroupJoinDao) ConfigurationDao(com.cloud.framework.config.dao.ConfigurationDao) AccountJoinDao(com.cloud.api.query.dao.AccountJoinDao) VolumeJoinDao(com.cloud.api.query.dao.VolumeJoinDao) ResourceDetail(com.cloud.api.ResourceDetail) VMInstanceDao(com.cloud.vm.dao.VMInstanceDao) DomainRouterDao(com.cloud.vm.dao.DomainRouterDao) ImageStoreResponse(com.cloud.api.response.ImageStoreResponse) Op(com.cloud.utils.db.SearchCriteria.Op) AffinityGroupResponse(com.cloud.affinity.AffinityGroupResponse) ProjectDao(com.cloud.projects.dao.ProjectDao) InstanceGroupJoinDao(com.cloud.api.query.dao.InstanceGroupJoinDao) DiskOfferingJoinVO(com.cloud.api.query.vo.DiskOfferingJoinVO) ListZonesCmdByAdmin(com.cloud.api.command.admin.zone.ListZonesCmdByAdmin) ResourceTagDao(com.cloud.tags.dao.ResourceTagDao) ListResponse(com.cloud.api.response.ListResponse) AffinityGroupDomainMapVO(com.cloud.affinity.AffinityGroupDomainMapVO) AffinityGroupJoinVO(com.cloud.api.query.vo.AffinityGroupJoinVO) EventResponse(com.cloud.api.response.EventResponse) ProjectAccountDao(com.cloud.projects.dao.ProjectAccountDao) InstanceGroupResponse(com.cloud.api.response.InstanceGroupResponse) HostTagResponse(com.cloud.api.response.HostTagResponse) AccountManager(com.cloud.user.AccountManager) DataCenterDetailsDao(com.cloud.dc.dao.DataCenterDetailsDao) NicSecondaryIpDao(com.cloud.vm.dao.NicSecondaryIpDao) ListRoutersCmd(com.cloud.api.command.admin.router.ListRoutersCmd) LoggerFactory(org.slf4j.LoggerFactory) ListAccountsCmdByAdmin(com.cloud.api.command.admin.account.ListAccountsCmdByAdmin) Func(com.cloud.utils.db.SearchCriteria.Func) Filter(com.cloud.utils.db.Filter) UserAccountJoinDao(com.cloud.api.query.dao.UserAccountJoinDao) JoinBuilder(com.cloud.utils.db.JoinBuilder) DataStoreRole(com.cloud.model.enumeration.DataStoreRole) DomainDao(com.cloud.domain.dao.DomainDao) ResourceTagJoinDao(com.cloud.api.query.dao.ResourceTagJoinDao) ProjectInvitationResponse(com.cloud.api.response.ProjectInvitationResponse) TemplateResponse(com.cloud.api.response.TemplateResponse) ListStoragePoolsCmd(com.cloud.api.command.admin.storage.ListStoragePoolsCmd) DedicatedResourceDao(com.cloud.dc.dao.DedicatedResourceDao) DataStoreManager(com.cloud.engine.subsystem.api.storage.DataStoreManager) DataCenterJoinDao(com.cloud.api.query.dao.DataCenterJoinDao) DomainRouterResponse(com.cloud.api.response.DomainRouterResponse) List(java.util.List) ImageFormat(com.cloud.model.enumeration.ImageFormat) TaggedResourceService(com.cloud.server.TaggedResourceService) ListProjectInvitationsCmd(com.cloud.api.command.user.project.ListProjectInvitationsCmd) VolumeResponse(com.cloud.api.response.VolumeResponse) ListDomainsCmd(com.cloud.api.command.admin.domain.ListDomainsCmd) SearchBuilder(com.cloud.utils.db.SearchBuilder) UserAccountJoinVO(com.cloud.api.query.vo.UserAccountJoinVO) Configurable(com.cloud.framework.config.Configurable) NetworkDao(com.cloud.network.dao.NetworkDao) Domain(com.cloud.legacymodel.domain.Domain) HostResponse(com.cloud.api.response.HostResponse) TemplateJoinVO(com.cloud.api.query.vo.TemplateJoinVO) UserVmDetailsDao(com.cloud.vm.dao.UserVmDetailsDao) ListZonesCmd(com.cloud.api.command.user.zone.ListZonesCmd) AffinityGroupVMMapVO(com.cloud.affinity.AffinityGroupVMMapVO) ListProjectAccountsCmd(com.cloud.api.command.user.account.ListProjectAccountsCmd) Network(com.cloud.legacymodel.network.Network) ResourceTagJoinVO(com.cloud.api.query.vo.ResourceTagJoinVO) DomainRouterJoinVO(com.cloud.api.query.vo.DomainRouterJoinVO) ListImageStoresCmd(com.cloud.api.command.admin.storage.ListImageStoresCmd) Account(com.cloud.legacymodel.user.Account) UserVmResponse(com.cloud.api.response.UserVmResponse) DateUtil(com.cloud.utils.DateUtil) TemplateJoinDao(com.cloud.api.query.dao.TemplateJoinDao) UserVmVO(com.cloud.vm.UserVmVO) Component(org.springframework.stereotype.Component) ListHostTagsCmd(com.cloud.api.command.admin.host.ListHostTagsCmd) ListVolumesCmdByAdmin(com.cloud.api.command.admin.volume.ListVolumesCmdByAdmin) ProjectInvitationJoinDao(com.cloud.api.query.dao.ProjectInvitationJoinDao) VpcDao(com.cloud.network.vpc.dao.VpcDao) AccountJoinVO(com.cloud.api.query.vo.AccountJoinVO) DomainVO(com.cloud.domain.DomainVO) Vpc(com.cloud.legacymodel.network.vpc.Vpc) HighAvailabilityDao(com.cloud.ha.dao.HighAvailabilityDao) TemplateFilter(com.cloud.legacymodel.storage.VirtualMachineTemplate.TemplateFilter) Account(com.cloud.legacymodel.user.Account) ListResponse(com.cloud.api.response.ListResponse) ArrayList(java.util.ArrayList) Domain(com.cloud.legacymodel.domain.Domain) NicVO(com.cloud.vm.NicVO)

Example 54 with Domain

use of com.cloud.legacymodel.domain.Domain in project cosmic by MissionCriticalCloud.

the class LdapManagerImpl method listLinkDomainToLdap.

@Override
public LinkDomainToLdapResponse listLinkDomainToLdap(final Long domainId) {
    Validate.notNull(domainId, "domainId cannot be null.");
    final LdapTrustMapVO ldapTrustMap = _ldapManager.getDomainLinkedToLdap(domainId);
    final Domain domain = _domainManager.getDomain(domainId);
    final LinkDomainToLdapResponse response;
    if (!_ldapManager.isLdapEnabled()) {
        return new LinkDomainToLdapResponse(domain.getUuid());
    }
    if (ldapTrustMap != null) {
        response = new LinkDomainToLdapResponse(domain.getUuid(), ldapTrustMap.getType().toString(), ldapTrustMap.getName(), ldapTrustMap.getAccountType());
    } else {
        response = new LinkDomainToLdapResponse(domain.getUuid());
    }
    return response;
}
Also used : LinkDomainToLdapResponse(com.cloud.api.response.LinkDomainToLdapResponse) Domain(com.cloud.legacymodel.domain.Domain)

Example 55 with Domain

use of com.cloud.legacymodel.domain.Domain in project cosmic by MissionCriticalCloud.

the class AccountManagerImplTest method deleteUserAccountCleanup.

@Test
public void deleteUserAccountCleanup() {
    final AccountVO account = new AccountVO();
    account.setId(42l);
    final DomainVO domain = new DomainVO();
    Mockito.when(_accountDao.findById(42l)).thenReturn(account);
    Mockito.when(securityChecker.checkAccess(Mockito.any(Account.class), Mockito.any(ControlledEntity.class), Mockito.any(AccessType.class), Mockito.anyString())).thenReturn(true);
    Mockito.when(_accountDao.remove(42l)).thenReturn(true);
    Mockito.when(_configMgr.releaseAccountSpecificVirtualRanges(42l)).thenReturn(true);
    Mockito.when(_userVmDao.listByAccountId(42l)).thenReturn(Arrays.asList(Mockito.mock(UserVmVO.class)));
    Mockito.when(_vmMgr.expunge(Mockito.any(UserVmVO.class), Mockito.anyLong(), Mockito.any(Account.class))).thenReturn(false);
    Mockito.when(_domainMgr.getDomain(Mockito.anyLong())).thenReturn(domain);
    Mockito.when(securityChecker.checkAccess(Mockito.any(Account.class), Mockito.any(Domain.class))).thenReturn(true);
    Assert.assertTrue(accountManager.deleteUserAccount(42));
    // assert that this was NOT a clean delete
    Mockito.verify(_accountDao, Mockito.atLeastOnce()).markForCleanup(Mockito.eq(42l));
}
Also used : DomainVO(com.cloud.domain.DomainVO) UserAccount(com.cloud.legacymodel.user.UserAccount) Account(com.cloud.legacymodel.user.Account) UserVmVO(com.cloud.vm.UserVmVO) ControlledEntity(com.cloud.legacymodel.acl.ControlledEntity) Domain(com.cloud.legacymodel.domain.Domain) AccessType(com.cloud.acl.SecurityChecker.AccessType) Test(org.junit.Test)

Aggregations

Domain (com.cloud.legacymodel.domain.Domain)55 Account (com.cloud.legacymodel.user.Account)37 InvalidParameterValueException (com.cloud.legacymodel.exceptions.InvalidParameterValueException)20 UserAccount (com.cloud.legacymodel.user.UserAccount)19 ArrayList (java.util.ArrayList)16 PermissionDeniedException (com.cloud.legacymodel.exceptions.PermissionDeniedException)11 Project (com.cloud.projects.Project)11 DomainVO (com.cloud.domain.DomainVO)10 Network (com.cloud.legacymodel.network.Network)10 DomainResponse (com.cloud.api.response.DomainResponse)8 Pair (com.cloud.legacymodel.utils.Pair)7 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)7 HostVO (com.cloud.host.HostVO)6 List (java.util.List)6 Filter (com.cloud.utils.db.Filter)5 HashSet (java.util.HashSet)5 Test (org.junit.Test)5 AffinityGroupResponse (com.cloud.affinity.AffinityGroupResponse)4 CloudAuthenticationException (com.cloud.legacymodel.exceptions.CloudAuthenticationException)4 NetworkVO (com.cloud.network.dao.NetworkVO)4