Search in sources :

Example 1 with DistributionListAction

use of com.zimbra.soap.account.type.DistributionListAction in project zm-mailbox by Zimbra.

the class TestDelegatedDL method addOwner.

private static void addOwner(SoapTransport transport, String groupName, String ownerName) throws Exception {
    DistributionListAction action = new DistributionListAction(Operation.addOwners);
    DistributionListActionRequest actionReq = new DistributionListActionRequest(DistributionListSelector.fromName(groupName), action);
    action.addOwner(new DistributionListGranteeSelector(com.zimbra.soap.type.GranteeType.usr, DistributionListGranteeBy.name, ownerName));
    DistributionListActionResponse actionResp = invokeJaxb(transport, actionReq);
}
Also used : DistributionListGranteeSelector(com.zimbra.soap.account.type.DistributionListGranteeSelector) DistributionListActionResponse(com.zimbra.soap.account.message.DistributionListActionResponse) DistributionListAction(com.zimbra.soap.account.type.DistributionListAction) DistributionListActionRequest(com.zimbra.soap.account.message.DistributionListActionRequest)

Example 2 with DistributionListAction

use of com.zimbra.soap.account.type.DistributionListAction in project zm-mailbox by Zimbra.

the class TestDelegatedDL method ownerIsGroup.

/*
     * owner of a group is a group
     */
@Test
public void ownerIsGroup() throws Exception {
    Group ownedGroup = provUtil.createGroup(genGroupNameLocalPart("owned"), domain, DYNAMIC);
    Group owningGroup = provUtil.createGroup(genGroupNameLocalPart("owning"), domain, DYNAMIC);
    /*
         * add members to owning group
         */
    Account acctInOwningGroup = provUtil.createAccount("acctInOwningGroup", domain);
    prov.addGroupMembers(owningGroup, new String[] { acctInOwningGroup.getName() });
    /*
         * grant ownDistList right to owningGroup on ownedGroup
         */
    prov.grantRight(TargetType.dl.getCode(), TargetBy.name, ownedGroup.getName(), GranteeType.GT_GROUP.getCode(), GranteeBy.name, owningGroup.getName(), null, Group.GroupOwner.GROUP_OWNER_RIGHT.getName(), null);
    /*
         * auth as acctInOwningGroup
         */
    SoapTransport transport = authUser(acctInOwningGroup.getName());
    /*
         * try to add member in ownedGroup
         */
    // addMembers
    DistributionListAction action = new DistributionListAction(Operation.addMembers);
    DistributionListActionRequest req = new DistributionListActionRequest(DistributionListSelector.fromName(ownedGroup.getName()), action);
    String MEMBER1 = "member1@test.com";
    String MEMBER2 = "member2@test.com";
    action.addMember(MEMBER1);
    action.addMember(MEMBER2);
    DistributionListActionResponse resp = invokeJaxb(transport, req);
    Group group = prov.getGroup(Key.DistributionListBy.name, ownedGroup.getName());
    Set<String> members = group.getAllMembersSet();
    assertEquals(2, members.size());
    assertTrue(members.contains(MEMBER1));
    assertTrue(members.contains(MEMBER2));
    provUtil.deleteAccount(acctInOwningGroup);
    provUtil.deleteGroup(owningGroup);
    provUtil.deleteGroup(ownedGroup);
}
Also used : Group(com.zimbra.cs.account.Group) Account(com.zimbra.cs.account.Account) 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 3 with DistributionListAction

use of com.zimbra.soap.account.type.DistributionListAction in project zm-mailbox by Zimbra.

the class TestDelegatedDL method distributionListActionSetBadOwners.

