Search in sources :

Example 56 with DistributionList

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

the class TestLdapProvAttrCallback method accountStatus.

@Test
public void accountStatus() throws Exception {
    String ACCT_NAME_LOCALPART = Names.makeAccountNameLocalPart(genAcctNameLocalPart("account"));
    Account acct = createAccount(ACCT_NAME_LOCALPART);
    String ALIAS_LOCALPART_1 = Names.makeAliasNameLocalPart(genAcctNameLocalPart("alias-1"));
    String ALIAS_NAME_1 = TestUtil.getAddress(ALIAS_LOCALPART_1, domain.getName()).toLowerCase();
    String ALIAS_LOCALPART_2 = Names.makeAliasNameLocalPart(genAcctNameLocalPart("alias-2"));
    String ALIAS_NAME_2 = TestUtil.getAddress(ALIAS_LOCALPART_2, domain.getName()).toLowerCase();
    prov.addAlias(acct, ALIAS_NAME_1);
    prov.addAlias(acct, ALIAS_NAME_2);
    String DL_NAME_LOCALPART = Names.makeDLNameLocalPart("accountStatus-dl");
    DistributionList dl = createDistributionList(DL_NAME_LOCALPART);
    dl.addMembers(new String[] { acct.getName(), ALIAS_NAME_1, ALIAS_NAME_2 });
    prov.flushCache(CacheEntryType.account, null);
    prov.flushCache(CacheEntryType.group, null);
    Set<String> allMembers = dl.getAllMembersSet();
    assertEquals(3, allMembers.size());
    assertTrue(allMembers.contains(acct.getName()));
    assertTrue(allMembers.contains(ALIAS_NAME_1));
    assertTrue(allMembers.contains(ALIAS_NAME_2));
    Map<String, Object> attrs = new HashMap<String, Object>();
    attrs.put(Provisioning.A_zimbraAccountStatus, ZAttrProvisioning.AccountStatus.closed.name());
    prov.modifyAttrs(acct, attrs);
    prov.flushCache(CacheEntryType.account, null);
    prov.flushCache(CacheEntryType.group, null);
    dl = prov.get(Key.DistributionListBy.id, dl.getId());
    allMembers = dl.getAllMembersSet();
    assertEquals(0, allMembers.size());
    deleteAccount(acct);
}
Also used : Account(com.zimbra.cs.account.Account) HashMap(java.util.HashMap) DistributionList(com.zimbra.cs.account.DistributionList)

Example 57 with DistributionList

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

the class TestLdapProvAlias method removeDistributionListAlias.

@Test
public void removeDistributionListAlias() throws Exception {
    String DL_NAME_LOCALPART = Names.makeDLNameLocalPart(genGroupNameLocalPart("dl"));
    DistributionList dl = createDistributionList(DL_NAME_LOCALPART);
    String DL_ID = dl.getId();
    String ALIAS_LOCALPART = Names.makeAliasNameLocalPart(genGroupNameLocalPart("alias"));
    String ALIAS_NAME = TestUtil.getAddress(ALIAS_LOCALPART, domain.getName());
    prov.addAlias(dl, ALIAS_NAME);
    prov.flushCache(CacheEntryType.group, null);
    DistributionList dlByAlias = prov.get(Key.DistributionListBy.name, ALIAS_NAME);
    assertEquals(DL_ID, dlByAlias.getId());
    prov.removeAlias(dl, ALIAS_NAME);
    prov.flushCache(CacheEntryType.group, null);
    dlByAlias = prov.get(Key.DistributionListBy.name, ALIAS_NAME);
    assertNull(dlByAlias);
    deleteDistributionList(dl);
}
Also used : DistributionList(com.zimbra.cs.account.DistributionList)

Example 58 with DistributionList

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

the class TestLdapProvDistributionList method removeMembers.

