Search in sources :

Example 16 with LoadBalancerCertMapVO

use of com.cloud.network.dao.LoadBalancerCertMapVO in project cloudstack by apache.

the class LoadBalancingRulesManagerImpl method getLbSslCert.

@Override
public LbSslCert getLbSslCert(long lbRuleId) {
    LoadBalancerCertMapVO lbCertMap = _lbCertMapDao.findByLbRuleId(lbRuleId);
    if (lbCertMap == null)
        return null;
    SslCertVO certVO = _entityMgr.findById(SslCertVO.class, lbCertMap.getCertId());
    if (certVO == null) {
        s_logger.warn("Cert rule with cert ID " + lbCertMap.getCertId() + " but Cert is not found");
        return null;
    }
    return new LbSslCert(certVO.getCertificate(), certVO.getKey(), certVO.getPassword(), certVO.getChain(), certVO.getFingerPrint(), lbCertMap.isRevoke());
}
Also used : LbSslCert(com.cloud.network.lb.LoadBalancingRule.LbSslCert) SslCertVO(com.cloud.network.dao.SslCertVO) LoadBalancerCertMapVO(com.cloud.network.dao.LoadBalancerCertMapVO)

Example 17 with LoadBalancerCertMapVO

use of com.cloud.network.dao.LoadBalancerCertMapVO in project cloudstack by apache.

the class LoadBalancingRulesManagerImpl method removeCertFromLoadBalancer.

@Override
@DB
@ActionEvent(eventType = EventTypes.EVENT_LB_CERT_REMOVE, eventDescription = "removing certificate from load balancer", async = true)
public boolean removeCertFromLoadBalancer(long lbRuleId) {
    CallContext caller = CallContext.current();
    LoadBalancerVO loadBalancer = _lbDao.findById(lbRuleId);
    LoadBalancerCertMapVO lbCertMap = _lbCertMapDao.findByLbRuleId(lbRuleId);
    if (loadBalancer == null) {
        throw new InvalidParameterException("Invalid load balancer value: " + lbRuleId);
    }
    if (lbCertMap == null) {
        throw new InvalidParameterException("No certificate is bound to lb with id: " + lbRuleId);
    }
    _accountMgr.checkAccess(caller.getCallingAccount(), null, true, loadBalancer);
    boolean success = false;
    FirewallRule.State backupState = loadBalancer.getState();
    try {
        loadBalancer.setState(FirewallRule.State.Add);
        _lbDao.persist(loadBalancer);
        lbCertMap.setRevoke(true);
        _lbCertMapDao.persist(lbCertMap);
        if (!applyLoadBalancerConfig(lbRuleId)) {
            s_logger.warn("Failed to remove cert from load balancer rule id " + lbRuleId);
            CloudRuntimeException ex = new CloudRuntimeException("Failed to remove certificate load balancer rule id " + lbRuleId);
            ex.addProxyObject(loadBalancer.getUuid(), "loadBalancerId");
            throw ex;
        }
        success = true;
    } catch (ResourceUnavailableException e) {
        if (isRollBackAllowedForProvider(loadBalancer)) {
            lbCertMap.setRevoke(false);
            _lbCertMapDao.persist(lbCertMap);
            loadBalancer.setState(backupState);
            _lbDao.persist(loadBalancer);
            s_logger.debug("Rolled back certificate removal lb id " + lbRuleId);
        }
        s_logger.warn("Unable to apply the load balancer config because resource is unavaliable.", e);
        if (!success) {
            CloudRuntimeException ex = new CloudRuntimeException("Failed to remove certificate from load balancer rule id " + lbRuleId);
            ex.addProxyObject(loadBalancer.getUuid(), "loadBalancerId");
            throw ex;
        }
    }
    return success;
}
Also used : InvalidParameterException(java.security.InvalidParameterException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) LoadBalancerVO(com.cloud.network.dao.LoadBalancerVO) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) LoadBalancerCertMapVO(com.cloud.network.dao.LoadBalancerCertMapVO) CallContext(org.apache.cloudstack.context.CallContext) FirewallRule(com.cloud.network.rules.FirewallRule) ActionEvent(com.cloud.event.ActionEvent) DB(com.cloud.utils.db.DB)

Example 18 with LoadBalancerCertMapVO

use of com.cloud.network.dao.LoadBalancerCertMapVO 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

LoadBalancerCertMapVO (com.cloud.network.dao.LoadBalancerCertMapVO)18 LoadBalancerVO (com.cloud.network.dao.LoadBalancerVO)12 SslCertVO (com.cloud.network.dao.SslCertVO)10 DB (com.cloud.utils.db.DB)10 ArrayList (java.util.ArrayList)10 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)8 Account (com.cloud.user.Account)8 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)8 ActionEvent (com.cloud.event.ActionEvent)6 FirewallRule (com.cloud.network.rules.FirewallRule)6 InvalidParameterException (java.security.InvalidParameterException)6 CallContext (com.cloud.context.CallContext)4 DomainVO (com.cloud.domain.DomainVO)4 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)4 LoadBalancerVMMapVO (com.cloud.network.dao.LoadBalancerVMMapVO)4 LoadBalancer (com.cloud.network.rules.LoadBalancer)4 Project (com.cloud.projects.Project)4 TransactionStatus (com.cloud.utils.db.TransactionStatus)4 InvalidParameterValueException (com.cloud.utils.exception.InvalidParameterValueException)4 List (java.util.List)4