Search in sources :

Example 11 with DistributionList

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

the class LdapProvisioning method getDistributionListIds.

private Set<String> getDistributionListIds(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) LdapDistributionList(com.zimbra.cs.account.ldap.entry.LdapDistributionList) DistributionList(com.zimbra.cs.account.DistributionList)

Example 12 with DistributionList

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

the class LdapProvisioning method getDLBasic.

private DistributionList getDLBasic(Key.DistributionListBy keyType, String key, ZLdapContext zlc) throws ServiceException {
    Group group = getGroupFromCache(keyType, key);
    if (group instanceof DistributionList) {
        return (DistributionList) group;
    } else if (group instanceof DynamicGroup) {
        return null;
    }
    // not in cache, fetch from LDAP
    DistributionList dl = null;
    switch(keyType) {
        case id:
            dl = getDistributionListByQuery(mDIT.mailBranchBaseDN(), filterFactory.distributionListById(key), zlc, true);
            break;
        case name:
            dl = getDistributionListByQuery(mDIT.mailBranchBaseDN(), filterFactory.distributionListByName(key), zlc, true);
            break;
        default:
            return null;
    }
    if (dl != null) {
        putInGroupCache(dl);
    }
    return dl;
}
Also used : Group(com.zimbra.cs.account.Group) DynamicGroup(com.zimbra.cs.account.DynamicGroup) LdapDynamicGroup(com.zimbra.cs.account.ldap.entry.LdapDynamicGroup) DynamicGroup(com.zimbra.cs.account.DynamicGroup) LdapDynamicGroup(com.zimbra.cs.account.ldap.entry.LdapDynamicGroup) LdapDistributionList(com.zimbra.cs.account.ldap.entry.LdapDistributionList) DistributionList(com.zimbra.cs.account.DistributionList)

Example 13 with DistributionList

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

the class LdapProvisioning method getAllDistributionListsForAddresses.

@SuppressWarnings("unchecked")
private List<DistributionList> getAllDistributionListsForAddresses(String[] addrs, boolean basicAttrsOnly) throws ServiceException {
    if (addrs == null || addrs.length == 0)
        return new ArrayList<DistributionList>();
    String[] attrs = basicAttrsOnly ? BASIC_DL_ATTRS : null;
    SearchDirectoryOptions searchOpts = new SearchDirectoryOptions(attrs);
    searchOpts.setFilter(filterFactory.distributionListsByMemberAddrs(addrs));
    searchOpts.setTypes(ObjectType.distributionlists);
    searchOpts.setSortOpt(SortOpt.SORT_ASCENDING);
    return (List<DistributionList>) searchDirectoryInternal(searchOpts);
}
Also used : SearchDirectoryOptions(com.zimbra.cs.account.SearchDirectoryOptions) LdapDistributionList(com.zimbra.cs.account.ldap.entry.LdapDistributionList) ArrayList(java.util.ArrayList) List(java.util.List) DistributionList(com.zimbra.cs.account.DistributionList) LdapDistributionList(com.zimbra.cs.account.ldap.entry.LdapDistributionList) DistributionList(com.zimbra.cs.account.DistributionList)

Example 14 with DistributionList

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

the class LdapProvisioning method getAllAddressesOfEntry.

//
// returns the primary address and all aliases of the named account or DL
//
private AddrsOfEntry getAllAddressesOfEntry(String name) {
    String primary = null;
    String[] aliases = null;
    AddrsOfEntry addrs = new AddrsOfEntry();
    try {
        // bug 56621.  Do not count implicit aliases (aliases resolved by alias domain)
        // when dealing with distribution list members.
        Account acct = getAccountByName(name, false, false);
        if (acct != null) {
            addrs.setIsAccount(true);
            primary = acct.getName();
            aliases = acct.getMailAlias();
        } else {
            DistributionList dl = get(Key.DistributionListBy.name, name);
            if (dl != null) {
                primary = dl.getName();
                aliases = dl.getAliases();
            }
        }
    } catch (ServiceException se) {
    // swallow any exception and go on
    }
    if (primary != null)
        addrs.setPrimary(primary);
    if (aliases != null)
        addrs.addAll(aliases);
    return addrs;
}
Also used : Account(com.zimbra.cs.account.Account) GuestAccount(com.zimbra.cs.account.GuestAccount) LdapAccount(com.zimbra.cs.account.ldap.entry.LdapAccount) 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 15 with DistributionList

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

the class LdapProvisioning method createDistributionList.

