Search in sources :

Example 1 with BySearchResultEntrySearcher

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

the class LdapDynamicGroup method updateGroupMembershipForDynamicGroups.

public static GroupMembership updateGroupMembershipForDynamicGroups(LdapProvisioning prov, GroupMembership membership, Account acct, Collection<String> ids, boolean adminGroupsOnly, boolean customGroupsOnly, boolean nonCustomGroupsOnly) throws ServiceException {
    if (ids.size() == 0) {
        return membership;
    }
    String acctDN = prov.getDNforAccount(acct, null, false);
    if (acctDN == null) {
        return membership;
    }
    ZLdapFilter filter = ZLdapFilterFactory.getInstance().dynamicGroupByIds(ids.toArray(new String[0]));
    ZLdapContext zlcCompare = null;
    try {
        zlcCompare = LdapClient.getContext(LdapServerType.get(false), LdapUsage.COMPARE);
        BySearchResultEntrySearcher searcher = new BySearchResultEntrySearcher(prov, (ZLdapContext) null, (Domain) null, BASIC_ATTRS, new GroupMembershipUpdator(prov, zlcCompare, acctDN, membership, adminGroupsOnly, customGroupsOnly, nonCustomGroupsOnly));
        searcher.doSearch(filter, DYNAMIC_GROUPS_TYPE);
    } finally {
        LdapClient.closeContext(zlcCompare);
    }
    return membership;
}
Also used : ZLdapFilter(com.zimbra.cs.ldap.ZLdapFilter) ZLdapContext(com.zimbra.cs.ldap.ZLdapContext) BySearchResultEntrySearcher(com.zimbra.cs.account.ldap.BySearchResultEntrySearcher)

Example 2 with BySearchResultEntrySearcher

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

the class LdapDynamicGroup method updateGroupMembershipForCustomDynamicGroups.

public static GroupMembership updateGroupMembershipForCustomDynamicGroups(LdapProvisioning prov, GroupMembership membership, Account acct, Domain domain, boolean adminGroupsOnly) throws ServiceException {
    String acctDN = prov.getDNforAccount(acct, null, false);
    if (acctDN == null) {
        return membership;
    }
    ZLdapFilter filter = ZLdapFilterFactory.getInstance().allDynamicGroups();
    ZLdapContext zlcCompare = null;
    try {
        zlcCompare = LdapClient.getContext(LdapServerType.get(false), LdapUsage.COMPARE);
        BySearchResultEntrySearcher searcher = new BySearchResultEntrySearcher(prov, (ZLdapContext) null, domain, BASIC_ATTRS, new GroupMembershipUpdator(prov, zlcCompare, acctDN, membership, adminGroupsOnly, true, false));
        searcher.doSearch(filter, DYNAMIC_GROUPS_TYPE);
    } finally {
        LdapClient.closeContext(zlcCompare);
    }
    return membership;
}
Also used : ZLdapFilter(com.zimbra.cs.ldap.ZLdapFilter) ZLdapContext(com.zimbra.cs.ldap.ZLdapContext) BySearchResultEntrySearcher(com.zimbra.cs.account.ldap.BySearchResultEntrySearcher)

Example 3 with BySearchResultEntrySearcher

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

the class DistributionList method getContainingDLs.

public static List<BasicInfo> getContainingDLs(LdapProvisioning prov, ZLdapContext zlc, BasicInfo dl, boolean adminGroupsOnly, boolean directOnly) throws ServiceException {
    String[] addrs = dl.getAllAddrsAsGroupMember().toArray(new String[0]);
    ZLdapFilter filter = ZLdapFilterFactory.getInstance().distributionListsByMemberAddrs(addrs);
    ContainingDLUpdator dlUpdator = new ContainingDLUpdator(prov, adminGroupsOnly);
    BySearchResultEntrySearcher searcher = new BySearchResultEntrySearcher(prov, zlc, (Domain) null, BASIC_ATTRS, dlUpdator);
    searcher.doSearch(filter, DISTRIBUTION_LISTS);
    return dlUpdator.getDistLists();
}
Also used : ZLdapFilter(com.zimbra.cs.ldap.ZLdapFilter) BySearchResultEntrySearcher(com.zimbra.cs.account.ldap.BySearchResultEntrySearcher)

