Search in sources :

Example 6 with GroupMembership

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

the class TestGroups method doGetGroupMembershipWithRights.

private GroupMembership doGetGroupMembershipWithRights(Account acct, Set<Right> rights, int expected, int adminOnlyExpected) throws ServiceException {
    String rightsDesc;
    if (rights == null) {
        rightsDesc = "rights={ALL(null)}";
    } else if (rights.isEmpty()) {
        rightsDesc = "rights={ALL(empty)}";
    } else {
        StringBuilder sb = new StringBuilder("rights=");
        for (Right right : rights) {
            if (sb.length() > 7) {
                sb.append(',');
            }
            sb.append(right.getName());
        }
        rightsDesc = sb.toString();
    }
    long before = System.currentTimeMillis();
    GroupMembership membership = ldapProv.getGroupMembershipWithRights(acct, rights, false);
    long after = System.currentTimeMillis();
    String groupNames = groupInfo(membership.groupIds());
    ZimbraLog.test.info("YYY getGroupMembershipWithRights %s ms=%s acct=%s size=%s\n%s\ngroupNames=%s", rightsDesc, after - before, acct.getName(), membership.groupIds().size(), membership, groupNames);
    before = System.currentTimeMillis();
    GroupMembership adminOnlyMembership = ldapProv.getGroupMembershipWithRights(acct, rights, true);
    after = System.currentTimeMillis();
    String adminOnlyGroupNames = groupInfo(membership.groupIds());
    ZimbraLog.test.info("YYY getGroupMembershipWithRights [adminOnly] %s ms=%s acct=%s size=%s\n%s\ngroupNames=%s", rightsDesc, after - before, acct.getName(), adminOnlyMembership.groupIds().size(), adminOnlyMembership, adminOnlyGroupNames);
    assertEquals(String.format("Number of groups with %s which contain %s groups=%s", rightsDesc, acct.getName(), groupNames), expected, membership.groupIds().size());
    assertEquals(String.format("Number of adminOnly groups with %s which contain %s groups=%s", rightsDesc, acct.getName(), adminOnlyGroupNames), adminOnlyExpected, adminOnlyMembership.groupIds().size());
    return membership;
}
Also used : Right(com.zimbra.cs.account.accesscontrol.Right) GroupMembership(com.zimbra.cs.account.Provisioning.GroupMembership)

Example 7 with GroupMembership

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

the class TestGroups method testDLupdateGroupMembershipWithViaWithAliases.

public void testDLupdateGroupMembershipWithViaWithAliases() throws Exception {
    Account acct = ldapProv.getAccountByName(acctWithAlias);
    GroupMembership membership = new GroupMembership();
    Map<String, String> via = Maps.newHashMap();
    long start = System.currentTimeMillis();
    DistributionList.updateGroupMembership(ldapProv, (ZLdapContext) null, membership, acct, via, false, /* adminGroupsOnly */
    false);
    ZimbraLog.test.info("testDLupdateGroupMembershipWithVia %s size=%d via size=%d via=%s", ZimbraLog.elapsedTime(start, System.currentTimeMillis()), membership.groupIds().size(), via.size(), via);
    for (int cnt = 1; cnt <= NUM_NORMAL_DL; cnt++) {
        String nam = String.format(normalDLPatt, cnt);
        DistributionList dl = ldapProv.get(DistributionListBy.name, nam);
        Assert.assertTrue(String.format("DL %s (id=%s) in membership", nam, dl.getId()), membership.groupIds().contains(dl.getId()));
    }
    DistributionList dl = ldapProv.get(DistributionListBy.name, dlWithAlias);
    Assert.assertTrue(String.format("DL %s (id=%s) in membership", dl.getId(), dl.getId()), membership.groupIds().contains(dl.getId()));
    dl = ldapProv.get(DistributionListBy.name, dlWithAlias2);
    Assert.assertTrue(String.format("DL %s (id=%s) in membership", dl.getId(), dl.getId()), membership.groupIds().contains(dl.getId()));
    Assert.assertEquals(String.format("Number of DLs User %s is a member of", acctWithAlias), NUM_NORMAL_DL + 2, membership.memberOf().size());
    Assert.assertEquals(String.format("Number of vias for User %s", acctWithAlias), 1, via.size());
    acct = ldapProv.getAccountByName(acctWithAlias2);
    membership = new GroupMembership();
    Maps.newHashMap();
    start = System.currentTimeMillis();
    DistributionList.updateGroupMembership(ldapProv, (ZLdapContext) null, membership, acct, via, false, /* adminGroupsOnly */
    false);
    ZimbraLog.test.info("testDLupdateGroupMembershipWithVia %s size=%d via size=%d via=%s", ZimbraLog.elapsedTime(start, System.currentTimeMillis()), membership.groupIds().size(), via.size(), via);
    dl = ldapProv.get(DistributionListBy.name, dlWithAlias);
    Assert.assertTrue(String.format("DL %s (id=%s) in membership", dl.getName(), dl.getId()), membership.groupIds().contains(dl.getId()));
    dl = ldapProv.get(DistributionListBy.name, dlWithAlias2);
    Assert.assertTrue(String.format("DL %s (id=%s) in membership", dl.getName(), dl.getId()), membership.groupIds().contains(dl.getId()));
    Assert.assertEquals(String.format("Number of DLs User %s is a member of", acctWithAlias2), 2, membership.memberOf().size());
    Assert.assertEquals(String.format("Number of vias for User %s", acctWithAlias2), 1, via.size());
}
Also used : Account(com.zimbra.cs.account.Account) GroupMembership(com.zimbra.cs.account.Provisioning.GroupMembership) DistributionList(com.zimbra.cs.account.DistributionList)

