use of com.zimbra.cs.account.Group in project zm-mailbox by Zimbra.
the class TestLdapProvDynamicGroup method getGroupMembership.
/*
* Test Provisioning.getGroupMembership
*/
@Test
public void getGroupMembership() throws Exception {
Group group = createDynamicGroup(genGroupNameLocalPart());
Group otherDynamicGroup = createDynamicGroup(genGroupNameLocalPart("other-dynamic"));
Group otherStaticGroup = provUtil.createDistributionList(genGroupNameLocalPart("other-static"), domain);
Account acct = provUtil.createAccount(genAcctNameLocalPart(), domain);
String externalAddr = "user@external.com";
GuestAccount guestAcct = new GuestAccount(externalAddr, null);
prov.addGroupMembers(group, new String[] { acct.getName(), externalAddr });
prov.addGroupMembers(otherDynamicGroup, new String[] { acct.getName(), externalAddr });
prov.addGroupMembers(otherStaticGroup, new String[] { acct.getName(), externalAddr });
Set<String> expectedMemberOf = Sets.newHashSet(Verify.makeResultStr(group.getId(), Boolean.FALSE), Verify.makeResultStr(otherDynamicGroup.getId(), Boolean.FALSE), Verify.makeResultStr(otherStaticGroup.getId(), Boolean.FALSE));
Set<String> expectedIds = Sets.newHashSet(Verify.makeResultStr(group.getId()), Verify.makeResultStr(otherDynamicGroup.getId()), Verify.makeResultStr(otherStaticGroup.getId()));
/*
* verify membership for acct
*/
GroupMembership membership = prov.getGroupMembership(acct, false);
List<MemberOf> memberOfList = membership.memberOf();
List<String> groupIdList = membership.groupIds();
Set<String> actualMemberOf = Sets.newHashSet();
for (MemberOf memberOf : memberOfList) {
actualMemberOf.add(Verify.makeResultStr(memberOf.getId(), memberOf.isAdminGroup()));
}
Set<String> actualIds = Sets.newHashSet();
for (String id : groupIdList) {
actualIds.add(Verify.makeResultStr(id));
}
Verify.verifyEquals(expectedMemberOf, actualMemberOf);
Verify.verifyEquals(expectedIds, actualIds);
/*
* verify membership for guest acct
*/
membership = prov.getGroupMembership(guestAcct, false);
memberOfList = membership.memberOf();
groupIdList = membership.groupIds();
actualMemberOf = Sets.newHashSet();
for (MemberOf memberOf : memberOfList) {
actualMemberOf.add(Verify.makeResultStr(memberOf.getId(), memberOf.isAdminGroup()));
}
actualIds = Sets.newHashSet();
for (String id : groupIdList) {
actualIds.add(Verify.makeResultStr(id));
}
Verify.verifyEquals(expectedMemberOf, actualMemberOf);
Verify.verifyEquals(expectedIds, actualIds);
}
use of com.zimbra.cs.account.Group in project zm-mailbox by Zimbra.
the class TestLdapProvDynamicGroup method addMembersInternalAddress.
/*
* Test add internal non-account address as members - not allowed
*/
@Test
public void addMembersInternalAddress() throws Exception {
Group group = createDynamicGroup(genGroupNameLocalPart());
String otherDynGroupLocalPart = genGroupNameLocalPart("other-dynamic");
Group otherDynamicGroup = createDynamicGroup(otherDynGroupLocalPart);
Group otherStaticGroup = provUtil.createDistributionList(genGroupNameLocalPart("other-static"), domain);
String errCode = null;
try {
prov.addGroupMembers(group, new String[] { otherDynamicGroup.getName() });
} catch (ServiceException e) {
errCode = e.getCode();
}
assertEquals(ServiceException.INVALID_REQUEST, errCode);
errCode = null;
try {
prov.addGroupMembers(group, new String[] { otherStaticGroup.getName() });
} catch (ServiceException e) {
errCode = e.getCode();
}
assertEquals(ServiceException.INVALID_REQUEST, errCode);
// dynamic unit of a dynamic group
errCode = null;
try {
String addr = otherDynGroupLocalPart + ".__internal__@" + domain.getName();
prov.addGroupMembers(group, new String[] { addr });
} catch (ServiceException e) {
errCode = e.getCode();
}
assertEquals(ServiceException.INVALID_REQUEST, errCode);
}
use of com.zimbra.cs.account.Group in project zm-mailbox by Zimbra.
the class TestLdapProvDynamicGroup method testGetMemberAddrs.
private void testGetMemberAddrs(boolean dynamic) throws Exception {
/*
* group has both internal and external members
*/
Group group = provUtil.createGroup(genGroupNameLocalPart(seq), domain, dynamic);
Account acct1 = provUtil.createAccount(genAcctNameLocalPart(seq), domain);
Account acct2 = provUtil.createAccount(genAcctNameLocalPart(seq), domain);
String externalAddr1 = "user1@external.com";
String externalAddr2 = "user2@external.com";
prov.addGroupMembers(group, new String[] { acct1.getName(), acct2.getName(), externalAddr1, externalAddr2 });
GroupMemberEmailAddrs addrs = prov.getMemberAddrs(group);
assertNull(addrs.groupAddr());
Verify.verifyEquals(Sets.newHashSet(acct1.getName(), acct2.getName()), addrs.internalAddrs());
Verify.verifyEquals(Sets.newHashSet(externalAddr1, externalAddr2), addrs.externalAddrs());
/*
* group has only internal members
*/
group = provUtil.createGroup(genGroupNameLocalPart(seq), domain, dynamic);
prov.addGroupMembers(group, new String[] { acct1.getName(), acct2.getName() });
addrs = prov.getMemberAddrs(group);
assertEquals(group.getName(), addrs.groupAddr());
assertNull(addrs.internalAddrs());
assertNull(addrs.externalAddrs());
/*
* group has only external members
*/
group = provUtil.createGroup(genGroupNameLocalPart(seq), domain, dynamic);
prov.addGroupMembers(group, new String[] { externalAddr1, externalAddr2 });
addrs = prov.getMemberAddrs(group);
assertNull(addrs.groupAddr());
assertNull(addrs.internalAddrs());
Verify.verifyEquals(Sets.newHashSet(externalAddr1, externalAddr2), addrs.externalAddrs());
/*
* group has no member
*/
group = provUtil.createGroup(genGroupNameLocalPart(seq), domain, dynamic);
addrs = prov.getMemberAddrs(group);
assertEquals(group.getName(), addrs.groupAddr());
assertNull(addrs.internalAddrs());
assertNull(addrs.externalAddrs());
}
use of com.zimbra.cs.account.Group in project zm-mailbox by Zimbra.
the class TestLdapProvDynamicGroup method addMemberExisting.
/*
* Test add existing members
*/
@Test
public void addMemberExisting() throws Exception {
Group group = createDynamicGroup(genGroupNameLocalPart());
Account acct1 = provUtil.createAccount(genAcctNameLocalPart("1"), domain);
Account acct2 = provUtil.createAccount(genAcctNameLocalPart("2"), domain);
String extAddr1 = "user1@external.com";
String extAddr2 = "user2@external.com";
Set<String> expected = Sets.newHashSet(acct1.getName(), acct2.getName(), extAddr1, extAddr2);
prov.addGroupMembers(group, new String[] { acct1.getName(), acct2.getName(), extAddr1, extAddr2 });
String[] members = prov.getGroupMembers(group);
Verify.verifyEquals(expected, members);
// add again, should get back the same members
prov.addGroupMembers(group, new String[] { acct1.getName(), acct2.getName(), extAddr1, extAddr2 });
members = prov.getGroupMembers(group);
Verify.verifyEquals(expected, members);
}
use of com.zimbra.cs.account.Group in project zm-mailbox by Zimbra.
the class TestLdapProvRenameDomain method setupDLs.
/*
* add all accounts, nested Dls, and their aliases of the domain to all DLs of all domains
*/
private void setupDLs(int domainIdx) throws Exception {
String domainName = DOMAIN_NAME(domainIdx);
System.out.println("crossLinkDomain: " + domainName);
// Domain sourceDomain = mProv.get(Provisioning.DomainBy.name, domainName);
List<String>[][] nestedDLMembers = new ArrayList[NUM_DOMAINS][NUM_DLS_NESTED];
List<String>[][] topDLMembers = new ArrayList[NUM_DOMAINS][NUM_DLS_TOP];
List<String>[][] dynamicGroupMembers = new ArrayList[NUM_DOMAINS][NUM_DYNAMIC_GROUPS];
for (int d = 0; d < NUM_DOMAINS; d++) {
for (int nd = 0; nd < NUM_DLS_TOP; nd++) {
nestedDLMembers[d][nd] = new ArrayList();
}
for (int td = 0; td < NUM_DLS_TOP; td++) {
topDLMembers[d][td] = new ArrayList();
}
for (int dd = 0; dd < NUM_DYNAMIC_GROUPS; dd++) {
dynamicGroupMembers[d][dd] = new ArrayList();
}
}
// entries is set to the dynamic group.
for (int a = 0; a < NUM_ACCOUNTS; a++) {
Set<String> members = ACCOUNT_NAMES(a, domainIdx, false);
for (int d = 0; d < NUM_DOMAINS; d++) {
for (int nd = 0; nd < NUM_DLS_NESTED; nd++) {
for (String m : members) nestedDLMembers[d][nd].add(m);
}
for (int td = 0; td < NUM_DLS_TOP; td++) {
for (String m : members) topDLMembers[d][td].add(m);
}
for (int dd = 0; dd < NUM_DYNAMIC_GROUPS; dd++) {
for (String m : members) dynamicGroupMembers[d][dd].add(m);
}
}
}
// add nested dls and their aliases to top dls
for (int nd = 0; nd < NUM_DLS_NESTED; nd++) {
Set<String> members = NESTED_DL_NAMES(nd, domainIdx, false);
for (int d = 0; d < NUM_DOMAINS; d++) {
for (int td = 0; td < NUM_DLS_TOP; td++) {
for (String m : members) topDLMembers[d][td].add(m);
}
}
}
// now add them
for (int d = 0; d < NUM_DOMAINS; d++) {
for (int nd = 0; nd < NUM_DLS_NESTED; nd++) {
DistributionList dl = prov.get(Key.DistributionListBy.name, NESTED_DL_NAME(nd, d));
prov.addMembers(dl, nestedDLMembers[d][nd].toArray(new String[0]));
}
for (int td = 0; td < NUM_DLS_TOP; td++) {
DistributionList dl = prov.get(Key.DistributionListBy.name, TOP_DL_NAME(td, d));
prov.addMembers(dl, topDLMembers[d][td].toArray(new String[0]));
}
for (int dd = 0; dd < NUM_DYNAMIC_GROUPS; dd++) {
Group dynGroup = prov.getGroup(Key.DistributionListBy.name, DYNAMIC_GROUP_NAME(dd, d));
prov.addGroupMembers(dynGroup, dynamicGroupMembers[d][dd].toArray(new String[0]));
}
}
}
Aggregations