Search in sources :

Example 6 with DistributionListActionRequest

use of com.zimbra.soap.account.message.DistributionListActionRequest in project zm-mailbox by Zimbra.

the class TestDelegatedDL method distributionListActionManipulateOwnerRight.

/*
     * verify owner right can never be altered directly, all modification on
     * owners must go through addOwners/remvoeOwners/setOwners operations
     */
@Test
public void distributionListActionManipulateOwnerRight() throws Exception {
    String GROUP_NAME = getAddress(genGroupNameLocalPart("group"));
    Group group = createGroupAndAddOwner(GROUP_NAME);
    String right = Group.GroupOwner.GROUP_OWNER_RIGHT.getName();
    Account grantee = provUtil.createAccount(genAcctNameLocalPart("1"), domain);
    SoapTransport transport = authUser(USER_OWNER);
    //
    // grantRights
    //
    DistributionListAction action = new DistributionListAction(Operation.grantRights);
    DistributionListActionRequest req = new DistributionListActionRequest(DistributionListSelector.fromName(GROUP_NAME), action);
    DistributionListRightSpec dlRight = new DistributionListRightSpec(right);
    dlRight.addGrantee(new DistributionListGranteeSelector(com.zimbra.soap.type.GranteeType.usr, DistributionListGranteeBy.name, grantee.getName()));
    action.addRight(dlRight);
    DistributionListActionResponse resp;
    boolean caughtException = false;
    try {
        resp = invokeJaxb(transport, req);
    } catch (ServiceException e) {
        if (ServiceException.INVALID_REQUEST.equals(e.getCode())) {
            caughtException = true;
        }
    }
    assertTrue(caughtException);
    //
    // revokeRights
    //
    action = new DistributionListAction(Operation.revokeRights);
    req = new DistributionListActionRequest(DistributionListSelector.fromName(GROUP_NAME), action);
    dlRight = new DistributionListRightSpec(right);
    dlRight.addGrantee(new DistributionListGranteeSelector(com.zimbra.soap.type.GranteeType.usr, DistributionListGranteeBy.name, grantee.getName()));
    action.addRight(dlRight);
    caughtException = false;
    try {
        resp = invokeJaxb(transport, req);
    } catch (ServiceException e) {
        if (ServiceException.INVALID_REQUEST.equals(e.getCode())) {
            caughtException = true;
        }
    }
    assertTrue(caughtException);
    //
    // setRights
    //
    action = new DistributionListAction(Operation.setRights);
    req = new DistributionListActionRequest(DistributionListSelector.fromName(GROUP_NAME), action);
    dlRight = new DistributionListRightSpec(right);
    dlRight.addGrantee(new DistributionListGranteeSelector(com.zimbra.soap.type.GranteeType.usr, DistributionListGranteeBy.name, grantee.getName()));
    action.addRight(dlRight);
    caughtException = false;
    try {
        resp = invokeJaxb(transport, req);
    } catch (ServiceException e) {
        if (ServiceException.INVALID_REQUEST.equals(e.getCode())) {
            caughtException = true;
        }
    }
    assertTrue(caughtException);
}
Also used : Group(com.zimbra.cs.account.Group) Account(com.zimbra.cs.account.Account) DistributionListGranteeSelector(com.zimbra.soap.account.type.DistributionListGranteeSelector) AccountServiceException(com.zimbra.cs.account.AccountServiceException) ServiceException(com.zimbra.common.service.ServiceException) DistributionListActionResponse(com.zimbra.soap.account.message.DistributionListActionResponse) DistributionListAction(com.zimbra.soap.account.type.DistributionListAction) DistributionListRightSpec(com.zimbra.soap.account.type.DistributionListRightSpec) SoapTransport(com.zimbra.common.soap.SoapTransport) DistributionListActionRequest(com.zimbra.soap.account.message.DistributionListActionRequest) Test(org.junit.Test)

Example 7 with DistributionListActionRequest

use of com.zimbra.soap.account.message.DistributionListActionRequest in project zm-mailbox by Zimbra.

the class TestDelegatedDL method distributionListActionRename.

