/** * If the account is null (domainLevel is true), then returns the domain id passed as a * parameter; otherwise (domainLevel is false) it returns the domain id from the owner account. * * @note: this method fixes a critical bug. More details in JIRA ticket CLOUDSTACK-9432. */ protected Long getDomainIdBasedOnDomainLevel(final Account owner, boolean domainLevel, Long domainId) { Long domainIdBasedOnDomainLevel = owner.getDomainId(); if (domainLevel) { domainIdBasedOnDomainLevel = domainId; } return domainIdBasedOnDomainLevel; }
private void checkIfNotMovingAcrossDomains(long domainId, Account newAccount) { if (newAccount.getDomainId() != domainId) { // not in scope throw new InvalidParameterValueException("moving a user from an account in one domain to an account in annother domain is not supported!"); } }
public Long getDomainId() { if (domainId == null) { return CallContext.current().getCallingAccount().getDomainId(); } return domainId; }
public long getDomainId() { if (domainId != null) { return domainId; } return CallContext.current().getCallingAccount().getDomainId(); }
public Long getDomainId() { if (domainId == null) { return CallContext.current().getCallingAccount().getDomainId(); } return domainId; }
@Override public Domain getDomain() { if (_domain == null) { getAccount(); _domain = s_entityMgr.findById(Domain.class, _account.getDomainId()); } return _domain; }
public Long getDomainId() { if (domainId != null) { return domainId; } else { return CallContext.current().getCallingAccount().getDomainId(); } }
private Long getZoneIdForAccount(Account account) { // Currently just for resource domain admin List<DataCenterVO> dcList = _dcDao.findZonesByDomainId(account.getDomainId()); if (dcList != null && dcList.size() != 0) { return dcList.get(0).getId(); } else { throw new CloudRuntimeException("Failed to find any private zone for Resource domain admin."); } }
@Override public GlobalLoadBalancerRuleVO doInTransaction(TransactionStatus status) { GlobalLoadBalancerRuleVO newGslbRule = new GlobalLoadBalancerRuleVO(name, description, domainName, algorithm, stickyMethod, serviceType, regionId, gslbOwner.getId(), gslbOwner.getDomainId(), GlobalLoadBalancerRule.State.Staged); _gslbRuleDao.persist(newGslbRule); UsageEventUtils.publishUsageEvent(EventTypes.EVENT_GLOBAL_LOAD_BALANCER_CREATE, newGslbRule.getAccountId(), 0, newGslbRule.getId(), name, GlobalLoadBalancerRule.class.getName(), newGslbRule.getUuid()); return newGslbRule; } });
@Override public SecurityGroupVO createDefaultSecurityGroup(Long accountId) { SecurityGroupVO groupVO = _securityGroupDao.findByAccountAndName(accountId, SecurityGroupManager.DEFAULT_GROUP_NAME); if (groupVO == null) { Account accVO = _accountDao.findById(accountId); if (accVO != null) { return createSecurityGroup(SecurityGroupManager.DEFAULT_GROUP_NAME, SecurityGroupManager.DEFAULT_GROUP_DESCRIPTION, accVO.getDomainId(), accVO.getId(), accVO.getAccountName()); } } return groupVO; }
@Override public ListResponse<UserResponse> searchForUsers(ListUsersCmd cmd) throws PermissionDeniedException { Pair<List<UserAccountJoinVO>, Integer> result = searchForUsersInternal(cmd); ListResponse<UserResponse> response = new ListResponse<UserResponse>(); List<UserResponse> userResponses = ViewResponseHelper.createUserResponse(CallContext.current().getCallingAccount().getDomainId(), result.first().toArray(new UserAccountJoinVO[result.first().size()])); response.setResponses(userResponses, result.second()); return response; }
public long getDomainId() { if (publicIpId != null) return _networkService.getIp(getSourceIpAddressId()).getDomainId(); if (domainId != null) { return domainId; } return CallContext.current().getCallingAccount().getDomainId(); }
/** * @param cmd * @param owner * @throws InvalidParameterValueException */ protected void checkForKeyByName(final RegisterSSHKeyPairCmd cmd, final Account owner) throws InvalidParameterValueException { final SSHKeyPairVO existingPair = _sshKeyPairDao.findByName(owner.getAccountId(), owner.getDomainId(), cmd.getName()); if (existingPair != null) { throw new InvalidParameterValueException("A key pair with name '" + cmd.getName() + "' already exists for this account."); } }
/** * @param cmd * @param owner * @throws InvalidParameterValueException */ private void checkForKeyByPublicKey(final RegisterSSHKeyPairCmd cmd, final Account owner) throws InvalidParameterValueException { final SSHKeyPairVO existingPair = _sshKeyPairDao.findByPublicKey(owner.getAccountId(), owner.getDomainId(), getPublicKeyFromKeyKeyMaterial(cmd.getPublicKey())); if (existingPair != null) { throw new InvalidParameterValueException("A key pair with key '" + cmd.getPublicKey() + "' already exists for this account."); } }
@Override public List<NuageVspDomainTemplateResponse> listNuageVspDomainTemplates(ListNuageVspDomainTemplatesCmd cmd){ long domainId; if (cmd.getDomainId() != null) { domainId = cmd.getDomainId(); } else { domainId = CallContext.current().getCallingAccount().getDomainId(); } return listNuageVspDomainTemplates(domainId, cmd.getKeyword(), cmd.getZoneId(), cmd.getPhysicalNetworkId()); }
@Override @ActionEvent(eventType = EventTypes.EVENT_SECURITY_GROUP_CREATE, eventDescription = "creating security group") public SecurityGroupVO createSecurityGroup(CreateSecurityGroupCmd cmd) throws PermissionDeniedException, InvalidParameterValueException { String name = cmd.getSecurityGroupName(); Account caller = CallContext.current().getCallingAccount(); Account owner = _accountMgr.finalizeOwner(caller, cmd.getAccountName(), cmd.getDomainId(), cmd.getProjectId()); if (_securityGroupDao.isNameInUse(owner.getId(), owner.getDomainId(), cmd.getSecurityGroupName())) { throw new InvalidParameterValueException("Unable to create security group, a group with name " + name + " already exists."); } return createSecurityGroup(cmd.getSecurityGroupName(), cmd.getDescription(), owner.getDomainId(), owner.getAccountId(), owner.getAccountName()); }
@Override public boolean canAccessProjectAccount(Account caller, long accountId) { //ROOT admin always can access the project if (_accountMgr.isRootAdmin(caller.getId())) { return true; } else if (_accountMgr.isDomainAdmin(caller.getId())) { Account owner = _accountMgr.getAccount(accountId); _accountMgr.checkAccess(caller, _domainDao.findById(owner.getDomainId())); return true; } return _projectAccountDao.canAccessProjectAccount(caller.getId(), accountId); }
@Override public boolean canModifyProjectAccount(Account caller, long accountId) { //ROOT admin always can access the project if (_accountMgr.isRootAdmin(caller.getId())) { return true; } else if (_accountMgr.isDomainAdmin(caller.getId())) { Account owner = _accountMgr.getAccount(accountId); _accountMgr.checkAccess(caller, _domainDao.findById(owner.getDomainId())); return true; } return _projectAccountDao.canModifyProjectAccount(caller.getId(), accountId); }
private SSHKeyPair createAndSaveSSHKeyPair(final String name, final String fingerprint, final String publicKey, final String privateKey, final Account owner) { final SSHKeyPairVO newPair = new SSHKeyPairVO(); newPair.setAccountId(owner.getAccountId()); newPair.setDomainId(owner.getDomainId()); newPair.setName(name); newPair.setFingerprint(fingerprint); newPair.setPublicKey(publicKey); newPair.setPrivateKey(privateKey); // transient; not saved. _sshKeyPairDao.persist(newPair); return newPair; }
@Override @ActionEvent(eventType = EventTypes.EVENT_USER_MOVE, eventDescription = "moving User to a new account") public boolean moveUser(MoveUserCmd cmd) { final Long id = cmd.getId(); UserVO user = getValidUserVO(id); Account oldAccount = _accountDao.findById(user.getAccountId()); checkAccountAndAccess(user, oldAccount); long domainId = oldAccount.getDomainId(); long newAccountId = getNewAccountId(domainId, cmd.getAccountName(), cmd.getAccountId()); return moveUser(user, newAccountId); }