Search in sources :

Example 1 with AllGroupMembers

use of com.zimbra.cs.account.accesscontrol.CollectAllEffectiveRights.AllGroupMembers in project zm-mailbox by Zimbra.

the class TestACLAllEffRights method shapeTest2.

@Test
public void shapeTest2() throws Exception {
    /*
         * setup
         */
    String domainName = genDomainName(baseDomainName());
    Domain domain = provUtil.createDomain(domainName);
    DistributionList groupA = provUtil.createDistributionList("groupA", domain);
    DistributionList groupB = provUtil.createDistributionList("groupB", domain);
    DistributionList groupC = provUtil.createDistributionList("groupC", domain);
    DistributionList groupD = provUtil.createDistributionList("groupD", domain);
    Account A = provUtil.createAccount("A", domain);
    Account B = provUtil.createAccount("B", domain);
    Account C = provUtil.createAccount("C", domain);
    Account D = provUtil.createAccount("D", domain);
    groupA.addMembers(new String[] { A.getName(), groupB.getName() });
    groupB.addMembers(new String[] { B.getName(), groupC.getName() });
    groupC.addMembers(new String[] { C.getName(), groupD.getName() });
    groupD.addMembers(new String[] { D.getName() });
    /*
         * test
         */
    Set<DistributionList> groupsWithGrants = new HashSet<DistributionList>();
    groupsWithGrants.add(groupA);
    groupsWithGrants.add(groupB);
    groupsWithGrants.add(groupC);
    groupsWithGrants.add(groupD);
    Set<GroupShape> accountShapes = new HashSet<GroupShape>();
    Set<GroupShape> calendarResourceShapes = new HashSet<GroupShape>();
    Set<GroupShape> distributionListShapes = new HashSet<GroupShape>();
    for (DistributionList group : groupsWithGrants) {
        DistributionList dl = prov.get(DistributionListBy.id, group.getId());
        AllGroupMembers allMembers = allGroupMembers(dl);
        GroupShape.shapeMembers(TargetType.account, accountShapes, allMembers);
        GroupShape.shapeMembers(TargetType.calresource, calendarResourceShapes, allMembers);
        GroupShape.shapeMembers(TargetType.dl, distributionListShapes, allMembers);
    }
    /*
         * verify
         */
    Set<String> result = new HashSet<String>();
    int count = 1;
    for (GroupShape shape : accountShapes) {
        List<String> elements = new ArrayList<String>();
        System.out.println("\n" + count++);
        for (String group : shape.getGroups()) {
            System.out.println("group " + group);
            elements.add("group " + group);
        }
        for (String member : shape.getMembers()) {
            System.out.println("    " + member);
            elements.add("member " + member);
        }
        Collections.sort(elements);
        // but it does not affect functionality
        if (shape.getMembers().size() > 0) {
            result.add(Verify.makeResultStr(elements));
        }
    }
    Set<String> expected = new HashSet<String>();
    expected.add(Verify.makeResultStr(Lists.newArrayList("group " + groupA.getName(), "member " + A.getName())));
    expected.add(Verify.makeResultStr(Lists.newArrayList("group " + groupA.getName(), "group " + groupB.getName(), "member " + B.getName())));
    expected.add(Verify.makeResultStr(Lists.newArrayList("group " + groupA.getName(), "group " + groupB.getName(), "group " + groupC.getName(), "member " + C.getName())));
    expected.add(Verify.makeResultStr(Lists.newArrayList("group " + groupA.getName(), "group " + groupB.getName(), "group " + groupC.getName(), "group " + groupD.getName(), "member " + D.getName())));
    Verify.verifyEquals(expected, result);
}
Also used : Account(com.zimbra.cs.account.Account) ArrayList(java.util.ArrayList) AllGroupMembers(com.zimbra.cs.account.accesscontrol.CollectAllEffectiveRights.AllGroupMembers) GroupShape(com.zimbra.cs.account.accesscontrol.CollectAllEffectiveRights.GroupShape) Domain(com.zimbra.cs.account.Domain) DistributionList(com.zimbra.cs.account.DistributionList) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 2 with AllGroupMembers

use of com.zimbra.cs.account.accesscontrol.CollectAllEffectiveRights.AllGroupMembers in project zm-mailbox by Zimbra.

the class TestACLAllEffRights method shapeTest1.