private DistributionList createDistributionList(String listAddress, Map<String, Object> listAttrs, Account creator) throws ServiceException {
    SpecialAttrs specialAttrs = mDIT.handleSpecialAttrs(listAttrs);
    String baseDn = specialAttrs.getLdapBaseDn();
    listAddress = listAddress.toLowerCase().trim();
    String[] parts = listAddress.split("@");
    if (parts.length != 2)
        throw ServiceException.INVALID_REQUEST("must be valid list address: " + listAddress, null);
    String localPart = parts[0];
    String domain = parts[1];
    domain = IDNUtil.toAsciiDomainName(domain);
    listAddress = localPart + "@" + domain;
    validEmailAddress(listAddress);
    CallbackContext callbackContext = new CallbackContext(CallbackContext.Op.CREATE);
    callbackContext.setCreatingEntryName(listAddress);
    AttributeManager.getInstance().preModify(listAttrs, null, callbackContext, true);
    ZLdapContext zlc = null;
    try {
        zlc = LdapClient.getContext(LdapServerType.MASTER, LdapUsage.CREATE_DISTRIBUTIONLIST);
        Domain d = getDomainByAsciiName(domain, zlc);
        if (d == null)
            throw AccountServiceException.NO_SUCH_DOMAIN(domain);
        if (!d.isLocal()) {
            throw ServiceException.INVALID_REQUEST("domain type must be local", null);
        }
        ZMutableEntry entry = LdapClient.createMutableEntry();
        entry.mapToAttrs(listAttrs);
        Set<String> ocs = LdapObjectClass.getDistributionListObjectClasses(this);
        entry.addAttr(A_objectClass, ocs);
        String zimbraIdStr = LdapUtil.generateUUID();
        entry.setAttr(A_zimbraId, zimbraIdStr);
        entry.setAttr(A_zimbraCreateTimestamp, LdapDateUtil.toGeneralizedTime(new Date()));
        entry.setAttr(A_mail, listAddress);
        // unlike accounts (which have a zimbraMailDeliveryAddress for the primary,
        // and zimbraMailAliases only for aliases), DLs use zibraMailAlias for both.
        // Postfix uses these two attributes to route mail, and zimbraMailDeliveryAddress
        // indicates that something has a physical mailbox, which DLs don't.
        entry.setAttr(A_zimbraMailAlias, listAddress);
        // by default a distribution list is always created enabled
        if (!entry.hasAttribute(Provisioning.A_zimbraMailStatus)) {
            entry.setAttr(A_zimbraMailStatus, MAIL_STATUS_ENABLED);
        }
        String displayName = entry.getAttrString(Provisioning.A_displayName);
        if (displayName != null) {
            entry.setAttr(A_cn, displayName);
        }
        entry.setAttr(A_uid, localPart);
        setGroupHomeServer(entry, creator);
        String dn = mDIT.distributionListDNCreate(baseDn, entry.getAttributes(), localPart, domain);
        entry.setDN(dn);
        zlc.createEntry(entry);
        DistributionList dlist = getDLBasic(DistributionListBy.id, zimbraIdStr, zlc);
        if (dlist != null) {
            AttributeManager.getInstance().postModify(listAttrs, dlist, callbackContext);
            removeExternalAddrsFromAllDynamicGroups(dlist.getAllAddrsSet(), zlc);
            allDLs.addGroup(dlist);
        } else {
            throw ServiceException.FAILURE("unable to get distribution list after creating LDAP entry: " + listAddress, null);
        }
        return dlist;
    } catch (LdapEntryAlreadyExistException nabe) {
        throw AccountServiceException.DISTRIBUTION_LIST_EXISTS(listAddress);
    } catch (LdapException e) {
        throw e;
    } catch (AccountServiceException e) {
        throw e;
    } catch (ServiceException e) {
        throw ServiceException.FAILURE("unable to create distribution list: " + listAddress, e);
    } finally {
        LdapClient.closeContext(zlc);
    }
}
Also used : ZMutableEntry(com.zimbra.cs.ldap.ZMutableEntry) LdapEntryAlreadyExistException(com.zimbra.cs.ldap.LdapException.LdapEntryAlreadyExistException) ZLdapContext(com.zimbra.cs.ldap.ZLdapContext) Date(java.util.Date) AccountServiceException(com.zimbra.cs.account.AccountServiceException) AccountServiceException(com.zimbra.cs.account.AccountServiceException) AuthFailedServiceException(com.zimbra.cs.account.AccountServiceException.AuthFailedServiceException) ServiceException(com.zimbra.common.service.ServiceException) CallbackContext(com.zimbra.cs.account.callback.CallbackContext) LdapDomain(com.zimbra.cs.account.ldap.entry.LdapDomain) Domain(com.zimbra.cs.account.Domain) LdapException(com.zimbra.cs.ldap.LdapException) LdapDistributionList(com.zimbra.cs.account.ldap.entry.LdapDistributionList) 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