Search in sources :

Example 16 with DistributionList

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

the class LdapProvisioning method renameAddressesInAllDistributionLists.

protected void renameAddressesInAllDistributionLists(Map<String, String> changedPairs) {
    String[] oldAddrs = changedPairs.keySet().toArray(new String[0]);
    String[] newAddrs = changedPairs.values().toArray(new String[0]);
    List<DistributionList> lists = null;
    Map<String, String[]> attrs = null;
    try {
        lists = getAllDistributionListsForAddresses(oldAddrs, false);
    } catch (ServiceException se) {
        ZimbraLog.account.warn("unable to rename addr " + oldAddrs.toString() + " in all DLs ", se);
        return;
    }
    for (DistributionList list : lists) {
        // removeMember/addMember might have to update an entry's zimbraMemberId twice
        if (attrs == null) {
            attrs = new HashMap<String, String[]>();
            attrs.put("-" + Provisioning.A_zimbraMailForwardingAddress, oldAddrs);
            attrs.put("+" + Provisioning.A_zimbraMailForwardingAddress, newAddrs);
        }
        try {
            modifyAttrs(list, attrs);
        //list.removeMember(oldName)
        //list.addMember(newName);
        } catch (ServiceException se) {
            // log warning an continue
            ZimbraLog.account.warn("unable to rename " + oldAddrs.toString() + " to " + newAddrs.toString() + " in DL " + list.getName(), se);
        }
    }
}
Also used : AccountServiceException(com.zimbra.cs.account.AccountServiceException) AuthFailedServiceException(com.zimbra.cs.account.AccountServiceException.AuthFailedServiceException) ServiceException(com.zimbra.common.service.ServiceException) LdapDistributionList(com.zimbra.cs.account.ldap.entry.LdapDistributionList) DistributionList(com.zimbra.cs.account.DistributionList)

Example 17 with DistributionList

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

the class SoapProvisioning method getDistributionLists.

private Set<String> getDistributionLists(Account acct, boolean directOnly) throws ServiceException {
    Set<String> dls = new HashSet<String>();
    List<DistributionList> lists = getDistributionLists(acct, directOnly, null);
    for (DistributionList dl : lists) {
        dls.add(dl.getId());
    }
    dls = Collections.unmodifiableSet(dls);
    return dls;
}
Also used : HashSet(java.util.HashSet) DistributionList(com.zimbra.cs.account.DistributionList)

Example 18 with DistributionList

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

the class TestGroups method setUp.

@Override
public void setUp() throws Exception {
    ldapProv = (LdapProvisioning) Provisioning.getInstance();
    if (soapProv == null) {
        soapProv = TestUtil.newSoapProvisioning();
    }
    tearDown();
    domain = createDomain(domainName);
    domain1 = createDomain(domainName1);
    domain2 = createDomain(domainName2);
    for (int cnt = 1; cnt <= NUM_COS; cnt++) {
        createCos(String.format(cosPatt, cnt));
    }
    groups.clear();
    for (int cnt = 1; cnt <= NUM_CUSTOM_DL; cnt++) {
        TestUtil.deleteAccount(String.format(customDLPatt, cnt));
        Group grp = createCustomDynamicGroupWhoseMembersShareCOS(String.format(customDLPatt, cnt), String.format(cosPatt, cnt));
        groups.put(grp.getId(), grp);
    }
    List<String> staticMembers = Lists.newArrayList();
    List<String> dynamicMembers = Lists.newArrayList();
    for (int cnt = 1; cnt <= NUM_ACCOUNTS; cnt++) {
        int cosChoice = cnt % NUM_COS + 1;
        createAccountAsMemberOfCOS(String.format(acctPatt, cnt), String.format(cosPatt, cosChoice));
        if (cnt % 2 == 0) {
            staticMembers.add(String.format(acctPatt, cnt));
        }
        if (cnt % 3 == 0) {
            dynamicMembers.add(String.format(acctPatt, cnt));
        }
    }
    createAccountWithAlias(acctWithAlias, acctAlias);
    createAccountWithAlias(acctWithAlias2, acctAlias2);
    staticMembers.add(acctAlias);
    DistributionList dlalias = createDistributionList(dlWithAlias);
    dlalias.addAlias(dlAlias);
    DistributionList dlalias2 = createDistributionList(dlWithAlias2);
    dlalias2.addAlias(dlAlias2);
    String[] aliasmems = { dlAlias2 };
    dlalias.addMembers(aliasmems);
    String[] aliasmems2 = { acctAlias, acctAlias2 };
    dlalias2.addMembers(aliasmems2);
    for (int cnt = 1; cnt <= NUM_NORMAL_DL; cnt++) {
        DistributionList dl = createDistributionList(String.format(normalDLPatt, cnt));
        groups.put(dl.getId(), dl);
        dl.addMembers(staticMembers.toArray(new String[staticMembers.size()]));
        for (String mem : staticMembers) {
            ZimbraLog.test.info("SETUP Distribution List %s has member acct=%s", dl.getName(), mem);
        }
    }
    for (int cnt = 1; cnt <= NUM_DYNAMIC_DL; cnt++) {
        Group grp = createDynamicGroup(String.format(dynamicDLPatt, cnt));
        groups.put(grp.getId(), grp);
        ldapProv.addGroupMembers(grp, dynamicMembers.toArray(new String[dynamicMembers.size()]));
        for (String mem : dynamicMembers) {
            ZimbraLog.test.info("SETUP Dynamic Group %s has member acct=%s", grp.getName(), mem);
        }
    }
    String groupName = String.format(customDLPatt, 1);
    // account4 should match this
    // account2 should NOT match this
    // account3 should NOT match this
    ldapProv.grantRight("domain", /* targetType */
    TargetBy.name, /* targetBy */
    domain.getName(), /* target */
    "grp", /* granteeType */
    GranteeSelector.GranteeBy.name, /* granteeBy */
    groupName, /* grantee */
    null, /* secret */
    RightConsts.RT_createDistList, /* right */
    null);
    ZimbraLog.test.info("SETUP Granted %s to Group %s for dom=%s", RightConsts.RT_createDistList, groupName, domain.getName());
    // account4 should match this
    // account2 should match this
    // account3 should NOT match this
    groupName = String.format(normalDLPatt, 1);
    ldapProv.grantRight("domain", /* targetType */
    TargetBy.name, /* targetBy */
    domain1.getName(), /* target */
    "grp", /* granteeType */
    GranteeSelector.GranteeBy.name, /* granteeBy */
    groupName, /* grantee */
    null, /* secret */
    RightConsts.RT_createDistList, /* right */
    null);
    ZimbraLog.test.info("SETUP Granted %s to Group %s for dom=%s", RightConsts.RT_createDistList, groupName, domain.getName());
    ldapProv.grantRight("domain", /* targetType */
    TargetBy.name, /* targetBy */
    domain.getName(), /* target */
    "grp", /* granteeType */
    GranteeSelector.GranteeBy.name, /* granteeBy */
    groupName, /* grantee */
    null, /* secret */
    RightConsts.RT_sendToDistList, /* right */
    null);
    ZimbraLog.test.info("SETUP Granted %s to Group %s for dom=%s", RightConsts.RT_sendToDistList, groupName, domain.getName());
    // account4 should NOT match this
    // account2 should NOT match this
    // account3 should match this
    groupName = String.format(dynamicDLPatt, 1);
    ldapProv.grantRight("domain", /* targetType */
    TargetBy.name, /* targetBy */
    domain2.getName(), /* target */
    "grp", /* granteeType */
    GranteeSelector.GranteeBy.name, /* granteeBy */
    groupName, /* grantee */
    null, /* secret */
    RightConsts.RT_createDistList, /* right */
    null);
    ZimbraLog.test.info("SETUP Granted %s to Group %s for dom=%s", RightConsts.RT_createDistList, groupName, domain.getName());
    // account4 should NOT match this
    // account2 should NOT match this
    // account3 should match this
    groupName = String.format(dynamicDLPatt, 2);
    ldapProv.grantRight("domain", /* targetType */
    TargetBy.name, /* targetBy */
    domain2.getName(), /* target */
    "grp", /* granteeType */
    GranteeSelector.GranteeBy.name, /* granteeBy */
    groupName, /* grantee */
    null, /* secret */
    RightConsts.RT_sendToDistList, /* right */
    null);
    ZimbraLog.test.info("SETUP Granted %s to Group %s for dom=%s", RightConsts.RT_sendToDistList, groupName, domain.getName());
}
Also used : Group(com.zimbra.cs.account.Group) DistributionList(com.zimbra.cs.account.DistributionList)

