Package org.apache.cloudstack.api.response.iam

Examples of org.apache.cloudstack.api.response.iam.IAMGroupResponse


        Pair<List<IAMGroup>, Integer> grpList = new Pair<List<IAMGroup>, Integer>(groups, 1);
        when(_iamSrv.listIAMGroups(null, "group1", callerDomainPath, 0L, 20L)).thenReturn(grpList);
        _aclSrv.attachIAMPoliciesToGroup(policyIds, groupId);
        ListResponse<IAMGroupResponse> grpResp = _aclSrv.listIAMGroups(null, "group1", callerDomainId, 0L, 20L);
        assertTrue("No. of response items should be one", grpResp.getCount() == 1);
        IAMGroupResponse resp = grpResp.getResponses().get(0);
        Set<String> policyNames = resp.getPolicyList();
        assertEquals("There should be 2 policies in the group", 2, policyNames.size());
        assertTrue("policy1 should be assigned to the group", policyNames.contains("policy1"));
        assertTrue("policy2 should be assigned to the group", policyNames.contains("policy2"));
        // remove "policy2" from group1
        policyIds.remove(1);
        policies.remove(policy2);
        when(_iamSrv.removeIAMPoliciesFromGroup(policyIds, groupId)).thenReturn(group);
        _aclSrv.removeIAMPoliciesFromGroup(policyIds, groupId);
        grpResp = _aclSrv.listIAMGroups(null, "group1", callerDomainId, 0L, 20L);
        assertTrue("No. of response items should be one", grpResp.getCount() == 1);
        resp = grpResp.getResponses().get(0);
        policyNames = resp.getPolicyList();
        assertEquals("There should be 1 policy attached to the group", 1, policyNames.size());
        assertFalse("policy2 should not belong to the group anymore", policyNames.contains("policy2"));
    }
View Full Code Here


        IAMGroup createdGrp = _aclSrv.createIAMGroup(caller, "group1", "tester group1");
        assertNotNull("IAM group 'group1' failed to create ", createdGrp);
        ListResponse<IAMGroupResponse> grpResp = _aclSrv.listIAMGroups(null, null, callerDomainId, 0L, 20L);
        assertTrue("No. of response items should be one", grpResp.getCount() == 1);
        IAMGroupResponse resp = grpResp.getResponses().get(0);
        assertEquals("Error in created group name", "group1", resp.getName());
    }
View Full Code Here

        Pair<List<IAMGroup>, Integer> grpList = new Pair<List<IAMGroup>, Integer>(groups, 1);
        when(_iamSrv.listIAMGroups(null, "group1", callerDomainPath, 0L, 20L)).thenReturn(grpList);
        _aclSrv.addAccountsToGroup(acctIds, groupId);
        ListResponse<IAMGroupResponse> grpResp = _aclSrv.listIAMGroups(null, "group1", callerDomainId, 0L, 20L);
        assertTrue("No. of response items should be one", grpResp.getCount() == 1);
        IAMGroupResponse resp = grpResp.getResponses().get(0);
        Set<String> acctNames = resp.getAccountNameList();
        assertEquals("There should be 2 accounts in the group", 2, acctNames.size());
        assertTrue("account1 should be assigned to the group", acctNames.contains("account1"));
        assertTrue("account2 should be assigned to the group", acctNames.contains("account2"));
        // remove "account2" from group1
        acctIds.remove(1);
        List<Long> rmAccts = new ArrayList<Long>();
        rmAccts.add(acct2.getId());
        when(_iamSrv.removeAccountsFromGroup(rmAccts, groupId)).thenReturn(group);
        _aclSrv.removeAccountsFromGroup(acctIds, groupId);
        grpResp = _aclSrv.listIAMGroups(null, "group1", callerDomainId, 0L, 20L);
        assertTrue("No. of response items should be one", grpResp.getCount() == 1);
        resp = grpResp.getResponses().get(0);
        acctNames = resp.getAccountNameList();
        assertEquals("There should be 1 accounts in the group", 1, acctNames.size());
        assertFalse("account2 should not belong to the group anymore", acctNames.contains("account2"));
    }
