Search in sources :

Example 6 with IAMGroupResponse

use of org.apache.cloudstack.api.response.iam.IAMGroupResponse in project cloudstack by apache.

the class IAMApiServiceTest method addRemoveAccountToGroupTest.

@Test
public void addRemoveAccountToGroupTest() {
    IAMGroup group = new IAMGroupVO("group1", "tester group1");
    List<IAMGroup> groups = new ArrayList<IAMGroup>();
    groups.add(group);
    Long groupId = group.getId();
    List<Long> acctIds = new ArrayList<Long>();
    AccountVO acct1 = new AccountVO(100L);
    acct1.setAccountName("account1");
    AccountVO acct2 = new AccountVO(200L);
    acct2.setAccountName("account2");
    acctIds.add(acct1.getId());
    acctIds.add(acct2.getId());
    when(_accountDao.findById(acct1.getId())).thenReturn(acct1);
    when(_accountDao.findById(acct2.getId())).thenReturn(acct2);
    when(_iamSrv.addAccountsToGroup(acctIds, groupId)).thenReturn(group);
    when(_iamSrv.listAccountsByGroup(groupId)).thenReturn(acctIds);
    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"));
}
Also used : IAMGroupVO(org.apache.cloudstack.iam.server.IAMGroupVO) IAMGroup(org.apache.cloudstack.iam.api.IAMGroup) ArrayList(java.util.ArrayList) AccountVO(com.cloud.user.AccountVO) IAMGroupResponse(org.apache.cloudstack.api.response.iam.IAMGroupResponse) List(java.util.List) ArrayList(java.util.ArrayList) Pair(com.cloud.utils.Pair) Test(org.junit.Test)

Example 7 with IAMGroupResponse

use of org.apache.cloudstack.api.response.iam.IAMGroupResponse in project cloudstack by apache.

the class AddAccountToIAMGroupCmd method execute.

@Override
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");
    }
}
Also used : IAMGroup(org.apache.cloudstack.iam.api.IAMGroup) ServerApiException(org.apache.cloudstack.api.ServerApiException) IAMGroupResponse(org.apache.cloudstack.api.response.iam.IAMGroupResponse)

Example 8 with IAMGroupResponse

use of org.apache.cloudstack.api.response.iam.IAMGroupResponse in project cloudstack by apache.

the class AttachIAMPolicyToIAMGroupCmd method execute.

@Override
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");
    }
}
Also used : IAMGroup(org.apache.cloudstack.iam.api.IAMGroup) ServerApiException(org.apache.cloudstack.api.ServerApiException) IAMGroupResponse(org.apache.cloudstack.api.response.iam.IAMGroupResponse)

Example 9 with IAMGroupResponse

use of org.apache.cloudstack.api.response.iam.IAMGroupResponse in project cloudstack by apache.

the class CreateIAMGroupCmd method execute.

@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);
    }
}
Also used : IAMGroup(org.apache.cloudstack.iam.api.IAMGroup) ServerApiException(org.apache.cloudstack.api.ServerApiException) IAMGroupResponse(org.apache.cloudstack.api.response.iam.IAMGroupResponse)

Example 10 with IAMGroupResponse

use of org.apache.cloudstack.api.response.iam.IAMGroupResponse in project cloudstack by apache.

the class RemoveIAMPolicyFromIAMGroupCmd method execute.

@Override
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");
    }
}
Also used : IAMGroup(org.apache.cloudstack.iam.api.IAMGroup) ServerApiException(org.apache.cloudstack.api.ServerApiException) IAMGroupResponse(org.apache.cloudstack.api.response.iam.IAMGroupResponse)

Aggregations

IAMGroupResponse (org.apache.cloudstack.api.response.iam.IAMGroupResponse)10 IAMGroup (org.apache.cloudstack.iam.api.IAMGroup)9 ServerApiException (org.apache.cloudstack.api.ServerApiException)5 ArrayList (java.util.ArrayList)4 List (java.util.List)4 Pair (com.cloud.utils.Pair)3 IAMGroupVO (org.apache.cloudstack.iam.server.IAMGroupVO)3 Test (org.junit.Test)3 AccountVO (com.cloud.user.AccountVO)2 IAMPolicy (org.apache.cloudstack.iam.api.IAMPolicy)2 Domain (com.cloud.domain.Domain)1 DomainVO (com.cloud.domain.DomainVO)1 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)1 Account (com.cloud.user.Account)1 ListResponse (org.apache.cloudstack.api.response.ListResponse)1 IAMPolicyVO (org.apache.cloudstack.iam.server.IAMPolicyVO)1