@Test
@Bug(bug = 72791)
public void distributionListActionSetBadOwners() throws Exception {
    String GROUP_NAME = getAddress(genGroupNameLocalPart());
    Group group = createGroupAndAddOwner(GROUP_NAME);
    Account owner1 = provUtil.createAccount(genAcctNameLocalPart("1"), domain);
    Account owner2 = provUtil.createAccount(genAcctNameLocalPart("2"), domain);
    Account owner3 = provUtil.createAccount(genAcctNameLocalPart("3"), domain);
    SoapTransport transport = authUser(USER_OWNER);
    //
    // setOwners: some good owners an a bogus owner (not a user)
    //
    DistributionListAction action = new DistributionListAction(Operation.setOwners);
    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()));
    action.addOwner(new DistributionListGranteeSelector(com.zimbra.soap.type.GranteeType.usr, DistributionListGranteeBy.name, owner3.getName()));
    action.addOwner(new DistributionListGranteeSelector(com.zimbra.soap.type.GranteeType.usr, DistributionListGranteeBy.name, "bogus@bogus.com"));
    String errorCode = null;
    try {
        DistributionListActionResponse resp = invokeJaxb(transport, req);
    } catch (ServiceException e) {
        errorCode = e.getCode();
    }
    assertEquals(AccountServiceException.NO_SUCH_ACCOUNT, errorCode);
    //
    // verify owners are NOT replaced
    //
    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(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) AccountServiceException(com.zimbra.cs.account.AccountServiceException) ServiceException(com.zimbra.common.service.ServiceException) DistributionListAction(com.zimbra.soap.account.type.DistributionListAction) SoapTransport(com.zimbra.common.soap.SoapTransport) Test(org.junit.Test) Bug(com.zimbra.qa.QA.Bug)

Example 4 with DistributionListAction

use of com.zimbra.soap.account.type.DistributionListAction in project zm-mailbox by Zimbra.

the class TestDelegatedDL method getDistributionListRights.

/*
     * verify rights are returned
     */
@Test
public void getDistributionListRights() throws Exception {
    String GROUP_NAME = getAddress(genGroupNameLocalPart("group"));
    Group group = createGroupAndAddOwner(GROUP_NAME);
    String right1 = Right.RT_sendToDistList;
    String right2 = Right.RT_viewDistList;
    Account grantee1 = provUtil.createAccount(genAcctNameLocalPart("1"), domain);
    Account grantee2 = provUtil.createAccount(genAcctNameLocalPart("2"), domain);
    SoapTransport transport = authUser(USER_OWNER);
    //
    // grantRights
    //
    DistributionListAction action = new DistributionListAction(Operation.grantRights);
    DistributionListActionRequest req = new DistributionListActionRequest(DistributionListSelector.fromName(GROUP_NAME), action);
    DistributionListRightSpec dlRight1 = new DistributionListRightSpec(right1);
    dlRight1.addGrantee(new DistributionListGranteeSelector(com.zimbra.soap.type.GranteeType.usr, DistributionListGranteeBy.name, grantee1.getName()));
    dlRight1.addGrantee(new DistributionListGranteeSelector(com.zimbra.soap.type.GranteeType.usr, DistributionListGranteeBy.name, grantee2.getName()));
    DistributionListRightSpec dlRight2 = new DistributionListRightSpec(right2);
    dlRight2.addGrantee(new DistributionListGranteeSelector(com.zimbra.soap.type.GranteeType.all, null, null));
    action.addRight(dlRight1);
    action.addRight(dlRight2);
    DistributionListActionResponse resp = invokeJaxb(transport, req);
    /*
         * verify rights are returned
         */
    GetDistributionListRequest getDLReq = new GetDistributionListRequest(DistributionListSelector.fromName(GROUP_NAME), Boolean.FALSE, right1 + "," + right2);
    GetDistributionListResponse getDLResp = invokeJaxb(transport, getDLReq);
    DistributionListInfo dlInfo = getDLResp.getDl();
    List<? extends DistributionListRightInfo> rights = dlInfo.getRights();
    Set<String> right1GranteeNames = Sets.newHashSet();
    Set<String> right2GranteeNames = Sets.newHashSet();
    for (DistributionListRightInfo rightInfo : rights) {
        String right = rightInfo.getRight();
        List<DistributionListGranteeInfo> grantees = rightInfo.getGrantees();
        if (right1.equals(right)) {
            for (DistributionListGranteeInfo grantee : grantees) {
                right1GranteeNames.add(Verify.makeResultStr(grantee.getType().name(), grantee.getName()));
            }
        } else if (right2.equals(right)) {
            for (DistributionListGranteeInfo grantee : grantees) {
                right2GranteeNames.add(Verify.makeResultStr(grantee.getType().name(), grantee.getName()));
            }
        }
    }
    Verify.verifyEquals(Sets.newHashSet(Verify.makeResultStr(GranteeType.GT_USER.getCode(), grantee1.getName()), Verify.makeResultStr(GranteeType.GT_USER.getCode(), grantee2.getName())), right1GranteeNames);
    Verify.verifyEquals(Sets.newHashSet(Verify.makeResultStr(GranteeType.GT_AUTHUSER.getCode(), "null")), right2GranteeNames);
}
Also used : GetDistributionListResponse(com.zimbra.soap.account.message.GetDistributionListResponse) Group(com.zimbra.cs.account.Group) Account(com.zimbra.cs.account.Account) DistributionListInfo(com.zimbra.soap.account.type.DistributionListInfo) DistributionListGranteeInfo(com.zimbra.soap.account.type.DistributionListGranteeInfo) DistributionListActionResponse(com.zimbra.soap.account.message.DistributionListActionResponse) GetDistributionListRequest(com.zimbra.soap.account.message.GetDistributionListRequest) DistributionListRightInfo(com.zimbra.soap.account.type.DistributionListRightInfo) DistributionListActionRequest(com.zimbra.soap.account.message.DistributionListActionRequest) DistributionListGranteeSelector(com.zimbra.soap.account.type.DistributionListGranteeSelector) DistributionListAction(com.zimbra.soap.account.type.DistributionListAction) DistributionListRightSpec(com.zimbra.soap.account.type.DistributionListRightSpec) SoapTransport(com.zimbra.common.soap.SoapTransport) Test(org.junit.Test)