@Test
public void distributionListActionRename() throws Exception {
    String GROUP_NAME = getAddress(genGroupNameLocalPart("group"));
    // create an owner account
    Account ownerAcct = provUtil.createAccount(genAcctNameLocalPart("owner"), domain);
    Group group = createGroupAndAddOwner(GROUP_NAME, ownerAcct.getName());
    DistributionListAction action = new DistributionListAction(Operation.rename);
    String GROUP_NEW_NAME = getAddress(genGroupNameLocalPart("new-name"));
    action.setNewName(GROUP_NEW_NAME);
    DistributionListActionRequest req = new DistributionListActionRequest(DistributionListSelector.fromName(GROUP_NAME), action);
    DistributionListActionResponse resp;
    SoapTransport transport = authUser(ownerAcct.getName());
    String errorCode = null;
    try {
        // only people with create right and owner right can rename
        resp = invokeJaxb(transport, req);
    } catch (ServiceException e) {
        errorCode = e.getCode();
    }
    assertEquals(ServiceException.PERM_DENIED, errorCode);
    // auth as creator and try again, should still fail
    transport = authUser(USER_CREATOR);
    errorCode = null;
    try {
        resp = invokeJaxb(transport, req);
    } catch (ServiceException e) {
        errorCode = e.getCode();
    }
    assertEquals(ServiceException.PERM_DENIED, errorCode);
    // make the creator an owner
    transport = authUser(ownerAcct.getName());
    addOwner(transport, GROUP_NAME, USER_CREATOR);
    // now try reanme as the creator (also an owner now), should succeed
    transport = authUser(USER_CREATOR);
    resp = invokeJaxb(transport, req);
    group = prov.getGroup(Key.DistributionListBy.name, GROUP_NEW_NAME);
    assertEquals(GROUP_NEW_NAME, group.getName());
    // rename into a different domain
    Domain otherDomain = provUtil.createDomain(genDomainName(domain.getName()));
    String GROUP_NEW_NAME_IN_ANOTHER_DOMAIN = TestUtil.getAddress(genGroupNameLocalPart(), otherDomain.getName());
    action = new DistributionListAction(Operation.rename);
    action.setNewName(GROUP_NEW_NAME_IN_ANOTHER_DOMAIN);
    req = new DistributionListActionRequest(DistributionListSelector.fromName(group.getName()), action);
    transport = authUser(USER_CREATOR);
    errorCode = null;
    try {
        // need create right on the other domain
        resp = invokeJaxb(transport, req);
    } catch (ServiceException e) {
        errorCode = e.getCode();
    }
    assertEquals(ServiceException.PERM_DENIED, errorCode);
    transport = authUser(ownerAcct.getName());
    errorCode = null;
    try {
        // need create right on the other domain
        resp = invokeJaxb(transport, req);
    } catch (ServiceException e) {
        errorCode = e.getCode();
    }
    assertEquals(ServiceException.PERM_DENIED, errorCode);
    // grant create right on the other domain
    prov.grantRight(TargetType.domain.getCode(), TargetBy.name, otherDomain.getName(), GranteeType.GT_USER.getCode(), GranteeBy.name, USER_CREATOR, null, User.R_createDistList.getName(), null);
    // do the rename again, should work now
    transport = authUser(USER_CREATOR);
    resp = invokeJaxb(transport, req);
    group = prov.getGroup(Key.DistributionListBy.name, GROUP_NEW_NAME_IN_ANOTHER_DOMAIN);
    assertEquals(GROUP_NEW_NAME_IN_ANOTHER_DOMAIN, group.getName());
    provUtil.deleteAccount(ownerAcct);
    provUtil.deleteGroup(group);
    provUtil.deleteDomain(otherDomain);
}
Also used : Account(com.zimbra.cs.account.Account) Group(com.zimbra.cs.account.Group) AccountServiceException(com.zimbra.cs.account.AccountServiceException) ServiceException(com.zimbra.common.service.ServiceException) DistributionListActionResponse(com.zimbra.soap.account.message.DistributionListActionResponse) DistributionListAction(com.zimbra.soap.account.type.DistributionListAction) Domain(com.zimbra.cs.account.Domain) SoapTransport(com.zimbra.common.soap.SoapTransport) DistributionListActionRequest(com.zimbra.soap.account.message.DistributionListActionRequest) Test(org.junit.Test)

Example 8 with DistributionListActionRequest

use of com.zimbra.soap.account.message.DistributionListActionRequest in project zm-mailbox by Zimbra.

the class TestDelegatedDL method distributionListActionAddRemoveMembers.

