Search in sources :

Example 1 with SslCertResponse

use of org.apache.cloudstack.api.response.SslCertResponse in project cloudstack by apache.

the class UploadSslCertCmd method execute.

/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException {
    try {
        SslCertResponse response = _certService.uploadSslCert(this);
        setResponseObject(response);
        response.setResponseName(getCommandName());
    } catch (Exception e) {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage());
    }
}
Also used : ServerApiException(org.apache.cloudstack.api.ServerApiException) SslCertResponse(org.apache.cloudstack.api.response.SslCertResponse) ServerApiException(org.apache.cloudstack.api.ServerApiException) NetworkRuleConflictException(com.cloud.exception.NetworkRuleConflictException) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) ResourceAllocationException(com.cloud.exception.ResourceAllocationException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException)

Example 2 with SslCertResponse

use of org.apache.cloudstack.api.response.SslCertResponse 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());
        } else {
            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());
    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)

Example 3 with SslCertResponse

use of org.apache.cloudstack.api.response.SslCertResponse in project cloudstack by apache.

the class ListSslCertsCmd method execute.

/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
@Override
public void execute() {
    try {
        List<SslCertResponse> certResponseList = _certService.listSslCerts(this);
        ListResponse<SslCertResponse> response = new ListResponse<SslCertResponse>();
        response.setResponses(certResponseList);
        response.setResponseName(getCommandName());
        this.setResponseObject(response);
    } catch (Exception e) {
        throw new CloudRuntimeException(e);
    }
}
Also used : ListResponse(org.apache.cloudstack.api.response.ListResponse) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) SslCertResponse(org.apache.cloudstack.api.response.SslCertResponse) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Example 4 with SslCertResponse

use of org.apache.cloudstack.api.response.SslCertResponse in project cloudstack by apache.

the class CertServiceImpl method listSslCerts.

@Override
public List<SslCertResponse> listSslCerts(final ListSslCertsCmd listSslCertCmd) {
    Preconditions.checkNotNull(listSslCertCmd);
    final CallContext ctx = CallContext.current();
    final Account caller = ctx.getCallingAccount();
    final Long certId = listSslCertCmd.getCertId();
    final Long accountId = listSslCertCmd.getAccountId();
    final Long lbRuleId = listSslCertCmd.getLbId();
    final Long projectId = listSslCertCmd.getProjectId();
    final List<SslCertResponse> certResponseList = new ArrayList<SslCertResponse>();
    if (certId == null && accountId == null && lbRuleId == null && projectId == null) {
        throw new InvalidParameterValueException("Invalid parameters either certificate ID or Account ID or Loadbalancer ID or Project ID required");
    }
    List<LoadBalancerCertMapVO> certLbMap = null;
    SslCertVO certVO = null;
    if (certId != null) {
        certVO = _sslCertDao.findById(certId);
        if (certVO == null) {
            throw new InvalidParameterValueException("Invalid certificate id: " + certId);
        }
        _accountMgr.checkAccess(caller, SecurityChecker.AccessType.UseEntry, true, certVO);
        certLbMap = _lbCertDao.listByCertId(certId);
        certResponseList.add(createCertResponse(certVO, certLbMap));
        return certResponseList;
    }
    if (lbRuleId != null) {
        final LoadBalancer lb = _entityMgr.findById(LoadBalancerVO.class, lbRuleId);
        if (lb == null) {
            throw new InvalidParameterValueException("Found no loadbalancer with id: " + lbRuleId);
        }
        _accountMgr.checkAccess(caller, SecurityChecker.AccessType.UseEntry, true, lb);
        // get the cert id
        LoadBalancerCertMapVO lbCertMapRule;
        lbCertMapRule = _lbCertDao.findByLbRuleId(lbRuleId);
        if (lbCertMapRule == null) {
            s_logger.debug("No certificate bound to loadbalancer id: " + lbRuleId);
            return certResponseList;
        }
        certVO = _sslCertDao.findById(lbCertMapRule.getCertId());
        certLbMap = _lbCertDao.listByCertId(lbCertMapRule.getCertId());
        certResponseList.add(createCertResponse(certVO, certLbMap));
        return certResponseList;
    }
    if (projectId != null) {
        final Project project = _projectMgr.getProject(projectId);
        if (project == null) {
            throw new InvalidParameterValueException("Found no project with id: " + projectId);
        }
        final List<SslCertVO> projectCertVOList = _sslCertDao.listByAccountId(project.getProjectAccountId());
        if (projectCertVOList == null || projectCertVOList.isEmpty()) {
            return certResponseList;
        }
        _accountMgr.checkAccess(caller, SecurityChecker.AccessType.UseEntry, true, projectCertVOList.get(0));
        for (final SslCertVO cert : projectCertVOList) {
            certLbMap = _lbCertDao.listByCertId(cert.getId());
            certResponseList.add(createCertResponse(cert, certLbMap));
        }
        return certResponseList;
    }
    //reached here look by accountId
    final List<SslCertVO> certVOList = _sslCertDao.listByAccountId(accountId);
    if (certVOList == null || certVOList.isEmpty()) {
        return certResponseList;
    }
    _accountMgr.checkAccess(caller, SecurityChecker.AccessType.UseEntry, true, certVOList.get(0));
    for (final SslCertVO cert : certVOList) {
        certLbMap = _lbCertDao.listByCertId(cert.getId());
        certResponseList.add(createCertResponse(cert, certLbMap));
    }
    return certResponseList;
}
Also used : Account(com.cloud.user.Account) ArrayList(java.util.ArrayList) LoadBalancerCertMapVO(com.cloud.network.dao.LoadBalancerCertMapVO) LoadBalancer(com.cloud.network.rules.LoadBalancer) CallContext(org.apache.cloudstack.context.CallContext) Project(com.cloud.projects.Project) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) SslCertVO(com.cloud.network.dao.SslCertVO) SslCertResponse(org.apache.cloudstack.api.response.SslCertResponse)

Aggregations

SslCertResponse (org.apache.cloudstack.api.response.SslCertResponse)4 LoadBalancerCertMapVO (com.cloud.network.dao.LoadBalancerCertMapVO)2 LoadBalancer (com.cloud.network.rules.LoadBalancer)2 Project (com.cloud.projects.Project)2 Account (com.cloud.user.Account)2 ArrayList (java.util.ArrayList)2 DomainVO (com.cloud.domain.DomainVO)1 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)1 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)1 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)1 NetworkRuleConflictException (com.cloud.exception.NetworkRuleConflictException)1 ResourceAllocationException (com.cloud.exception.ResourceAllocationException)1 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)1 SslCertVO (com.cloud.network.dao.SslCertVO)1 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)1 ServerApiException (org.apache.cloudstack.api.ServerApiException)1 ListResponse (org.apache.cloudstack.api.response.ListResponse)1 CallContext (org.apache.cloudstack.context.CallContext)1