@Test
public void shapeTest1() throws Exception {
    /*
         * setup
         */
    String domainName = genDomainName(baseDomainName());
    Domain domain = provUtil.createDomain(domainName);
    DistributionList groupA = provUtil.createDistributionList("groupA", domain);
    DistributionList groupB = provUtil.createDistributionList("groupB", domain);
    DistributionList groupC = provUtil.createDistributionList("groupC", domain);
    DistributionList groupD = provUtil.createDistributionList("groupD", domain);
    Account A = provUtil.createAccount("A", domain);
    Account B = provUtil.createAccount("B", domain);
    Account C = provUtil.createAccount("C", domain);
    Account D = provUtil.createAccount("D", domain);
    Account AB = provUtil.createAccount("AB", domain);
    Account AC = provUtil.createAccount("AC", domain);
    Account AD = provUtil.createAccount("AD", domain);
    Account BC = provUtil.createAccount("BC", domain);
    Account BD = provUtil.createAccount("BD", domain);
    Account CD = provUtil.createAccount("CD", domain);
    Account ABC = provUtil.createAccount("ABC", domain);
    Account ABD = provUtil.createAccount("ABD", domain);
    Account ACD = provUtil.createAccount("ACD", domain);
    Account BCD = provUtil.createAccount("BCD", domain);
    Account ABCD = provUtil.createAccount("ABCD", domain);
    groupA.addMembers(new String[] { A.getName(), AB.getName(), AC.getName(), AD.getName(), ABC.getName(), ABD.getName(), ACD.getName(), ABCD.getName() });
    groupB.addMembers(new String[] { B.getName(), AB.getName(), BC.getName(), BD.getName(), ABC.getName(), ABD.getName(), BCD.getName(), ABCD.getName() });
    groupC.addMembers(new String[] { C.getName(), AC.getName(), BC.getName(), CD.getName(), ABC.getName(), ACD.getName(), BCD.getName(), ABCD.getName() });
    groupD.addMembers(new String[] { D.getName(), AD.getName(), BD.getName(), CD.getName(), ABD.getName(), ACD.getName(), BCD.getName(), ABCD.getName() });
    /*
         * test
         */
    Set<DistributionList> groupsWithGrants = new HashSet<DistributionList>();
    groupsWithGrants.add(groupA);
    groupsWithGrants.add(groupB);
    groupsWithGrants.add(groupC);
    groupsWithGrants.add(groupD);
    Set<GroupShape> accountShapes = new HashSet<GroupShape>();
    Set<GroupShape> calendarResourceShapes = new HashSet<GroupShape>();
    Set<GroupShape> distributionListShapes = new HashSet<GroupShape>();
    for (DistributionList group : groupsWithGrants) {
        DistributionList dl = prov.get(DistributionListBy.id, group.getId());
        AllGroupMembers allMembers = allGroupMembers(dl);
        GroupShape.shapeMembers(TargetType.account, accountShapes, allMembers);
        GroupShape.shapeMembers(TargetType.calresource, calendarResourceShapes, allMembers);
        GroupShape.shapeMembers(TargetType.dl, distributionListShapes, allMembers);
    }
    /*
         * verify
         */
    Set<String> result = new HashSet<String>();
    int count = 1;
    for (GroupShape shape : accountShapes) {
        List<String> elements = new ArrayList<String>();
        System.out.println("\n" + count++);
        for (String group : shape.getGroups()) {
            System.out.println("group " + group);
            elements.add("group " + group);
        }
        for (String member : shape.getMembers()) {
            System.out.println("    member" + member);
            elements.add("member " + member);
        }
        Collections.sort(elements);
        // but it does not affect functionality
        if (shape.getMembers().size() > 0) {
            result.add(Verify.makeResultStr(elements));
        }
    }
    Set<String> expected = new HashSet<String>();
    expected.add(Verify.makeResultStr(Lists.newArrayList("group " + groupA.getName(), "member " + A.getName())));
    expected.add(Verify.makeResultStr(Lists.newArrayList("group " + groupB.getName(), "member " + B.getName())));
    expected.add(Verify.makeResultStr(Lists.newArrayList("group " + groupC.getName(), "member " + C.getName())));
    expected.add(Verify.makeResultStr(Lists.newArrayList("group " + groupD.getName(), "member " + D.getName())));
    expected.add(Verify.makeResultStr(Lists.newArrayList("group " + groupA.getName(), "group " + groupB.getName(), "member " + AB.getName())));
    expected.add(Verify.makeResultStr(Lists.newArrayList("group " + groupA.getName(), "group " + groupC.getName(), "member " + AC.getName())));
    expected.add(Verify.makeResultStr(Lists.newArrayList("group " + groupA.getName(), "group " + groupD.getName(), "member " + AD.getName())));
    expected.add(Verify.makeResultStr(Lists.newArrayList("group " + groupB.getName(), "group " + groupC.getName(), "member " + BC.getName())));
    expected.add(Verify.makeResultStr(Lists.newArrayList("group " + groupB.getName(), "group " + groupD.getName(), "member " + BD.getName())));
    expected.add(Verify.makeResultStr(Lists.newArrayList("group " + groupC.getName(), "group " + groupD.getName(), "member " + CD.getName())));
    expected.add(Verify.makeResultStr(Lists.newArrayList("group " + groupA.getName(), "group " + groupB.getName(), "group " + groupC.getName(), "member " + ABC.getName())));
    expected.add(Verify.makeResultStr(Lists.newArrayList("group " + groupA.getName(), "group " + groupB.getName(), "group " + groupD.getName(), "member " + ABD.getName())));
    expected.add(Verify.makeResultStr(Lists.newArrayList("group " + groupA.getName(), "group " + groupC.getName(), "group " + groupD.getName(), "member " + ACD.getName())));
    expected.add(Verify.makeResultStr(Lists.newArrayList("group " + groupB.getName(), "group " + groupC.getName(), "group " + groupD.getName(), "member " + BCD.getName())));
    expected.add(Verify.makeResultStr(Lists.newArrayList("group " + groupA.getName(), "group " + groupB.getName(), "group " + groupC.getName(), "group " + groupD.getName(), "member " + ABCD.getName())));
    Verify.verifyEquals(expected, result);
}
Also used : Account(com.zimbra.cs.account.Account) ArrayList(java.util.ArrayList) AllGroupMembers(com.zimbra.cs.account.accesscontrol.CollectAllEffectiveRights.AllGroupMembers) GroupShape(com.zimbra.cs.account.accesscontrol.CollectAllEffectiveRights.GroupShape) Domain(com.zimbra.cs.account.Domain) DistributionList(com.zimbra.cs.account.DistributionList) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

Account (com.zimbra.cs.account.Account)2 DistributionList (com.zimbra.cs.account.DistributionList)2 Domain (com.zimbra.cs.account.Domain)2 AllGroupMembers (com.zimbra.cs.account.accesscontrol.CollectAllEffectiveRights.AllGroupMembers)2 GroupShape (com.zimbra.cs.account.accesscontrol.CollectAllEffectiveRights.GroupShape)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 Test (org.junit.Test)2