Package com.cloud.user

Examples of com.cloud.user.User


    public Outcome<VirtualMachine> addVmToNetworkThroughJobQueue(
            final VirtualMachine vm, final Network network, final NicProfile requested) {

        final CallContext context = CallContext.current();
        final User user = context.getCallingUser();
        final Account account = context.getCallingAccount();

        Object[] result = Transaction.execute(new TransactionCallback<Object[]>() {
            @Override
            public Object[] doInTransaction(TransactionStatus status) {

                _vmDao.lockRow(vm.getId(), true);

                List<VmWorkJobVO> pendingWorkJobs = _workJobDao.listPendingWorkJobs(
                        VirtualMachine.Type.Instance, vm.getId(),
                        VmWorkAddVmToNetwork.class.getName());

                VmWorkJobVO workJob = null;
                if (pendingWorkJobs != null && pendingWorkJobs.size() > 0) {
                    assert (pendingWorkJobs.size() == 1);
                    workJob = pendingWorkJobs.get(0);
                } else {

                    workJob = new VmWorkJobVO(context.getContextId());

                    workJob.setDispatcher(VmWorkConstants.VM_WORK_JOB_DISPATCHER);
                    workJob.setCmd(VmWorkAddVmToNetwork.class.getName());

                    workJob.setAccountId(account.getId());
                    workJob.setUserId(user.getId());
                    workJob.setVmType(VirtualMachine.Type.Instance);
                    workJob.setVmInstanceId(vm.getId());
                    workJob.setRelated(AsyncJobExecutionContext.getOriginJobContextId());

                    // save work context info (there are some duplications)
                    VmWorkAddVmToNetwork workInfo = new VmWorkAddVmToNetwork(user.getId(), account.getId(), vm.getId(),
                            VirtualMachineManagerImpl.VM_WORK_JOB_HANDLER, network.getId(), requested);
                    workJob.setCmdInfo(VmWorkSerializer.serialize(workInfo));

                    _jobMgr.submitAsyncJob(workJob, VmWorkConstants.VM_WORK_QUEUE, vm.getId());
                }
View Full Code Here


    public Outcome<VirtualMachine> removeNicFromVmThroughJobQueue(
            final VirtualMachine vm, final Nic nic) {

        final CallContext context = CallContext.current();
        final User user = context.getCallingUser();
        final Account account = context.getCallingAccount();

        Object[] result = Transaction.execute(new TransactionCallback<Object[]>() {
            @Override
            public Object[] doInTransaction(TransactionStatus status) {

                _vmDao.lockRow(vm.getId(), true);

                List<VmWorkJobVO> pendingWorkJobs = _workJobDao.listPendingWorkJobs(
                        VirtualMachine.Type.Instance, vm.getId(),
                        VmWorkRemoveNicFromVm.class.getName());

                VmWorkJobVO workJob = null;
                if (pendingWorkJobs != null && pendingWorkJobs.size() > 0) {
                    assert (pendingWorkJobs.size() == 1);
                    workJob = pendingWorkJobs.get(0);
                } else {

                    workJob = new VmWorkJobVO(context.getContextId());

                    workJob.setDispatcher(VmWorkConstants.VM_WORK_JOB_DISPATCHER);
                    workJob.setCmd(VmWorkRemoveNicFromVm.class.getName());

                    workJob.setAccountId(account.getId());
                    workJob.setUserId(user.getId());
                    workJob.setVmType(VirtualMachine.Type.Instance);
                    workJob.setVmInstanceId(vm.getId());
                    workJob.setRelated(AsyncJobExecutionContext.getOriginJobContextId());

                    // save work context info (there are some duplications)
                    VmWorkRemoveNicFromVm workInfo = new VmWorkRemoveNicFromVm(user.getId(), account.getId(), vm.getId(),
                            VirtualMachineManagerImpl.VM_WORK_JOB_HANDLER, nic.getId());
                    workJob.setCmdInfo(VmWorkSerializer.serialize(workInfo));

                    _jobMgr.submitAsyncJob(workJob, VmWorkConstants.VM_WORK_QUEUE, vm.getId());
                }
View Full Code Here

    public Outcome<VirtualMachine> removeVmFromNetworkThroughJobQueue(
            final VirtualMachine vm, final Network network, final URI broadcastUri) {

        final CallContext context = CallContext.current();
        final User user = context.getCallingUser();
        final Account account = context.getCallingAccount();

        Object[] result = Transaction.execute(new TransactionCallback<Object[]>() {
            @Override
            public Object[] doInTransaction(TransactionStatus status) {

                _vmDao.lockRow(vm.getId(), true);

                List<VmWorkJobVO> pendingWorkJobs = _workJobDao.listPendingWorkJobs(
                        VirtualMachine.Type.Instance, vm.getId(),
                        VmWorkRemoveVmFromNetwork.class.getName());

                VmWorkJobVO workJob = null;
                if (pendingWorkJobs != null && pendingWorkJobs.size() > 0) {
                    assert (pendingWorkJobs.size() == 1);
                    workJob = pendingWorkJobs.get(0);
                } else {

                    workJob = new VmWorkJobVO(context.getContextId());

                    workJob.setDispatcher(VmWorkConstants.VM_WORK_JOB_DISPATCHER);
                    workJob.setCmd(VmWorkRemoveVmFromNetwork.class.getName());

                    workJob.setAccountId(account.getId());
                    workJob.setUserId(user.getId());
                    workJob.setVmType(VirtualMachine.Type.Instance);
                    workJob.setVmInstanceId(vm.getId());
                    workJob.setRelated(AsyncJobExecutionContext.getOriginJobContextId());

                    // save work context info (there are some duplications)
                    VmWorkRemoveVmFromNetwork workInfo = new VmWorkRemoveVmFromNetwork(user.getId(), account.getId(), vm.getId(),
                            VirtualMachineManagerImpl.VM_WORK_JOB_HANDLER, network, broadcastUri);
                    workJob.setCmdInfo(VmWorkSerializer.serialize(workInfo));

                    _jobMgr.submitAsyncJob(workJob, VmWorkConstants.VM_WORK_QUEUE, vm.getId());
                }
View Full Code Here

    public Outcome<VirtualMachine> reconfigureVmThroughJobQueue(
            final String vmUuid, final ServiceOffering newServiceOffering, final boolean reconfiguringOnExistingHost) {

        final CallContext context = CallContext.current();
        final User user = context.getCallingUser();
        final Account account = context.getCallingAccount();

        final VMInstanceVO vm = _vmDao.findByUuid(vmUuid);

        Object[] result = Transaction.execute(new TransactionCallback<Object[]>() {
            @Override
            public Object[] doInTransaction(TransactionStatus status) {

                _vmDao.lockRow(vm.getId(), true);

                List<VmWorkJobVO> pendingWorkJobs = _workJobDao.listPendingWorkJobs(
                        VirtualMachine.Type.Instance, vm.getId(),
                        VmWorkReconfigure.class.getName());

                VmWorkJobVO workJob = null;
                if (pendingWorkJobs != null && pendingWorkJobs.size() > 0) {
                    assert (pendingWorkJobs.size() == 1);
                    workJob = pendingWorkJobs.get(0);
                } else {

                    workJob = new VmWorkJobVO(context.getContextId());

                    workJob.setDispatcher(VmWorkConstants.VM_WORK_JOB_DISPATCHER);
                    workJob.setCmd(VmWorkReconfigure.class.getName());

                    workJob.setAccountId(account.getId());
                    workJob.setUserId(user.getId());
                    workJob.setVmType(VirtualMachine.Type.Instance);
                    workJob.setVmInstanceId(vm.getId());
                    workJob.setRelated(AsyncJobExecutionContext.getOriginJobContextId());

                    // save work context info (there are some duplications)
                    VmWorkReconfigure workInfo = new VmWorkReconfigure(user.getId(), account.getId(), vm.getId(),
                            VirtualMachineManagerImpl.VM_WORK_JOB_HANDLER, newServiceOffering.getId(), reconfiguringOnExistingHost);
                    workJob.setCmdInfo(VmWorkSerializer.serialize(workInfo));

                    _jobMgr.submitAsyncJob(workJob, VmWorkConstants.VM_WORK_QUEUE, vm.getId());
                }
View Full Code Here

    @Inject DataStoreProviderManager providerMgr;

    @Override
    public boolean maintain(DataStore store) {
        Long userId = UserContext.current().getCallerUserId();
        User user = _userDao.findById(userId);
        Account account = UserContext.current().getCaller();
        StoragePoolVO pool = this.primaryDataStoreDao.findById(store.getId());
        try {
            List<StoragePoolVO> spes = null;
            // Handling Zone and Cluster wide storage scopes.
View Full Code Here

    @Override
    public boolean cancelMaintain(DataStore store) {
        // Change the storage state back to up
        Long userId = UserContext.current().getCallerUserId();
        User user = _userDao.findById(userId);
        Account account = UserContext.current().getCaller();
        StoragePoolVO poolVO = this.primaryDataStoreDao
                .findById(store.getId());
        StoragePool pool = (StoragePool)store;
View Full Code Here

        if (registrationToken == null || registrationToken.trim().length() == 0) {
            statusCode = 503;
            responseMessage = "{ \"registration_info\" : { \"errorcode\" : \"503\", \"errortext\" : \"Missing token\" } }";
        } else {
            s_logger.info("Attempting to register user account with token = "+registrationToken);
            User resourceAdminUser = _accountSvc.getActiveUserByRegistrationToken(registrationToken);
            if (resourceAdminUser != null) {
                if(resourceAdminUser.isRegistered()) {
                    statusCode = 503;
                    responseMessage = "{ \"registration_info\" : { \"errorcode\" : \"503\", \"errortext\" : \"Expired token = " + registrationToken + "\" } }";
                } else {
                    if(expires != null && expires.toLowerCase().equals("true")){
                        _accountSvc.markUserRegistered(resourceAdminUser.getId());
                    }

                    Account resourceAdminAccount = _accountSvc.getActiveAccountById(resourceAdminUser.getAccountId());
                    Account rsUserAccount = _accountSvc.getActiveAccountByName(resourceAdminAccount.getAccountName()+"-user", resourceAdminAccount.getDomainId());

                    List<UserVO> users =  _userDao.listByAccount(rsUserAccount.getId());
                    User rsUser = users.get(0);

                    Configuration config = _configDao.findByName("endpointe.url");

                    StringBuffer sb = new StringBuffer();
                    sb.append("{ \"registration_info\" : { \"endpoint_url\" : \""+encodeParam(config.getValue())+"\", ");
                    sb.append("\"domain_id\" : \""+resourceAdminAccount.getDomainId()+"\", ");
                    sb.append("\"admin_account\" : \""+encodeParam(resourceAdminUser.getUsername())+"\", ");
                    sb.append("\"admin_account_api_key\" : \""+resourceAdminUser.getApiKey()+"\", ");
                    sb.append("\"admin_account_secret_key\" : \""+resourceAdminUser.getSecretKey()+"\", ");
                    sb.append("\"user_account\" : \""+encodeParam(rsUser.getUsername())+"\", ");
                    sb.append("\"user_account_api_key\" : \""+rsUser.getApiKey()+"\", ");
                    sb.append("\"user_account_secret_key\" : \""+rsUser.getSecretKey()+"\" ");
                    sb.append("} }");
                    responseMessage = sb.toString();
                }
            } else {
                statusCode = 503;
View Full Code Here

                eventType,
                EventTypes.getEntityForEvent(eventType), null);

        Map<String, String> eventDescription = new HashMap<String, String>();
        Account account = _accountDao.findById(accountId);
        User user = _userDao.findById(userId);
        // if account has been deleted, this might be called during cleanup of resources and results in null pointer
        if (account == null)
            return;
        if (user == null)
            return;
        eventDescription.put("user", user.getUuid());
        eventDescription.put("account", account.getUuid());
        eventDescription.put("event", eventType);
        eventDescription.put("status", state.toString());
        eventDescription.put("entity", entityType);
        eventDescription.put("entityuuid", entityUuid);
View Full Code Here

        return false;
    }

    public boolean verifyUser(Long userId) {
        // copy from ApiServer.java, a bit ugly here
        User user = _accountMgr.getUserIncludingRemoved(userId);
        Account account = null;
        if (user != null) {
            account = _accountMgr.getAccount(user.getAccountId());
        }

        if ((user == null) || (user.getRemoved() != null) || !user.getState().equals(Account.State.enabled)
                || (account == null) || !account.getState().equals(Account.State.enabled)) {
            s_logger.warn("Deleted/Disabled/Locked user with id=" + userId + " attempting to access public API");
            return false;
        }
        return true;
View Full Code Here

                return false; // no signature, bad request
            }

            Transaction txn = Transaction.open(Transaction.CLOUD_DB);
            txn.close();
            User user = null;
            // verify there is a user with this api key
            Pair<User, Account> userAcctPair = _accountMgr.findUserByApiKey(apiKey);
            if (userAcctPair == null) {
                s_logger.debug("apiKey does not map to a valid user -- ignoring request, apiKey: " + apiKey);
                return false;
            }

            user = userAcctPair.first();
            Account account = userAcctPair.second();

            if (!user.getState().equals(Account.State.enabled) || !account.getState().equals(Account.State.enabled)) {
                s_logger.debug("disabled or locked user accessing the api, userid = " + user.getId() + "; name = " + user.getUsername() + "; state: " + user.getState() + "; accountState: " + account.getState());
                return false;
            }

            // verify secret key exists
            secretKey = user.getSecretKey();
            if (secretKey == null) {
                s_logger.debug("User does not have a secret key associated with the account -- ignoring request, username: " + user.getUsername());
                return false;
            }

            unsignedRequest = unsignedRequest.toLowerCase();

            Mac mac = Mac.getInstance("HmacSHA1");
            SecretKeySpec keySpec = new SecretKeySpec(secretKey.getBytes(), "HmacSHA1");
            mac.init(keySpec);
            mac.update(unsignedRequest.getBytes());
            byte[] encryptedBytes = mac.doFinal();
            String computedSignature = Base64.encodeBase64String(encryptedBytes);
            boolean equalSig = signature.equals(computedSignature);
            if (!equalSig) {
                s_logger.debug("User signature: " + signature + " is not equaled to computed signature: " + computedSignature);
            }

            if(equalSig) {
                requestParameters.put("userid", new Object[] {String.valueOf(user.getId())});
                requestParameters.put("account", new Object[] {account.getAccountName()});
                requestParameters.put("accountobj", new Object[] { account });
            }
            return equalSig;
        } catch (Exception ex) {
View Full Code Here

TOP

Related Classes of com.cloud.user.User

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.