View Full Code Here

        return response;
    }

    @Override
    public IAMGroupResponse createIAMGroupResponse(IAMGroup group) {
        IAMGroupResponse response = new IAMGroupResponse();
        response.setId(group.getUuid());
        response.setName(group.getName());
        response.setDescription(group.getDescription());
        String domainPath = group.getPath();
        if (domainPath != null) {
            DomainVO domain = _domainDao.findDomainByPath(domainPath);
            if (domain != null) {
                response.setDomainId(domain.getUuid());
                response.setDomainName(domain.getName());
            }
        }
        long accountId = group.getAccountId();
        AccountVO owner = _accountDao.findById(accountId);
        if (owner != null) {
            response.setAccountName(owner.getAccountName());
        }
        // find all the members in this group
        List<Long> members = _iamSrv.listAccountsByGroup(group.getId());
        if (members != null && members.size() > 0) {
            for (Long member : members) {
                AccountVO mem = _accountDao.findById(member);
                if (mem != null) {
                    response.addMemberAccount(mem.getAccountName());
                }
            }
        }

        // find all the policies attached to this group
        List<IAMPolicy> policies = _iamSrv.listIAMPoliciesByGroup(group.getId());
        if (policies != null && policies.size() > 0) {
            for (IAMPolicy policy : policies) {
                response.addPolicy(policy.getName());
            }
        }

        response.setObjectName("aclgroup");
        return response;

    }
View Full Code Here

        Pair<List<IAMGroup>, Integer> result = _iamSrv.listIAMGroups(iamGroupId, iamGroupName, domainPath, startIndex, pageSize);
        // generate group response
        ListResponse<IAMGroupResponse> response = new ListResponse<IAMGroupResponse>();
        List<IAMGroupResponse> groupResponses = new ArrayList<IAMGroupResponse>();
        for (IAMGroup group : result.first()) {
            IAMGroupResponse resp = createIAMGroupResponse(group);
            groupResponses.add(resp);
        }
        response.setResponses(groupResponses, result.second());
        return response;
    }
View Full Code Here

    public void execute() throws ResourceUnavailableException,
            InsufficientCapacityException, ServerApiException {
        CallContext.current().setEventDetails("IAM group Id: " + getId());
        IAMGroup result = _iamApiSrv.addAccountsToGroup(accountIdList, id);
        if (result != null){
            IAMGroupResponse response = _iamApiSrv.createIAMGroupResponse(result);
            response.setResponseName(getCommandName());
            setResponseObject(response);
        } else {
            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add accounts to iam group");
        }
    }
View Full Code Here

    public void execute() throws ResourceUnavailableException,
            InsufficientCapacityException, ServerApiException {
        CallContext.current().setEventDetails("IAM group Id: " + getId());
        IAMGroup result = _iamApiSrv.attachIAMPoliciesToGroup(policyIdList, id);
        if (result != null){
            IAMGroupResponse response = _iamApiSrv.createIAMGroupResponse(result);
            response.setResponseName(getCommandName());
            setResponseObject(response);
        } else {
            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add roles to iam group");
        }
    }
View Full Code Here

    public void execute() throws ResourceUnavailableException,
            InsufficientCapacityException, ServerApiException {
        CallContext.current().setEventDetails("IAM group Id: " + getId());
        IAMGroup result = _iamApiSrv.removeIAMPoliciesFromGroup(policyIdList, id);
        if (result != null){
            IAMGroupResponse response = _iamApiSrv.createIAMGroupResponse(result);
            response.setResponseName(getCommandName());
            setResponseObject(response);
        } else {
            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add roles to iam group");
        }
    }
View Full Code Here

    @Override
    public void execute() {
        IAMGroup grp = _entityMgr.findById(IAMGroup.class, getEntityId());
        if (grp != null) {
            IAMGroupResponse response = _iamApiSrv.createIAMGroupResponse(grp);
            response.setResponseName(getCommandName());
            setResponseObject(response);
        } else {
            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create iam group:" + name);
        }
    }
View Full Code Here

    public void execute() throws ResourceUnavailableException,
            InsufficientCapacityException, ServerApiException {
        CallContext.current().setEventDetails("IAM group Id: " + getId());
        IAMGroup result = _iamApiSrv.removeAccountsFromGroup(accountIdList, id);
        if (result != null){
            IAMGroupResponse response = _iamApiSrv.createIAMGroupResponse(result);
            response.setResponseName(getCommandName());
            setResponseObject(response);
        } else {
            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to remove accounts from iam group");
        }
    }
View Full Code Here

TOP

Related Classes of org.apache.cloudstack.api.response.iam.IAMGroupResponse

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.