Search in sources :

Example 81 with Account

use of com.cloud.legacymodel.user.Account in project cosmic by MissionCriticalCloud.

the class NetworkServiceImpl method listNics.

@Override
public List<? extends Nic> listNics(final ListNicsCmd cmd) {
    final Account caller = CallContext.current().getCallingAccount();
    final Long nicId = cmd.getNicId();
    final long vmId = cmd.getVmId();
    final Long networkId = cmd.getNetworkId();
    final UserVmVO userVm = _userVmDao.findById(vmId);
    if (userVm == null || !userVm.isDisplayVm() && caller.getType() == Account.ACCOUNT_TYPE_NORMAL) {
        final InvalidParameterValueException ex = new InvalidParameterValueException("Virtual mahine id does not exist");
        ex.addProxyObject(Long.valueOf(vmId).toString(), "vmId");
        throw ex;
    }
    _accountMgr.checkAccess(caller, null, true, userVm);
    return _networkMgr.listVmNics(vmId, nicId, networkId);
}
Also used : Account(com.cloud.legacymodel.user.Account) UserVmVO(com.cloud.vm.UserVmVO) InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException)

Example 82 with Account

use of com.cloud.legacymodel.user.Account in project cosmic by MissionCriticalCloud.

the class NetworkServiceImpl method allocateIP.

@Override
@ActionEvent(eventType = EventTypes.EVENT_NET_IP_ASSIGN, eventDescription = "allocating Ip", create = true)
public IpAddress allocateIP(final Account ipOwner, final long zoneId, final Long networkId, final Boolean displayIp) throws ResourceAllocationException, InsufficientAddressCapacityException, ConcurrentOperationException {
    final Account caller = CallContext.current().getCallingAccount();
    final long callerUserId = CallContext.current().getCallingUserId();
    final DataCenter zone = _entityMgr.findById(DataCenter.class, zoneId);
    if (networkId != null) {
        final Network network = _networksDao.findById(networkId);
        if (network == null) {
            throw new InvalidParameterValueException("Invalid network id is given");
        }
        if (network.getGuestType() == GuestType.Shared) {
            if (zone == null) {
                throw new InvalidParameterValueException("Invalid zone Id is given");
            }
            // if shared network in the advanced zone, then check the caller against the network for 'AccessType.UseNetwork'
            if (zone.getNetworkType() == NetworkType.Advanced) {
                if (isSharedNetworkOfferingWithServices(network.getNetworkOfferingId())) {
                    _accountMgr.checkAccess(caller, AccessType.UseEntry, false, network);
                    if (s_logger.isDebugEnabled()) {
                        s_logger.debug("Associate IP address called by the user " + callerUserId + " account " + ipOwner.getId());
                    }
                    return _ipAddrMgr.allocateIp(ipOwner, false, caller, callerUserId, zone, displayIp);
                } else {
                    throw new InvalidParameterValueException("Associate IP address can only be called on the shared networks in the advanced zone" + " with Firewall/Source Nat/Static Nat/Port Forwarding/Load balancing services enabled");
                }
            }
        }
    } else {
        _accountMgr.checkAccess(caller, null, false, ipOwner);
    }
    return _ipAddrMgr.allocateIp(ipOwner, false, caller, callerUserId, zone, displayIp);
}
Also used : Account(com.cloud.legacymodel.user.Account) DataCenter(com.cloud.legacymodel.dc.DataCenter) InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) Network(com.cloud.legacymodel.network.Network) ActionEvent(com.cloud.event.ActionEvent)

Example 83 with Account

use of com.cloud.legacymodel.user.Account in project cosmic by MissionCriticalCloud.

the class CertServiceImpl method uploadSslCert.