Example 19 with DistributionList

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

the class TestGalGroupMembers method cleanupZimbraDomain.

private static void cleanupZimbraDomain() throws Exception {
    Provisioning prov = Provisioning.getInstance();
    GalTestUtil.disableGalSyncAccount(prov, ZIMBRA_DOMAIN);
    // delete the test user
    String userAddr = TestUtil.getAddress(USER, ZIMBRA_DOMAIN);
    Account userAcct = prov.get(AccountBy.name, userAddr);
    if (prov.get(AccountBy.name, userAddr) != null) {
        prov.deleteAccount(userAcct.getId());
    }
    for (ZimbraGroupMembers member : ZimbraGroupMembers.values()) {
        if (member.isZimbraAccount()) {
            String addr = member.getAddress();
            Account acct = prov.get(AccountBy.name, addr);
            if (acct != null) {
                prov.deleteAccount(acct.getId());
            }
        }
    }
    String groupAddr = TestUtil.getAddress(ZIMBRA_GROUP, ZIMBRA_DOMAIN);
    DistributionList group = prov.get(Key.DistributionListBy.name, groupAddr);
    if (group != null) {
        prov.deleteDistributionList(group.getId());
    }
    Domain domain = prov.get(Key.DomainBy.name, ZIMBRA_DOMAIN);
    if (domain != null) {
        ZimbraLog.test.info("Deleting domain " + ZIMBRA_DOMAIN);
        prov.deleteDomain(domain.getId());
    }
}
Also used : Account(com.zimbra.cs.account.Account) Domain(com.zimbra.cs.account.Domain) Provisioning(com.zimbra.cs.account.Provisioning) DistributionList(com.zimbra.cs.account.DistributionList)

Example 20 with DistributionList

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

the class TestGalGroupMembers method cleanupExternalDomain.

private static void cleanupExternalDomain() throws Exception {
    Provisioning prov = Provisioning.getInstance();
    String groupAddr = TestUtil.getAddress(EXTERNAL_GROUP, EXTERNAL_DOMAIN);
    DistributionList group = prov.get(Key.DistributionListBy.name, groupAddr);
    if (group != null) {
        prov.deleteDistributionList(group.getId());
    }
    Domain domain = prov.get(Key.DomainBy.name, EXTERNAL_DOMAIN);
    if (domain != null) {
        ZimbraLog.test.info("Deleting domain " + EXTERNAL_DOMAIN);
        prov.deleteDomain(domain.getId());
    }
}
Also used : Domain(com.zimbra.cs.account.Domain) Provisioning(com.zimbra.cs.account.Provisioning) 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