Search in sources :

Example 6 with ZSearchControls

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

the class ZLdapHelper method searchForEntry.

@Override
@TODOEXCEPTIONMAPPING
public ZSearchResultEntry searchForEntry(String base, ZLdapFilter filter, ZLdapContext initZlc, boolean useMaster, String[] returnAttrs) throws LdapMultipleEntriesMatchedException, ServiceException {
    ZLdapContext zlc = initZlc;
    try {
        if (zlc == null) {
            zlc = LdapClient.getContext(LdapServerType.get(useMaster), LdapUsage.SEARCH);
        }
        ZSearchControls sc = (returnAttrs == null) ? ZSearchControls.SEARCH_CTLS_SUBTREE() : ZSearchControls.createSearchControls(ZSearchScope.SEARCH_SCOPE_SUBTREE, ZSearchControls.SIZE_UNLIMITED, returnAttrs);
        ZSearchResultEnumeration ne = zlc.searchDir(base, filter, sc);
        if (ne.hasMore()) {
            ZSearchResultEntry sr = ne.next();
            if (ne.hasMore()) {
                String dups = LdapUtil.formatMultipleMatchedEntries(sr, ne);
                throw LdapException.MULTIPLE_ENTRIES_MATCHED(base, filter.toFilterString(), dups);
            }
            ne.close();
            return sr;
        }
    /*  all callsites with the following @TODOEXCEPTIONMAPPING pattern can have ease of mind now and remove the
         * TODOEXCEPTIONMAPPING annotation
         *
        } catch (NameNotFoundException e) {
            return null;
        } catch (InvalidNameException e) {
            return null;
        } catch (NamingException e) {
            throw ServiceException.FAILURE("unable to lookup account via query: "+query+" message: "+e.getMessage(), e);
        */
    } finally {
        if (initZlc == null)
            LdapClient.closeContext(zlc);
    }
    return null;
}
Also used : ZSearchControls(com.zimbra.cs.ldap.ZSearchControls) ZLdapContext(com.zimbra.cs.ldap.ZLdapContext) ZSearchResultEnumeration(com.zimbra.cs.ldap.ZSearchResultEnumeration) ZSearchResultEntry(com.zimbra.cs.ldap.ZSearchResultEntry) TODOEXCEPTIONMAPPING(com.zimbra.cs.ldap.LdapTODO.TODOEXCEPTIONMAPPING)

Example 7 with ZSearchControls

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

the class TestLdap method getDirectChildrenDNs.

private static List<String> getDirectChildrenDNs(ZLdapContext zlc, String dn) throws Exception {
    final List<String> childrenDNs = new ArrayList<String>();
    ZLdapFilter filter = ZLdapFilterFactory.getInstance().anyEntry();
    ZSearchControls searchControls = ZSearchControls.createSearchControls(ZSearchScope.SEARCH_SCOPE_ONELEVEL, ZSearchControls.SIZE_UNLIMITED, new String[] { "objectClass" });
    ZSearchResultEnumeration sr = zlc.searchDir(dn, filter, searchControls);
    while (sr.hasMore()) {
        ZSearchResultEntry entry = sr.next();
        childrenDNs.add(entry.getDN());
    }
    sr.close();
    return childrenDNs;
}
Also used : ZLdapFilter(com.zimbra.cs.ldap.ZLdapFilter) TestLdapZLdapFilter(com.zimbra.qa.unittest.prov.ldap.TestLdapZLdapFilter) ZSearchControls(com.zimbra.cs.ldap.ZSearchControls) ZSearchResultEnumeration(com.zimbra.cs.ldap.ZSearchResultEnumeration) ArrayList(java.util.ArrayList) ZSearchResultEntry(com.zimbra.cs.ldap.ZSearchResultEntry)

Example 8 with ZSearchControls

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

the class Cleanup method getDirectChildrenDNs.

private static List<String> getDirectChildrenDNs(ZLdapContext zlc, String dn) throws Exception {
    final List<String> childrenDNs = new ArrayList<String>();
    ZLdapFilter filter = ZLdapFilterFactory.getInstance().anyEntry();
    ZSearchControls searchControls = ZSearchControls.createSearchControls(ZSearchScope.SEARCH_SCOPE_ONELEVEL, ZSearchControls.SIZE_UNLIMITED, new String[] { "objectClass" });
    ZSearchResultEnumeration sr = zlc.searchDir(dn, filter, searchControls);
    while (sr.hasMore()) {
        ZSearchResultEntry entry = sr.next();
        childrenDNs.add(entry.getDN());
    }
    sr.close();
    return childrenDNs;
}
Also used : ZLdapFilter(com.zimbra.cs.ldap.ZLdapFilter) ZSearchControls(com.zimbra.cs.ldap.ZSearchControls) ZSearchResultEnumeration(com.zimbra.cs.ldap.ZSearchResultEnumeration) ArrayList(java.util.ArrayList) ZSearchResultEntry(com.zimbra.cs.ldap.ZSearchResultEntry)

Example 9 with ZSearchControls

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

the class TestLdapZLdapContext method searchDir.