@Test
public void distributionListActionAddRemoveMembers() throws Exception {
    SoapTransport transport = authUser(USER_OWNER);
    // addMembers
    DistributionListAction action = new DistributionListAction(Operation.addMembers);
    DistributionListActionRequest req = new DistributionListActionRequest(DistributionListSelector.fromName(DL_NAME), action);
    Account member1 = provUtil.createAccount(genAcctNameLocalPart("member1"), domain);
    Account member2 = provUtil.createAccount(genAcctNameLocalPart("member2"), domain);
    String MEMBER1 = member1.getName();
    String MEMBER2 = member2.getName();
    action.addMember(MEMBER1);
    action.addMember(MEMBER2);
    DistributionListActionResponse resp = invokeJaxb(transport, req);
    Group group = prov.getGroup(Key.DistributionListBy.name, DL_NAME);
    Set<String> members = group.getAllMembersSet();
    Verify.verifyEquals(Sets.newHashSet(MEMBER1, MEMBER2), members);
    // removeMembers
    action = new DistributionListAction(Operation.removeMembers);
    req = new DistributionListActionRequest(DistributionListSelector.fromName(DL_NAME), action);
    action.addMember(MEMBER1);
    action.addMember(MEMBER2);
    resp = invokeJaxb(transport, req);
    group = prov.getGroup(Key.DistributionListBy.name, DL_NAME);
    members = group.getAllMembersSet();
    assertEquals(0, members.size());
}
Also used : Account(com.zimbra.cs.account.Account) Group(com.zimbra.cs.account.Group) DistributionListActionResponse(com.zimbra.soap.account.message.DistributionListActionResponse) DistributionListAction(com.zimbra.soap.account.type.DistributionListAction) SoapTransport(com.zimbra.common.soap.SoapTransport) DistributionListActionRequest(com.zimbra.soap.account.message.DistributionListActionRequest) Test(org.junit.Test)

Example 9 with DistributionListActionRequest

use of com.zimbra.soap.account.message.DistributionListActionRequest in project zm-mailbox by Zimbra.

the class TestDelegatedDL method distributionListActionAddRemoveOwners.

@Test
public void distributionListActionAddRemoveOwners() throws Exception {
    String GROUP_NAME = getAddress(genGroupNameLocalPart("group"));
    Group group = createGroupAndAddOwner(GROUP_NAME);
    Account owner1 = provUtil.createAccount(genAcctNameLocalPart("1"), domain);
    Account owner2 = provUtil.createAccount(genAcctNameLocalPart("2"), domain);
    SoapTransport transport = authUser(USER_OWNER);
    //
    // addOwners
    //
    DistributionListAction action = new DistributionListAction(Operation.addOwners);
    DistributionListActionRequest req = new DistributionListActionRequest(DistributionListSelector.fromName(GROUP_NAME), action);
    action.addOwner(new DistributionListGranteeSelector(com.zimbra.soap.type.GranteeType.usr, DistributionListGranteeBy.name, USER_OWNER));
    action.addOwner(new DistributionListGranteeSelector(com.zimbra.soap.type.GranteeType.usr, DistributionListGranteeBy.name, owner1.getName()));
    action.addOwner(new DistributionListGranteeSelector(com.zimbra.soap.type.GranteeType.usr, DistributionListGranteeBy.name, owner2.getName()));
    DistributionListActionResponse resp = invokeJaxb(transport, req);
    //
    // verify owners are added
    //
    GetDistributionListRequest getDLReq = new GetDistributionListRequest(DistributionListSelector.fromName(GROUP_NAME), Boolean.TRUE);
    GetDistributionListResponse getDLResp = invokeJaxb(transport, getDLReq);
    DistributionListInfo dlInfo = getDLResp.getDl();
    List<? extends DistributionListGranteeInfoInterface> owners = dlInfo.getOwners();
    Set<String> ownerNames = Sets.newHashSet();
    for (DistributionListGranteeInfoInterface owner : owners) {
        if (owner.getType() == com.zimbra.soap.type.GranteeType.usr) {
            ownerNames.add(owner.getName());
        }
    }
    assertEquals(3, owners.size());
    Verify.verifyEquals(Sets.newHashSet(USER_OWNER, owner1.getName(), owner2.getName()), ownerNames);
    //
    // removeOwners
    //
    action = new DistributionListAction(Operation.removeOwners);
    req = new DistributionListActionRequest(DistributionListSelector.fromName(GROUP_NAME), action);
    action.addOwner(new DistributionListGranteeSelector(com.zimbra.soap.type.GranteeType.usr, DistributionListGranteeBy.name, owner1.getName()));
    action.addOwner(new DistributionListGranteeSelector(com.zimbra.soap.type.GranteeType.usr, DistributionListGranteeBy.name, owner2.getName()));
    resp = invokeJaxb(transport, req);
    //
    // verify owners are removed
    //
    getDLReq = new GetDistributionListRequest(DistributionListSelector.fromName(GROUP_NAME), Boolean.TRUE);
    getDLResp = invokeJaxb(transport, getDLReq);
    dlInfo = getDLResp.getDl();
    owners = dlInfo.getOwners();
    ownerNames = Sets.newHashSet();
    for (DistributionListGranteeInfoInterface owner : owners) {
        if (owner.getType() == com.zimbra.soap.type.GranteeType.usr) {
            ownerNames.add(owner.getName());
        }
    }
    assertEquals(1, owners.size());
    Verify.verifyEquals(Sets.newHashSet(USER_OWNER), ownerNames);
}
Also used : GetDistributionListResponse(com.zimbra.soap.account.message.GetDistributionListResponse) Group(com.zimbra.cs.account.Group) Account(com.zimbra.cs.account.Account) DistributionListGranteeInfoInterface(com.zimbra.soap.base.DistributionListGranteeInfoInterface) DistributionListInfo(com.zimbra.soap.account.type.DistributionListInfo) DistributionListActionResponse(com.zimbra.soap.account.message.DistributionListActionResponse) GetDistributionListRequest(com.zimbra.soap.account.message.GetDistributionListRequest) DistributionListActionRequest(com.zimbra.soap.account.message.DistributionListActionRequest) DistributionListGranteeSelector(com.zimbra.soap.account.type.DistributionListGranteeSelector) DistributionListAction(com.zimbra.soap.account.type.DistributionListAction) SoapTransport(com.zimbra.common.soap.SoapTransport) Test(org.junit.Test)

