Search in sources :

Example 51 with DomainVO

use of com.cloud.domain.DomainVO in project cloudstack by apache.

the class DomainManagerImplTest method createDomainVoTestValidInformedUuid.

@Test
public void createDomainVoTestValidInformedUuid() {
    DomainVO domainVo = domainManager.createDomainVo("test", 1L, 2L, "NetworkTest", "testUuid");
    Assert.assertEquals("testUuid", domainVo.getUuid());
}
Also used : DomainVO(com.cloud.domain.DomainVO) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 52 with DomainVO

use of com.cloud.domain.DomainVO in project cloudstack by apache.

the class DomainManagerImplTest method createDomainVoTestCreateValidUuidIfWhiteSpace.

@Test
public void createDomainVoTestCreateValidUuidIfWhiteSpace() {
    DomainVO domainVo = domainManager.createDomainVo("test", 1L, 2L, "NetworkTest", "  ");
    Assert.assertTrue(UuidUtils.validateUUID(domainVo.getUuid()));
}
Also used : DomainVO(com.cloud.domain.DomainVO) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 53 with DomainVO

use of com.cloud.domain.DomainVO in project cloudstack by apache.

the class DomainManagerImplTest method validateUniqueDomainNameTestUniqueNameDoesNotThrowException.

@Test
public void validateUniqueDomainNameTestUniqueNameDoesNotThrowException() {
    SearchCriteria scMock = Mockito.mock(SearchCriteria.class);
    ArrayList<DomainVO> listMock = Mockito.mock(ArrayList.class);
    Mockito.doReturn(scMock).when(domainDaoMock).createSearchCriteria();
    Mockito.doReturn(listMock).when(domainDaoMock).search(Mockito.any(SearchCriteria.class), Mockito.any());
    Mockito.doReturn(true).when(listMock).isEmpty();
    domainManager.validateUniqueDomainName("testUnique", 1L);
    Mockito.verify(domainDaoMock).createSearchCriteria();
    Mockito.verify(scMock).addAnd("name", SearchCriteria.Op.EQ, "testUnique");
    Mockito.verify(scMock).addAnd("parent", SearchCriteria.Op.EQ, 1L);
    Mockito.verify(domainDaoMock).search(scMock, null);
    Mockito.verify(listMock).isEmpty();
}
Also used : DomainVO(com.cloud.domain.DomainVO) SearchCriteria(com.cloud.utils.db.SearchCriteria) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 54 with DomainVO

use of com.cloud.domain.DomainVO in project cloudstack by apache.

the class AnnotationManagerImpl method isEntityOwnedByTheUser.

private boolean isEntityOwnedByTheUser(String entityType, String entityUuid, UserVO callingUser) {
    try {
        if (!isCallingUserRole(RoleType.Admin)) {
            EntityType type = EntityType.valueOf(entityType);
            List<EntityType> notAllowedTypes = EntityType.getNotAllowedTypesForNonAdmins(getCallingUserRole());
            if (notAllowedTypes.contains(type)) {
                return false;
            }
            if (isCallingUserRole(RoleType.DomainAdmin)) {
                if (type == EntityType.SERVICE_OFFERING || type == EntityType.DISK_OFFERING) {
                    return true;
                } else if (type == EntityType.DOMAIN) {
                    DomainVO domain = domainDao.findByUuid(entityUuid);
                    AccountVO account = accountDao.findById(callingUser.getAccountId());
                    accountService.checkAccess(account, domain);
                    return true;
                }
            }
            ControlledEntity entity = getEntityFromUuidAndType(entityUuid, type);
            if (entity == null) {
                String errMsg = String.format("Could not find an entity with type: %s and ID: %s", entityType, entityUuid);
                LOGGER.error(errMsg);
                throw new CloudRuntimeException(errMsg);
            }
            if (type == EntityType.NETWORK && entity instanceof NetworkVO && ((NetworkVO) entity).getAclType() == ControlledEntity.ACLType.Domain) {
                NetworkVO network = (NetworkVO) entity;
                DomainVO domain = domainDao.findById(network.getDomainId());
                AccountVO account = accountDao.findById(callingUser.getAccountId());
                accountService.checkAccess(account, domain);
            } else {
                accountService.checkAccess(callingUser, entity);
            }
        }
    } catch (IllegalArgumentException e) {
        LOGGER.error("Could not parse entity type " + entityType, e);
        return false;
    } catch (PermissionDeniedException e) {
        LOGGER.debug(e.getMessage(), e);
        return false;
    }
    return true;
}
Also used : DomainVO(com.cloud.domain.DomainVO) NetworkVO(com.cloud.network.dao.NetworkVO) ControlledEntity(org.apache.cloudstack.acl.ControlledEntity) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) PermissionDeniedException(com.cloud.exception.PermissionDeniedException) AccountVO(com.cloud.user.AccountVO)