@Test
public void removeMembers() throws Exception {
    String DL_NAME_LOCALPART = Names.makeDLNameLocalPart(genGroupNameLocalPart());
    String MEMBER_1 = "member_1@test.com";
    String MEMBER_2 = "member_2@test.com";
    String MEMBER_3 = "member_3@test.com";
    String MEMBER_4 = "member_4@test.com";
    Map<String, Object> attrs = new HashMap<String, Object>();
    // add initial members
    StringUtil.addToMultiMap(attrs, Provisioning.A_zimbraMailForwardingAddress, MEMBER_1);
    StringUtil.addToMultiMap(attrs, Provisioning.A_zimbraMailForwardingAddress, MEMBER_2);
    StringUtil.addToMultiMap(attrs, Provisioning.A_zimbraMailForwardingAddress, MEMBER_3);
    StringUtil.addToMultiMap(attrs, Provisioning.A_zimbraMailForwardingAddress, MEMBER_4);
    DistributionList dl = createDistributionList(DL_NAME_LOCALPART, attrs);
    prov.removeMembers(dl, new String[] { MEMBER_3, MEMBER_4 });
    Set<String> allMembers = dl.getAllMembersSet();
    assertEquals(2, allMembers.size());
    assertTrue(allMembers.contains(MEMBER_1));
    assertTrue(allMembers.contains(MEMBER_2));
    deleteDistributionList(dl);
}
Also used : HashMap(java.util.HashMap) DistributionList(com.zimbra.cs.account.DistributionList)

Example 59 with DistributionList

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

the class TestLdapProvDistributionList method getDistributionListById.

private void getDistributionListById(String id) throws Exception {
    prov.flushCache(CacheEntryType.group, null);
    DistributionList dl = prov.get(Key.DistributionListBy.id, id);
    assertNotNull(dl);
    assertEquals(id, dl.getId());
}
Also used : DistributionList(com.zimbra.cs.account.DistributionList)

Example 60 with DistributionList

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

the class TestLdapProvDistributionList method renameDistributionListDomainChanged.

@Test
public void renameDistributionListDomainChanged() throws Exception {
    String DL_NAME_LOCALPART = Names.makeDLNameLocalPart(genGroupNameLocalPart());
    String NEW_DOMAIN_NAME = genDomainSegmentName() + "." + BASE_DOMAIN_NAME;
    Domain newDomain = provUtil.createDomain(NEW_DOMAIN_NAME, null);
    String DL_NEW_NAME_LOCALPART = Names.makeDLNameLocalPart(genGroupNameLocalPart("new"));
    String DL_NEW_NAME = TestUtil.getAddress(DL_NEW_NAME_LOCALPART, newDomain.getName()).toLowerCase();
    DistributionList dl = createDistributionList(DL_NAME_LOCALPART);
    String DL_ID = dl.getId();
    // set zimbraPrefAllowAddressForDelegatedSender
    Map<String, Object> attrs = Maps.newHashMap();
    attrs.put(Provisioning.A_zimbraPrefAllowAddressForDelegatedSender, dl.getName());
    prov.modifyAttrs(dl, attrs);
    prov.renameDistributionList(DL_ID, DL_NEW_NAME);
    getDistributionListById(DL_ID);
    getDistributionListByName(DL_NEW_NAME);
    // make sure zimbraPrefAllowAddressForDelegatedSender is updated
    DistributionList renamedDl = prov.get(DistributionListBy.name, DL_NEW_NAME);
    Set<String> addrsForDelegatedSender = renamedDl.getMultiAttrSet(Provisioning.A_zimbraPrefAllowAddressForDelegatedSender);
    assertEquals(1, addrsForDelegatedSender.size());
    assertTrue(addrsForDelegatedSender.contains(DL_NEW_NAME));
    deleteDistributionList(dl);
    provUtil.deleteDomain(newDomain);
}
Also used : Domain(com.zimbra.cs.account.Domain) DistributionList(com.zimbra.cs.account.DistributionList)

Aggregations

DistributionList (com.zimbra.cs.account.DistributionList)120 Account (com.zimbra.cs.account.Account)58 Domain (com.zimbra.cs.account.Domain)43 HashMap (java.util.HashMap)24 Test (org.junit.Test)24 Provisioning (com.zimbra.cs.account.Provisioning)22 NamedEntry (com.zimbra.cs.account.NamedEntry)18 HashSet (java.util.HashSet)18 ArrayList (java.util.ArrayList)14 ServiceException (com.zimbra.common.service.ServiceException)13 AccountServiceException (com.zimbra.cs.account.AccountServiceException)13 Right (com.zimbra.cs.account.accesscontrol.Right)12 DynamicGroup (com.zimbra.cs.account.DynamicGroup)10 LdapDistributionList (com.zimbra.cs.account.ldap.entry.LdapDistributionList)10 Group (com.zimbra.cs.account.Group)9 GuestAccount (com.zimbra.cs.account.GuestAccount)9 LdapProv (com.zimbra.cs.account.ldap.LdapProv)8 List (java.util.List)7 Entry (com.zimbra.cs.account.Entry)6 LdapEntry (com.zimbra.cs.account.ldap.entry.LdapEntry)6