Search in sources :

Example 6 with ZLdapFilter

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

the class LdapProvisioning method getAllAlwaysOnClusters.

@Override
public List<AlwaysOnCluster> getAllAlwaysOnClusters() throws ServiceException {
    List<AlwaysOnCluster> result = new ArrayList<AlwaysOnCluster>();
    ZLdapFilter filter = filterFactory.allAlwaysOnClusters();
    try {
        ZSearchResultEnumeration ne = helper.searchDir(mDIT.alwaysOnClusterBaseDN(), filter, ZSearchControls.SEARCH_CTLS_SUBTREE());
        while (ne.hasMore()) {
            ZSearchResultEntry sr = ne.next();
            LdapAlwaysOnCluster c = new LdapAlwaysOnCluster(sr.getDN(), sr.getAttributes(), null, this);
            result.add(c);
        }
        ne.close();
    } catch (ServiceException e) {
        throw ServiceException.FAILURE("unable to list all alwaysOnClusters", e);
    }
    if (result.size() > 0)
        alwaysOnClusterCache.put(result, true);
    Collections.sort(result);
    return result;
}
Also used : ZLdapFilter(com.zimbra.cs.ldap.ZLdapFilter) LdapAlwaysOnCluster(com.zimbra.cs.account.ldap.entry.LdapAlwaysOnCluster) LdapAlwaysOnCluster(com.zimbra.cs.account.ldap.entry.LdapAlwaysOnCluster) AlwaysOnCluster(com.zimbra.cs.account.AlwaysOnCluster) AccountServiceException(com.zimbra.cs.account.AccountServiceException) AuthFailedServiceException(com.zimbra.cs.account.AccountServiceException.AuthFailedServiceException) ServiceException(com.zimbra.common.service.ServiceException) ZSearchResultEnumeration(com.zimbra.cs.ldap.ZSearchResultEnumeration) ArrayList(java.util.ArrayList) ZSearchResultEntry(com.zimbra.cs.ldap.ZSearchResultEntry)

Example 7 with ZLdapFilter

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

the class LdapProvisioning method searchDynamicGroupInternalMembers.

private void searchDynamicGroupInternalMembers(ZLdapContext zlc, String dynGroupId, SearchLdapVisitor visitor) throws ServiceException {
    String base = mDIT.mailBranchBaseDN();
    ZLdapFilter filter = filterFactory.accountByMemberOf(dynGroupId);
    SearchLdapOptions searchOptions = new SearchLdapOptions(base, filter, new String[] { A_zimbraMailDeliveryAddress, Provisioning.A_zimbraMemberOf }, SearchLdapOptions.SIZE_UNLIMITED, null, ZSearchScope.SEARCH_SCOPE_SUBTREE, visitor);
    zlc.searchPaged(searchOptions);
}
Also used : ZLdapFilter(com.zimbra.cs.ldap.ZLdapFilter) SearchLdapOptions(com.zimbra.cs.ldap.SearchLdapOptions)

Example 8 with ZLdapFilter

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

the class LdapProvisioning method getAllServers.

@Override
public List<Server> getAllServers(String service) throws ServiceException {
    List<Server> result = new ArrayList<Server>();
    ZLdapFilter filter;
    if (service != null) {
        filter = filterFactory.serverByService(service);
    } else {
        filter = filterFactory.allServers();
    }
    try {
        Map<String, Object> serverDefaults = getConfig().getServerDefaults();
        ZSearchResultEnumeration ne = helper.searchDir(mDIT.serverBaseDN(), filter, ZSearchControls.SEARCH_CTLS_SUBTREE());
        while (ne.hasMore()) {
            ZSearchResultEntry sr = ne.next();
            LdapServer s = new LdapServer(sr.getDN(), sr.getAttributes(), serverDefaults, this);
            result.add(s);
        }
        ne.close();
    } catch (ServiceException e) {
        throw ServiceException.FAILURE("unable to list all servers", e);
    }
    if (result.size() > 0)
        serverCache.put(result, true);
    Collections.sort(result);
    return result;
}
Also used : ZLdapFilter(com.zimbra.cs.ldap.ZLdapFilter) InMemoryLdapServer(com.zimbra.cs.ldap.unboundid.InMemoryLdapServer) LdapServer(com.zimbra.cs.account.ldap.entry.LdapServer) InMemoryLdapServer(com.zimbra.cs.ldap.unboundid.InMemoryLdapServer) LdapServer(com.zimbra.cs.account.ldap.entry.LdapServer) Server(com.zimbra.cs.account.Server) AccountServiceException(com.zimbra.cs.account.AccountServiceException) AuthFailedServiceException(com.zimbra.cs.account.AccountServiceException.AuthFailedServiceException) ServiceException(com.zimbra.common.service.ServiceException) ZSearchResultEnumeration(com.zimbra.cs.ldap.ZSearchResultEnumeration) ArrayList(java.util.ArrayList) ZSearchResultEntry(com.zimbra.cs.ldap.ZSearchResultEntry)

Example 9 with ZLdapFilter

use of com.zimbra.cs.ldap.ZLdapFilter 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 10 with ZLdapFilter

use of com.zimbra.cs.ldap.ZLdapFilter 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)

Aggregations

ZLdapFilter (com.zimbra.cs.ldap.ZLdapFilter)121 ZSearchResultEntry (com.zimbra.cs.ldap.ZSearchResultEntry)15 ZSearchResultEnumeration (com.zimbra.cs.ldap.ZSearchResultEnumeration)11 ZLdapContext (com.zimbra.cs.ldap.ZLdapContext)8 ZSearchControls (com.zimbra.cs.ldap.ZSearchControls)8 ArrayList (java.util.ArrayList)8 ServiceException (com.zimbra.common.service.ServiceException)7 Server (com.zimbra.cs.account.Server)7 LdapDIT (com.zimbra.cs.account.ldap.LdapDIT)7 Account (com.zimbra.cs.account.Account)6 AccountServiceException (com.zimbra.cs.account.AccountServiceException)6 AuthFailedServiceException (com.zimbra.cs.account.AccountServiceException.AuthFailedServiceException)6 LdapSizeLimitExceededException (com.zimbra.cs.ldap.LdapException.LdapSizeLimitExceededException)6 NamedEntry (com.zimbra.cs.account.NamedEntry)5 SearchAccountsOptions (com.zimbra.cs.account.SearchAccountsOptions)5 BySearchResultEntrySearcher (com.zimbra.cs.account.ldap.BySearchResultEntrySearcher)5 SearchLdapOptions (com.zimbra.cs.ldap.SearchLdapOptions)5 ProvTest (com.zimbra.qa.unittest.prov.ProvTest)5 LDAPException (com.unboundid.ldap.sdk.LDAPException)3 SearchRequest (com.unboundid.ldap.sdk.SearchRequest)3