Search in sources :

Example 31 with Group

use of com.zimbra.cs.account.Group in project zm-mailbox by Zimbra.

the class TestDelegatedDL method getDistributionListAdmin.

/*
     * Test the owners element in zimbraAdmin:GetDistributionList
     */
@Test
public void getDistributionListAdmin() throws Exception {
    SoapTransport transport = authAdmin(ADMIN);
    com.zimbra.soap.admin.message.GetDistributionListRequest req = new com.zimbra.soap.admin.message.GetDistributionListRequest(com.zimbra.soap.admin.type.DistributionListSelector.fromName(DL_NAME));
    com.zimbra.soap.admin.message.GetDistributionListResponse resp = invokeJaxb(transport, req);
    com.zimbra.soap.admin.type.DistributionListInfo dlInfo = resp.getDl();
    String dlId = dlInfo.getId();
    Group group = prov.getGroup(Key.DistributionListBy.name, DL_NAME);
    assertNotNull(group);
    assertEquals(group.getId(), dlId);
    /*
        System.out.println("\nAttrs:");
        List<com.zimbra.soap.admin.type.Attr> attrs = dlInfo.getAttrList();
        for (com.zimbra.soap.admin.type.Attr attr : attrs) {
            System.out.println(attr.getN() + ", " + attr.getValue());
        }
        */
    List<GranteeInfo> dlOwners = dlInfo.getOwners();
    assertEquals(1, dlOwners.size());
    for (GranteeInfo owner : dlOwners) {
        com.zimbra.soap.type.GranteeType type = owner.getType();
        String id = owner.getId();
        String name = owner.getName();
        assertEquals(com.zimbra.soap.type.GranteeType.usr, type);
        assertEquals(USER_OWNER, name);
    }
}
Also used : Group(com.zimbra.cs.account.Group) GranteeInfo(com.zimbra.soap.admin.type.GranteeInfo) DistributionListGranteeInfo(com.zimbra.soap.account.type.DistributionListGranteeInfo) GetDistributionListRequest(com.zimbra.soap.account.message.GetDistributionListRequest) SoapTransport(com.zimbra.common.soap.SoapTransport) Test(org.junit.Test)

Example 32 with Group

use of com.zimbra.cs.account.Group in project zm-mailbox by Zimbra.

the class TestDiscoverRights method displayName.

/*
     * verify display name is returned in DiscoverRights and discovered targets
     * are sorted by displayName
     */