@Test
public void searchDir() throws Exception {
    int SIZE_LIMIT = 5;
    String base = LdapConstants.DN_ROOT_DSE;
    ZLdapFilter filter = ZLdapFilterFactory.getInstance().anyEntry();
    String[] returnAttrs = new String[] { "objectClass" };
    ZSearchControls searchControls = ZSearchControls.createSearchControls(ZSearchScope.SEARCH_SCOPE_SUBTREE, SIZE_LIMIT, returnAttrs);
    int numFound = 0;
    boolean caughtException = false;
    ZLdapContext zlc = null;
    try {
        zlc = LdapClient.getContext(LdapUsage.UNITTEST);
        ZSearchResultEnumeration ne = zlc.searchDir(base, filter, searchControls);
        while (ne.hasMore()) {
            ZSearchResultEntry sr = ne.next();
            numFound++;
        }
        ne.close();
    } catch (LdapSizeLimitExceededException e) {
        caughtException = true;
    } finally {
        LdapClient.closeContext(zlc);
    }
    assertTrue(caughtException);
/*
        // unboundid does not return entries if LdapSizeLimitExceededException
        // is thrown,  See commons on ZLdapContext.searchDir().
        if (testConfig != TestLdap.TestConfig.UBID) {
            assertEquals(SIZE_LIMIT, numFound);
        }
        */
}
Also used : ZLdapFilter(com.zimbra.cs.ldap.ZLdapFilter) ZSearchControls(com.zimbra.cs.ldap.ZSearchControls) ZLdapContext(com.zimbra.cs.ldap.ZLdapContext) ZSearchResultEnumeration(com.zimbra.cs.ldap.ZSearchResultEnumeration) LdapSizeLimitExceededException(com.zimbra.cs.ldap.LdapException.LdapSizeLimitExceededException) ZSearchResultEntry(com.zimbra.cs.ldap.ZSearchResultEntry)

Example 10 with ZSearchControls

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

the class LdapProvisioning method getDistributionListByQuery.

private DistributionList getDistributionListByQuery(String base, ZLdapFilter filter, ZLdapContext initZlc, boolean basicAttrsOnly) throws ServiceException {
    String[] returnAttrs = basicAttrsOnly ? BASIC_DL_ATTRS : null;
    DistributionList dl = null;
    try {
        ZSearchControls searchControls = ZSearchControls.createSearchControls(ZSearchScope.SEARCH_SCOPE_SUBTREE, ZSearchControls.SIZE_UNLIMITED, returnAttrs);
        ZSearchResultEnumeration ne = helper.searchDir(base, filter, searchControls, initZlc, LdapServerType.REPLICA);
        if (ne.hasMore()) {
            ZSearchResultEntry sr = ne.next();
            dl = makeDistributionList(sr.getDN(), sr.getAttributes(), basicAttrsOnly);
            List<String> objectclass = sr.getAttributes().getMultiAttrStringAsList(Provisioning.A_objectClass, CheckBinary.NOCHECK);
            if (dl != null && objectclass != null && objectclass.contains(AttributeClass.OC_zimbraHabGroup)) {
                dl.setHABGroup(Boolean.TRUE);
            }
        }
        ne.close();
    } catch (ServiceException e) {
        throw ServiceException.FAILURE("unable to lookup distribution list via query: " + filter.toFilterString() + " message: " + e.getMessage(), e);
    }
    return dl;
}
Also used : ZSearchControls(com.zimbra.cs.ldap.ZSearchControls) 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) LdapDistributionList(com.zimbra.cs.account.ldap.entry.LdapDistributionList) DistributionList(com.zimbra.cs.account.DistributionList) ZSearchResultEntry(com.zimbra.cs.ldap.ZSearchResultEntry)

Aggregations

ZSearchControls (com.zimbra.cs.ldap.ZSearchControls)15 ZSearchResultEnumeration (com.zimbra.cs.ldap.ZSearchResultEnumeration)14 ZSearchResultEntry (com.zimbra.cs.ldap.ZSearchResultEntry)12 ZLdapFilter (com.zimbra.cs.ldap.ZLdapFilter)10 ServiceException (com.zimbra.common.service.ServiceException)5 ZLdapContext (com.zimbra.cs.ldap.ZLdapContext)5 AccountServiceException (com.zimbra.cs.account.AccountServiceException)4 AuthFailedServiceException (com.zimbra.cs.account.AccountServiceException.AuthFailedServiceException)4 LdapSizeLimitExceededException (com.zimbra.cs.ldap.LdapException.LdapSizeLimitExceededException)4 ArrayList (java.util.ArrayList)3 LdapDIT (com.zimbra.cs.account.ldap.LdapDIT)2 HashSet (java.util.HashSet)2 AddressList (com.zimbra.cs.account.AddressList)1 DistributionList (com.zimbra.cs.account.DistributionList)1 LdapDistributionList (com.zimbra.cs.account.ldap.entry.LdapDistributionList)1 LdapEntry (com.zimbra.cs.account.ldap.entry.LdapEntry)1 GenericLdapConfig (com.zimbra.cs.ldap.LdapServerConfig.GenericLdapConfig)1 TODOEXCEPTIONMAPPING (com.zimbra.cs.ldap.LdapTODO.TODOEXCEPTIONMAPPING)1 ZAttributes (com.zimbra.cs.ldap.ZAttributes)1 TestLdapZLdapFilter (com.zimbra.qa.unittest.prov.ldap.TestLdapZLdapFilter)1