Example 4 with BySearchResultEntrySearcher

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

the class DistributionList method updateGroupMembership.

/**
 * @param via - leave as NULL if not needed as computing via is significantly more expensive.
 * @return Updated membership
 */
public static GroupMembership updateGroupMembership(LdapProvisioning prov, ZLdapContext zlc, GroupMembership membership, Account acct, Map<String, String> via, boolean adminGroupsOnly, boolean directOnly) throws ServiceException {
    boolean ownContext = false;
    String[] addrs = acct.getAllAddrsAsGroupMember();
    ZLdapFilter filter = ZLdapFilterFactory.getInstance().distributionListsByMemberAddrs(addrs);
    ContainingDLUpdator dlUpdator = new ContainingDLUpdator(prov, adminGroupsOnly);
    try {
        if (zlc == null) {
            ownContext = true;
            zlc = LdapClient.getContext(LdapServerType.get(false), LdapUsage.SEARCH);
        }
        BySearchResultEntrySearcher searcher = new BySearchResultEntrySearcher(prov, zlc, (Domain) null, BASIC_ATTRS, dlUpdator);
        searcher.doSearch(filter, DISTRIBUTION_LISTS);
        List<BasicInfo> directDLs = dlUpdator.getDistLists();
        BasicInfo.mergeIntoGroupMembership(membership, directDLs);
        if (directOnly) {
            return membership;
        }
        if (via == null) {
            updateGroupMembership(prov, zlc, membership, directDLs, adminGroupsOnly, directOnly);
        } else {
            for (BasicInfo directDL : directDLs) {
                updateGroupMembership(prov, zlc, membership, directDL, via, adminGroupsOnly, directOnly);
            }
        }
        return membership;
    } finally {
        if (ownContext) {
            LdapClient.closeContext(zlc);
        }
    }
}
Also used : ZLdapFilter(com.zimbra.cs.ldap.ZLdapFilter) BySearchResultEntrySearcher(com.zimbra.cs.account.ldap.BySearchResultEntrySearcher)

Example 5 with BySearchResultEntrySearcher

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

the class DistributionList method getContainingDLs.

public static List<BasicInfo> getContainingDLs(LdapProvisioning prov, ZLdapContext zlc, List<BasicInfo> dls, boolean adminGroupsOnly, boolean directOnly) throws ServiceException {
    final int chunkSize = 500;
    List<String> addrs = Lists.newArrayList();
    for (BasicInfo dl : dls) {
        addrs.addAll(dl.getAllAddrsAsGroupMember());
    }
    int lastIndex = addrs.size() - 1;
    int start = 0;
    int end = (lastIndex < chunkSize) ? lastIndex : chunkSize - 1;
    List<BasicInfo> containingDLs = Lists.newArrayList();
    while (end <= lastIndex) {
        String[] chunk = addrs.subList(start, end + 1).toArray(new String[0]);
        ZLdapFilter filter = ZLdapFilterFactory.getInstance().distributionListsByMemberAddrs(chunk);
        ContainingDLUpdator dlUpdator = new ContainingDLUpdator(prov, adminGroupsOnly);
        BySearchResultEntrySearcher searcher = new BySearchResultEntrySearcher(prov, zlc, (Domain) null, BASIC_ATTRS, dlUpdator);
        searcher.doSearch(filter, DISTRIBUTION_LISTS);
        containingDLs.addAll(dlUpdator.getDistLists());
        if (end >= lastIndex) {
            break;
        }
        start += chunkSize;
        end += chunkSize;
        if (end > lastIndex) {
            end = lastIndex;
        }
    }
    return containingDLs;
}
Also used : ZLdapFilter(com.zimbra.cs.ldap.ZLdapFilter) BySearchResultEntrySearcher(com.zimbra.cs.account.ldap.BySearchResultEntrySearcher)

Aggregations

BySearchResultEntrySearcher (com.zimbra.cs.account.ldap.BySearchResultEntrySearcher)5 ZLdapFilter (com.zimbra.cs.ldap.ZLdapFilter)5 ZLdapContext (com.zimbra.cs.ldap.ZLdapContext)2