Example 10 with DistributionListActionRequest

use of com.zimbra.soap.account.message.DistributionListActionRequest in project zm-mailbox by Zimbra.

the class TestDelegatedDL method distributionListActionModify.

@Test
public void distributionListActionModify() throws Exception {
    String ATTR = Provisioning.A_description;
    String VALUE = "test description";
    SoapTransport transport = authUser(USER_OWNER);
    DistributionListAction action = new DistributionListAction(Operation.modify);
    List<KeyValuePair> attrs = Lists.newArrayList(new KeyValuePair(ATTR, VALUE));
    action.setKeyValuePairs(attrs);
    DistributionListActionRequest req = new DistributionListActionRequest(DistributionListSelector.fromName(DL_NAME), action);
    DistributionListActionResponse resp = invokeJaxb(transport, req);
    Group group = prov.getGroup(Key.DistributionListBy.name, DL_NAME);
    assertEquals(VALUE, group.getAttr(ATTR));
}
Also used : Group(com.zimbra.cs.account.Group) KeyValuePair(com.zimbra.soap.type.KeyValuePair) DistributionListActionResponse(com.zimbra.soap.account.message.DistributionListActionResponse) DistributionListAction(com.zimbra.soap.account.type.DistributionListAction) SoapTransport(com.zimbra.common.soap.SoapTransport) DistributionListActionRequest(com.zimbra.soap.account.message.DistributionListActionRequest) Test(org.junit.Test)

Aggregations

DistributionListActionRequest (com.zimbra.soap.account.message.DistributionListActionRequest)14 DistributionListAction (com.zimbra.soap.account.type.DistributionListAction)14 DistributionListActionResponse (com.zimbra.soap.account.message.DistributionListActionResponse)13 SoapTransport (com.zimbra.common.soap.SoapTransport)12 Group (com.zimbra.cs.account.Group)12 Test (org.junit.Test)12 Account (com.zimbra.cs.account.Account)9 DistributionListGranteeSelector (com.zimbra.soap.account.type.DistributionListGranteeSelector)8 ServiceException (com.zimbra.common.service.ServiceException)5 AccountServiceException (com.zimbra.cs.account.AccountServiceException)5 GetDistributionListRequest (com.zimbra.soap.account.message.GetDistributionListRequest)5 GetDistributionListResponse (com.zimbra.soap.account.message.GetDistributionListResponse)4 DistributionListInfo (com.zimbra.soap.account.type.DistributionListInfo)4 DistributionListRightSpec (com.zimbra.soap.account.type.DistributionListRightSpec)3 DistributionListGranteeInfoInterface (com.zimbra.soap.base.DistributionListGranteeInfoInterface)3 Bug (com.zimbra.qa.QA.Bug)2 Domain (com.zimbra.cs.account.Domain)1 RightCommand (com.zimbra.cs.account.accesscontrol.RightCommand)1 SubscribeDistributionListRequest (com.zimbra.soap.account.message.SubscribeDistributionListRequest)1 DistributionListGranteeInfo (com.zimbra.soap.account.type.DistributionListGranteeInfo)1