Example 8 with GroupMembership

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

the class TestLdapProvDynamicGroup method renameAccount.

/*
     * renaming an account should not affect its membership in a dynamic group
     */
@Test
public void renameAccount() throws Exception {
    Group group = createDynamicGroup(genGroupNameLocalPart());
    String groupId = group.getId();
    Account acct = provUtil.createAccount(genAcctNameLocalPart("1"), domain);
    String newAddr = TestUtil.getAddress(genAcctNameLocalPart("2"), domain.getName());
    prov.addGroupMembers(group, new String[] { acct.getName(), newAddr });
    String[] members = prov.getGroupMembers(group);
    // ensure groups contains the account
    Verify.verifyEquals(Sets.newHashSet(acct.getName(), newAddr), members);
    GroupMembership membership = prov.getGroupMembership(acct, false);
    List<String> groupIdList = membership.groupIds();
    // ensure the account is a member of the group
    assertTrue(groupIdList.contains(groupId));
    //
    // rename the account, then make sure the account is still in the group
    //
    prov.renameAccount(acct.getId(), newAddr);
    group = prov.getGroupBasic(DistributionListBy.id, groupId);
    members = prov.getGroupMembers(group);
    // ensure groups contains the account
    Verify.verifyEquals(Sets.newHashSet(newAddr), members);
    membership = prov.getGroupMembership(acct, false);
    groupIdList = membership.groupIds();
    // ensure the account is a member of the group
    assertTrue(groupIdList.contains(groupId));
}
Also used : DynamicGroup(com.zimbra.cs.account.DynamicGroup) Group(com.zimbra.cs.account.Group) LdapDynamicGroup(com.zimbra.cs.account.ldap.entry.LdapDynamicGroup) LdapAccount(com.zimbra.cs.account.ldap.entry.LdapAccount) GuestAccount(com.zimbra.cs.account.GuestAccount) Account(com.zimbra.cs.account.Account) GroupMembership(com.zimbra.cs.account.Provisioning.GroupMembership) Test(org.junit.Test)

Aggregations

GroupMembership (com.zimbra.cs.account.Provisioning.GroupMembership)8 Account (com.zimbra.cs.account.Account)7 DistributionList (com.zimbra.cs.account.DistributionList)4 Group (com.zimbra.cs.account.Group)3 DynamicGroup (com.zimbra.cs.account.DynamicGroup)2 GuestAccount (com.zimbra.cs.account.GuestAccount)2 LdapAccount (com.zimbra.cs.account.ldap.entry.LdapAccount)2 LdapDynamicGroup (com.zimbra.cs.account.ldap.entry.LdapDynamicGroup)2 Test (org.junit.Test)2 AccountBy (com.zimbra.common.account.Key.AccountBy)1 Element (com.zimbra.common.soap.Element)1 Domain (com.zimbra.cs.account.Domain)1 GlobalGrant (com.zimbra.cs.account.GlobalGrant)1 Provisioning (com.zimbra.cs.account.Provisioning)1 MemberOf (com.zimbra.cs.account.Provisioning.MemberOf)1 Right (com.zimbra.cs.account.accesscontrol.Right)1 ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)1 GetAdminConsoleUICompRequest (com.zimbra.soap.admin.message.GetAdminConsoleUICompRequest)1 DistributionListSelector (com.zimbra.soap.admin.type.DistributionListSelector)1 AccountSelector (com.zimbra.soap.type.AccountSelector)1