@DB
@Override
@ActionEvent(eventType = EventTypes.EVENT_LB_CERT_UPLOAD, eventDescription = "Uploading a certificate to cloudstack", async = false)
public SslCertResponse uploadSslCert(final UploadSslCertCmd certCmd) {
    try {
        final String cert = certCmd.getCert();
        final String key = certCmd.getKey();
        final String password = certCmd.getPassword();
        final String chain = certCmd.getChain();
        validate(cert, key, password, chain);
        s_logger.debug("Certificate Validation succeeded");
        final String fingerPrint = generateFingerPrint(parseCertificate(cert));
        final CallContext ctx = CallContext.current();
        final Account caller = ctx.getCallingAccount();
        Account owner = null;
        if ((certCmd.getAccountName() != null && certCmd.getDomainId() != null) || certCmd.getProjectId() != null) {
            owner = _accountMgr.finalizeOwner(caller, certCmd.getAccountName(), certCmd.getDomainId(), certCmd.getProjectId());
        } else {
            owner = caller;
        }
        final Long accountId = owner.getId();
        final Long domainId = owner.getDomainId();
        final SslCertVO certVO = new SslCertVO(cert, key, password, chain, accountId, domainId, fingerPrint);
        _sslCertDao.persist(certVO);
        return createCertResponse(certVO, null);
    } catch (final Exception e) {
        throw new CloudRuntimeException("Error parsing certificate data " + e.getMessage());
    }
}
Also used : Account(com.cloud.legacymodel.user.Account) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) SslCertVO(com.cloud.network.dao.SslCertVO) CallContext(com.cloud.context.CallContext) InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) IllegalBlockSizeException(javax.crypto.IllegalBlockSizeException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) InvalidKeyException(java.security.InvalidKeyException) CertificateEncodingException(java.security.cert.CertificateEncodingException) InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException) CertPathBuilderException(java.security.cert.CertPathBuilderException) NoSuchPaddingException(javax.crypto.NoSuchPaddingException) IOException(java.io.IOException) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) BadPaddingException(javax.crypto.BadPaddingException) NoSuchProviderException(java.security.NoSuchProviderException) ActionEvent(com.cloud.event.ActionEvent) DB(com.cloud.utils.db.DB)

Example 84 with Account

use of com.cloud.legacymodel.user.Account in project cosmic by MissionCriticalCloud.

the class CertServiceImpl method deleteSslCert.

@DB
@Override
@ActionEvent(eventType = EventTypes.EVENT_LB_CERT_DELETE, eventDescription = "Deleting a certificate to cloudstack", async = false)
public void deleteSslCert(final DeleteSslCertCmd deleteSslCertCmd) {
    final CallContext ctx = CallContext.current();
    final Account caller = ctx.getCallingAccount();
    final Long certId = deleteSslCertCmd.getId();
    final SslCertVO certVO = _sslCertDao.findById(certId);
    if (certVO == null) {
        throw new InvalidParameterValueException("Invalid certificate id: " + certId);
    }
    _accountMgr.checkAccess(caller, SecurityChecker.AccessType.OperateEntry, true, certVO);
    final List<LoadBalancerCertMapVO> lbCertRule = _lbCertDao.listByCertId(certId);
    if ((lbCertRule != null) && (!lbCertRule.isEmpty())) {
        String lbUuids = "";
        for (final LoadBalancerCertMapVO rule : lbCertRule) {
            final LoadBalancerVO lb = _entityMgr.findById(LoadBalancerVO.class, rule.getLbId());
            lbUuids += " " + lb.getUuid();
        }
        throw new CloudRuntimeException("Certificate in use by a loadbalancer(s)" + lbUuids);
    }
    _sslCertDao.remove(certId);
}
Also used : Account(com.cloud.legacymodel.user.Account) InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) SslCertVO(com.cloud.network.dao.SslCertVO) LoadBalancerVO(com.cloud.network.dao.LoadBalancerVO) LoadBalancerCertMapVO(com.cloud.network.dao.LoadBalancerCertMapVO) CallContext(com.cloud.context.CallContext) ActionEvent(com.cloud.event.ActionEvent) DB(com.cloud.utils.db.DB)

Example 85 with Account

use of com.cloud.legacymodel.user.Account in project cosmic by MissionCriticalCloud.

the class IpAddressManagerImpl method assignDedicateIpAddress.