Example 5 with DistributionListAction

use of com.zimbra.soap.account.type.DistributionListAction in project zm-mailbox by Zimbra.

the class TestDelegatedDL method distributionListActionSetOwners.

@Test
public void distributionListActionSetOwners() 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);
    Account owner3 = provUtil.createAccount(genAcctNameLocalPart("3"), domain);
    SoapTransport transport = authUser(USER_OWNER);
    //
    // setOwners
    //
    DistributionListAction action = new DistributionListAction(Operation.setOwners);
    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()));
    action.addOwner(new DistributionListGranteeSelector(com.zimbra.soap.type.GranteeType.email, DistributionListGranteeBy.name, owner3.getName()));
    DistributionListActionResponse resp = invokeJaxb(transport, req);
    //
    // verify owners are replaced
    //
    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(4, owners.size());
    Verify.verifyEquals(Sets.newHashSet(USER_OWNER, owner1.getName(), owner2.getName(), owner3.getName()), ownerNames);
    /*
         * test invalid grantee type for owner
         */
    action = new DistributionListAction(Operation.setOwners);
    req = new DistributionListActionRequest(DistributionListSelector.fromName(GROUP_NAME), action);
    action.addOwner(new DistributionListGranteeSelector(com.zimbra.soap.type.GranteeType.email, DistributionListGranteeBy.name, "user@external.com"));
    String errCode = null;
    try {
        resp = invokeJaxb(transport, req);
    } catch (ServiceException e) {
        errCode = e.getCode();
    }
    assertEquals(ServiceException.INVALID_REQUEST, errCode);
    // remove all owners
    action = new DistributionListAction(Operation.setOwners);
    req = new DistributionListActionRequest(DistributionListSelector.fromName(GROUP_NAME), action);
    resp = invokeJaxb(transport, req);
    getDLReq = new GetDistributionListRequest(DistributionListSelector.fromName(GROUP_NAME), Boolean.TRUE);
    getDLResp = invokeJaxb(transport, getDLReq);
    dlInfo = getDLResp.getDl();
    owners = dlInfo.getOwners();
    assertEquals(0, owners.size());
}
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) AccountServiceException(com.zimbra.cs.account.AccountServiceException) ServiceException(com.zimbra.common.service.ServiceException) DistributionListAction(com.zimbra.soap.account.type.DistributionListAction) SoapTransport(com.zimbra.common.soap.SoapTransport) 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