Example 55 with DomainVO

use of com.cloud.domain.DomainVO in project cloudstack by apache.

the class CertServiceImpl method createCertResponse.

public SslCertResponse createCertResponse(final SslCertVO cert, final List<LoadBalancerCertMapVO> lbCertMap) {
    Preconditions.checkNotNull(cert);
    final SslCertResponse response = new SslCertResponse();
    final Account account = _accountDao.findByIdIncludingRemoved(cert.getAccountId());
    if (account.getType() == Account.ACCOUNT_TYPE_PROJECT) {
        // find the project
        final Project project = _projectMgr.findByProjectAccountIdIncludingRemoved(account.getId());
        if (project != null) {
            response.setProjectId(project.getUuid());
            response.setProjectName(project.getName());
        }
        response.setAccountName(account.getAccountName());
    } else {
        response.setAccountName(account.getAccountName());
    }
    final DomainVO domain = _domainDao.findByIdIncludingRemoved(cert.getDomainId());
    response.setDomainId(domain.getUuid());
    response.setDomainName(domain.getName());
    response.setObjectName("sslcert");
    response.setId(cert.getUuid());
    response.setCertificate(cert.getCertificate());
    response.setFingerprint(cert.getFingerPrint());
    response.setName(cert.getName());
    if (cert.getChain() != null) {
        response.setCertchain(cert.getChain());
    }
    if (lbCertMap != null && !lbCertMap.isEmpty()) {
        final List<String> lbIds = new ArrayList<String>();
        for (final LoadBalancerCertMapVO mapVO : lbCertMap) {
            final LoadBalancer lb = _entityMgr.findById(LoadBalancerVO.class, mapVO.getLbId());
            if (lb != null) {
                lbIds.add(lb.getUuid());
            }
        }
        response.setLbIds(lbIds);
    }
    return response;
}
Also used : Account(com.cloud.user.Account) Project(com.cloud.projects.Project) DomainVO(com.cloud.domain.DomainVO) ArrayList(java.util.ArrayList) LoadBalancerCertMapVO(com.cloud.network.dao.LoadBalancerCertMapVO) LoadBalancer(com.cloud.network.rules.LoadBalancer) SslCertResponse(org.apache.cloudstack.api.response.SslCertResponse)

Aggregations

DomainVO (com.cloud.domain.DomainVO)196 Account (com.cloud.user.Account)85 AccountVO (com.cloud.user.AccountVO)64 Test (org.junit.Test)56 ArrayList (java.util.ArrayList)53 DomainDao (com.cloud.domain.dao.DomainDao)30 Field (java.lang.reflect.Field)30 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)29 SslCertDao (com.cloud.network.dao.SslCertDao)29 AccountManager (com.cloud.user.AccountManager)29 SslCertVO (com.cloud.network.dao.SslCertVO)27 List (java.util.List)26 PermissionDeniedException (com.cloud.exception.PermissionDeniedException)24 Pair (com.cloud.utils.Pair)24 Domain (com.cloud.domain.Domain)23 Filter (com.cloud.utils.db.Filter)23 File (java.io.File)23 IOException (java.io.IOException)23 FileUtils.readFileToString (org.apache.commons.io.FileUtils.readFileToString)23 InvalidParameterValueException (com.cloud.utils.exception.InvalidParameterValueException)22