@DB
@Override
public PublicIp assignDedicateIpAddress(final Account owner, final Long guestNtwkId, final Long vpcId, final long dcId, final boolean isSourceNat) throws ConcurrentOperationException, InsufficientAddressCapacityException {
    final long ownerId = owner.getId();
    PublicIp ip = null;
    try {
        ip = Transaction.execute(new TransactionCallbackWithException<PublicIp, InsufficientAddressCapacityException>() {

            @Override
            public PublicIp doInTransaction(final TransactionStatus status) throws InsufficientAddressCapacityException {
                final Account owner = _accountDao.acquireInLockTable(ownerId);
                if (owner == null) {
                    // this ownerId comes from owner or type Account. See the class "AccountVO" and the annotations in that class
                    // to get the table name and field name that is queried to fill this ownerid.
                    final ConcurrentOperationException ex = new ConcurrentOperationException("Unable to lock account");
                    throw ex;
                }
                if (s_logger.isDebugEnabled()) {
                    s_logger.debug("lock account " + ownerId + " is acquired");
                }
                boolean displayIp = true;
                if (guestNtwkId != null) {
                    final Network ntwk = _networksDao.findById(guestNtwkId);
                    displayIp = ntwk.getDisplayNetwork();
                } else if (vpcId != null) {
                    final VpcVO vpc = _vpcDao.findById(vpcId);
                    displayIp = vpc.isDisplay();
                }
                final PublicIp ip = fetchNewPublicIp(dcId, null, null, owner, VlanType.VirtualNetwork, guestNtwkId, isSourceNat, false, null, false, vpcId, displayIp);
                final IPAddressVO publicIp = ip.ip();
                markPublicIpAsAllocated(publicIp);
                _ipAddressDao.update(publicIp.getId(), publicIp);
                return ip;
            }
        });
        return ip;
    } finally {
        if (owner != null) {
            if (s_logger.isDebugEnabled()) {
                s_logger.debug("Releasing lock account " + ownerId);
            }
            _accountDao.releaseFromLockTable(ownerId);
        }
        if (ip == null) {
            s_logger.error("Unable to get source nat ip address for account " + ownerId);
        }
    }
}
Also used : Account(com.cloud.legacymodel.user.Account) VpcVO(com.cloud.network.vpc.VpcVO) PublicIp(com.cloud.network.addr.PublicIp) TransactionCallbackWithException(com.cloud.utils.db.TransactionCallbackWithException) Network(com.cloud.legacymodel.network.Network) TransactionStatus(com.cloud.utils.db.TransactionStatus) IPAddressVO(com.cloud.network.dao.IPAddressVO) ConcurrentOperationException(com.cloud.legacymodel.exceptions.ConcurrentOperationException) DB(com.cloud.utils.db.DB)

Aggregations

Account (com.cloud.legacymodel.user.Account)435 InvalidParameterValueException (com.cloud.legacymodel.exceptions.InvalidParameterValueException)229 ActionEvent (com.cloud.event.ActionEvent)120 ArrayList (java.util.ArrayList)103 CloudRuntimeException (com.cloud.legacymodel.exceptions.CloudRuntimeException)98 PermissionDeniedException (com.cloud.legacymodel.exceptions.PermissionDeniedException)78 User (com.cloud.legacymodel.user.User)73 DB (com.cloud.utils.db.DB)59 List (java.util.List)58 Pair (com.cloud.legacymodel.utils.Pair)53 Network (com.cloud.legacymodel.network.Network)48 CallContext (com.cloud.context.CallContext)47 DomainVO (com.cloud.domain.DomainVO)47 UserAccount (com.cloud.legacymodel.user.UserAccount)47 Filter (com.cloud.utils.db.Filter)47 TransactionStatus (com.cloud.utils.db.TransactionStatus)40 Domain (com.cloud.legacymodel.domain.Domain)39 ResourceUnavailableException (com.cloud.legacymodel.exceptions.ResourceUnavailableException)37 Test (org.junit.Test)36 Ternary (com.cloud.legacymodel.utils.Ternary)34