@Test
@Bug(bug = 68225)
public void displayName() throws Exception {
    Account acct = provUtil.createAccount(genAcctNameLocalPart(), domain);
    String GROUP_1_NAME = getAddress(genGroupNameLocalPart("1"));
    String GROUP_1_DISPLAY_NAME = "third";
    String GROUP_2_NAME = getAddress(genGroupNameLocalPart("2"));
    String GROUP_2_DISPLAY_NAME = "first";
    String GROUP_3_NAME = getAddress(genGroupNameLocalPart("3"));
    String GROUP_3_DISPLAY_NAME = "first";
    Group group1 = provUtil.createGroup(GROUP_1_NAME, Collections.singletonMap(Provisioning.A_displayName, (Object) GROUP_1_DISPLAY_NAME), false);
    Group group2 = provUtil.createGroup(GROUP_2_NAME, Collections.singletonMap(Provisioning.A_displayName, (Object) GROUP_2_DISPLAY_NAME), false);
    Group group3 = provUtil.createGroup(GROUP_3_NAME, Collections.singletonMap(Provisioning.A_displayName, (Object) GROUP_3_DISPLAY_NAME), false);
    String RIGHT_NAME = User.R_ownDistList.getName();
    prov.grantRight(TargetType.dl.getCode(), TargetBy.name, group1.getName(), GranteeType.GT_USER.getCode(), GranteeBy.name, acct.getName(), null, RIGHT_NAME, null);
    prov.grantRight(TargetType.dl.getCode(), TargetBy.name, group2.getName(), GranteeType.GT_USER.getCode(), GranteeBy.name, acct.getName(), null, RIGHT_NAME, null);
    prov.grantRight(TargetType.dl.getCode(), TargetBy.name, group3.getName(), GranteeType.GT_USER.getCode(), GranteeBy.name, acct.getName(), null, RIGHT_NAME, null);
    SoapTransport transport = authUser(acct.getName());
    DiscoverRightsRequest req = new DiscoverRightsRequest(Collections.singletonList(RIGHT_NAME));
    DiscoverRightsResponse resp = invokeJaxb(transport, req);
    List<DiscoverRightsInfo> rightsInfo = resp.getDiscoveredRights();
    assertEquals(1, rightsInfo.size());
    List<String> result = Lists.newArrayList();
    for (DiscoverRightsInfo rightInfo : rightsInfo) {
        List<DiscoverRightsTarget> targets = rightInfo.getTargets();
        for (DiscoverRightsTarget target : targets) {
            String id = target.getId();
            String name = target.getName();
            String displayName = target.getDisplayName();
            result.add(Verify.makeResultStr(id, name, displayName));
        }
    }
    // result should be sorted by displayName.
    // If displayName are the same, sorted by entry.getLabel()
    Verify.verifyEquals(Lists.newArrayList(Verify.makeResultStr(group2.getId(), group2.getName(), group2.getDisplayName()), Verify.makeResultStr(group3.getId(), group3.getName(), group3.getDisplayName()), Verify.makeResultStr(group1.getId(), group1.getName(), group1.getDisplayName())), result);
}
Also used : Account(com.zimbra.cs.account.Account) Group(com.zimbra.cs.account.Group) DiscoverRightsRequest(com.zimbra.soap.account.message.DiscoverRightsRequest) DiscoverRightsInfo(com.zimbra.soap.account.type.DiscoverRightsInfo) DiscoverRightsResponse(com.zimbra.soap.account.message.DiscoverRightsResponse) DiscoverRightsTarget(com.zimbra.soap.account.type.DiscoverRightsTarget) SoapTransport(com.zimbra.common.soap.SoapTransport) Test(org.junit.Test) Bug(com.zimbra.qa.QA.Bug)

Example 33 with Group

use of com.zimbra.cs.account.Group 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 34 with Group

use of com.zimbra.cs.account.Group 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 35 with Group

use of com.zimbra.cs.account.Group in project zm-mailbox by Zimbra.

the class DistributionListAction method handle.

@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
    ZimbraSoapContext zsc = getZimbraSoapContext(context);
    Provisioning prov = Provisioning.getInstance();
    Account acct = getAuthenticatedAccount(zsc);
    Group group = getGroupBasic(request, prov);
    DistributionListActionHandler handler = new DistributionListActionHandler(group, request, prov, acct);
    handler.handle();
    Element response = zsc.createElement(AccountConstants.DISTRIBUTION_LIST_ACTION_RESPONSE);
    return response;
}
Also used : Account(com.zimbra.cs.account.Account) Group(com.zimbra.cs.account.Group) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) Element(com.zimbra.common.soap.Element) Provisioning(com.zimbra.cs.account.Provisioning)

Aggregations

Group (com.zimbra.cs.account.Group)110 Account (com.zimbra.cs.account.Account)53 Test (org.junit.Test)42 DynamicGroup (com.zimbra.cs.account.DynamicGroup)27 ServiceException (com.zimbra.common.service.ServiceException)23 SoapTransport (com.zimbra.common.soap.SoapTransport)23 Provisioning (com.zimbra.cs.account.Provisioning)23 LdapDynamicGroup (com.zimbra.cs.account.ldap.entry.LdapDynamicGroup)21 Domain (com.zimbra.cs.account.Domain)17 GuestAccount (com.zimbra.cs.account.GuestAccount)17 ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)17 Element (com.zimbra.common.soap.Element)16 AccountServiceException (com.zimbra.cs.account.AccountServiceException)15 NamedEntry (com.zimbra.cs.account.NamedEntry)14 LdapAccount (com.zimbra.cs.account.ldap.entry.LdapAccount)12 DistributionListActionRequest (com.zimbra.soap.account.message.DistributionListActionRequest)12 DistributionListAction (com.zimbra.soap.account.type.DistributionListAction)12 DistributionListActionResponse (com.zimbra.soap.account.message.DistributionListActionResponse)11 DistributionList (com.zimbra.cs.account.DistributionList)9 Entry (com.zimbra.cs.account.Entry)9