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

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


        IAMPolicy createdPolicy = _aclSrv.createIAMPolicy(caller, "policy1", "tester policy1", null);
        assertNotNull("IAM policy 'policy1' failed to create ", createdPolicy);
        ListResponse<IAMPolicyResponse> policyResp = _aclSrv.listIAMPolicies(null, null, callerDomainId, 0L, 20L);
        assertTrue("No. of response items should be one", policyResp.getCount() == 1);
        IAMPolicyResponse resp = policyResp.getResponses().get(0);
        assertEquals("Error in created group name", "policy1", resp.getName());
    }
View Full Code Here


        policyPerms.add(perm);
        when(_iamSrv.listIAMPolicies(null, "policy1", callerDomainPath, 0L, 20L)).thenReturn(policyList);
        when(_iamSrv.listPolicyPermissions(policyId)).thenReturn(policyPerms);
        ListResponse<IAMPolicyResponse> policyResp = _aclSrv.listIAMPolicies(null, "policy1", callerDomainId, 0L, 20L);
        assertTrue("No. of response items should be one", policyResp.getCount() == 1);
        IAMPolicyResponse resp = policyResp.getResponses().get(0);
        Set<IAMPermissionResponse> permList = resp.getPermissionList();
        assertTrue("Permission list should not be empty", permList != null && permList.size() > 0);
        IAMPermissionResponse permResp = permList.iterator().next();
        assertEquals("There should be one permission for listVirtualMachines", "listVirtualMachines", permResp.getAction());

        //remove permission from policy
        policyPerms.remove(perm);
        _aclSrv.removeIAMPermissionFromIAMPolicy(policyId, VirtualMachine.class.getSimpleName(),
                PermissionScope.RESOURCE, resId, "listVirtualMachines");
        policyResp = _aclSrv.listIAMPolicies(null, "policy1", callerDomainId, 0L, 20L);
        assertTrue("No. of response items should be one", policyResp.getCount() == 1);
        resp = policyResp.getResponses().get(0);
        permList = resp.getPermissionList();
        assertTrue("Permission list should be empty", permList != null && permList.size() == 0);
    }
View Full Code Here

    public void execute() throws ResourceUnavailableException,
            InsufficientCapacityException, ServerApiException {
        CallContext.current().setEventDetails("IAM policy Id: " + getId());
        IAMPolicy result = _iamApiSrv.removeIAMPermissionFromIAMPolicy(id, entityType, PermissionScope.valueOf(scope), getScopeId(), action);
        if (result != null) {
            IAMPolicyResponse response = _iamApiSrv.createIAMPolicyResponse(result);
            response.setResponseName(getCommandName());
            setResponseObject(response);
        } else {
            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to remove permission from iam policy " + getId());
        }
    }
View Full Code Here

    }


    @Override
    public IAMPolicyResponse createIAMPolicyResponse(IAMPolicy policy) {
        IAMPolicyResponse response = new IAMPolicyResponse();
        response.setId(policy.getUuid());
        response.setName(policy.getName());
        response.setDescription(policy.getDescription());
        String domainPath = policy.getPath();
        if (domainPath != null) {
            DomainVO domain = _domainDao.findDomainByPath(domainPath);
            if (domain != null) {
                response.setDomainId(domain.getUuid());
                response.setDomainName(domain.getName());
            }
        }
        long accountId = policy.getAccountId();
        AccountVO owner = _accountDao.findById(accountId);
        if (owner != null) {
            response.setAccountName(owner.getAccountName());
        }
        // find permissions associated with this policy
        List<IAMPolicyPermission> permissions = _iamSrv.listPolicyPermissions(policy.getId());
        if (permissions != null && permissions.size() > 0) {
            for (IAMPolicyPermission permission : permissions) {
                IAMPermissionResponse perm = new IAMPermissionResponse();
                perm.setAction(permission.getAction());
                if (permission.getEntityType() != null) {
                    perm.setEntityType(permission.getEntityType());
                }
                if (permission.getScope() != null) {
                    perm.setScope(PermissionScope.valueOf(permission.getScope()));
                }
                perm.setScopeId(permission.getScopeId());
                perm.setPermission(permission.getPermission());
                response.addPermission(perm);
            }
        }
        response.setObjectName("aclpolicy");
        return response;
    }
View Full Code Here

        Pair<List<IAMPolicy>, Integer> result = _iamSrv.listIAMPolicies(iamPolicyId, iamPolicyName, domainPath, startIndex, pageSize);
        // generate policy response
        ListResponse<IAMPolicyResponse> response = new ListResponse<IAMPolicyResponse>();
        List<IAMPolicyResponse> policyResponses = new ArrayList<IAMPolicyResponse>();
        for (IAMPolicy policy : result.first()) {
            IAMPolicyResponse resp = createIAMPolicyResponse(policy);
            policyResponses.add(resp);
        }
        response.setResponses(policyResponses, result.second());
        return response;
    }
View Full Code Here

        CallContext.current().setEventDetails("IAM policy Id: " + getId());
        // Only explicit ALLOW is supported for this release, no explicit deny
        IAMPolicy result = _iamApiSrv.addIAMPermissionToIAMPolicy(id, entityType, PermissionScope.valueOf(scope),
                getScopeId(), action, Permission.Allow, false, isReadOnly());
        if (result != null) {
            IAMPolicyResponse response = _iamApiSrv.createIAMPolicyResponse(result);
            response.setResponseName(getCommandName());
            setResponseObject(response);
        } else {
            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to grant permission to iam policy "
                    + getId());
        }
View Full Code Here

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

TOP

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

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.