Search in sources :

Example 6 with LdapSizeLimitExceededException

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

the class TestLdapZLdapContext method searchPaged.

@Test
public void searchPaged() throws Exception {
    int SIZE_LIMIT = 5;
    String base = LdapConstants.DN_ROOT_DSE;
    ZLdapFilter filter = ZLdapFilterFactory.getInstance().anyEntry();
    String[] returnAttrs = new String[] { "objectClass" };
    final List<String> result = new ArrayList<String>();
    SearchLdapOptions.SearchLdapVisitor visitor = new SearchLdapOptions.SearchLdapVisitor() {

        @Override
        public void visit(String dn, Map<String, Object> attrs, IAttributes ldapAttrs) {
            result.add(dn);
        }
    };
    SearchLdapOptions searchOptions = new SearchLdapOptions(base, filter, returnAttrs, SIZE_LIMIT, null, ZSearchScope.SEARCH_SCOPE_SUBTREE, visitor);
    boolean caughtException = false;
    ZLdapContext zlc = null;
    try {
        zlc = LdapClient.getContext(LdapUsage.UNITTEST);
        zlc.searchPaged(searchOptions);
    } catch (LdapSizeLimitExceededException e) {
        caughtException = true;
    } finally {
        LdapClient.closeContext(zlc);
    }
    assertTrue(caughtException);
    assertEquals(SIZE_LIMIT, result.size());
}
Also used : ZLdapContext(com.zimbra.cs.ldap.ZLdapContext) ArrayList(java.util.ArrayList) SearchLdapOptions(com.zimbra.cs.ldap.SearchLdapOptions) ZLdapFilter(com.zimbra.cs.ldap.ZLdapFilter) IAttributes(com.zimbra.cs.ldap.IAttributes) LdapSizeLimitExceededException(com.zimbra.cs.ldap.LdapException.LdapSizeLimitExceededException) Map(java.util.Map)

Example 7 with LdapSizeLimitExceededException

use of com.zimbra.cs.ldap.LdapException.LdapSizeLimitExceededException 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 8 with LdapSizeLimitExceededException

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

the class LdapProvisioning method addressExistsUnderDN.

/*
     * returns if any one of addrs is an email address under the specified baseDN
     */
private boolean addressExistsUnderDN(ZLdapContext zlc, String baseDN, String[] addrs) throws ServiceException {
    ZLdapFilter filter = filterFactory.addrsExist(addrs);
    ZSearchControls searchControls = ZSearchControls.createSearchControls(ZSearchScope.SEARCH_SCOPE_SUBTREE, 1, null);
    try {
        long count = helper.countEntries(baseDN, filter, searchControls, zlc, LdapServerType.MASTER);
        return count > 0;
    } catch (LdapSizeLimitExceededException e) {
        return true;
    }
}
Also used : ZLdapFilter(com.zimbra.cs.ldap.ZLdapFilter) ZSearchControls(com.zimbra.cs.ldap.ZSearchControls) LdapSizeLimitExceededException(com.zimbra.cs.ldap.LdapException.LdapSizeLimitExceededException)

Example 9 with LdapSizeLimitExceededException

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

the class TestLdapHelper method searchDirSizeLimitExceeded.

@Test
public void searchDirSizeLimitExceeded() throws Exception {
    int SIZE_LIMIT = 5;
    String base = LdapConstants.DN_ROOT_DSE;
    ZLdapFilter filter = filterFactory.anyEntry();
    String[] returnAttrs = new String[] { "objectClass" };
    ZSearchControls searchControls = ZSearchControls.createSearchControls(ZSearchScope.SEARCH_SCOPE_SUBTREE, SIZE_LIMIT, returnAttrs);
    int numFound = 0;
    boolean caughtException = false;
    try {
        ZSearchResultEnumeration ne = ldapHelper.searchDir(base, filter, searchControls);
        while (ne.hasMore()) {
            ZSearchResultEntry sr = ne.next();
            numFound++;
        }
        ne.close();
    } catch (LdapSizeLimitExceededException e) {
        caughtException = true;
    }
    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) ZSearchResultEnumeration(com.zimbra.cs.ldap.ZSearchResultEnumeration) LdapSizeLimitExceededException(com.zimbra.cs.ldap.LdapException.LdapSizeLimitExceededException) ZSearchResultEntry(com.zimbra.cs.ldap.ZSearchResultEntry)

Aggregations

LdapSizeLimitExceededException (com.zimbra.cs.ldap.LdapException.LdapSizeLimitExceededException)9 ZLdapFilter (com.zimbra.cs.ldap.ZLdapFilter)6 SearchLdapOptions (com.zimbra.cs.ldap.SearchLdapOptions)5 ZLdapContext (com.zimbra.cs.ldap.ZLdapContext)5 ZSearchControls (com.zimbra.cs.ldap.ZSearchControls)4 ServiceException (com.zimbra.common.service.ServiceException)3 ZSearchResultEntry (com.zimbra.cs.ldap.ZSearchResultEntry)3 ZSearchResultEnumeration (com.zimbra.cs.ldap.ZSearchResultEnumeration)3 AccountServiceException (com.zimbra.cs.account.AccountServiceException)2 AuthFailedServiceException (com.zimbra.cs.account.AccountServiceException.AuthFailedServiceException)2 IAttributes (com.zimbra.cs.ldap.IAttributes)2 LdapInvalidAttrValueException (com.zimbra.cs.ldap.LdapException.LdapInvalidAttrValueException)2 Map (java.util.Map)2 LdapDomain (com.zimbra.cs.account.ldap.entry.LdapDomain)1 LdapException (com.zimbra.cs.ldap.LdapException)1 LdapContextNotEmptyException (com.zimbra.cs.ldap.LdapException.LdapContextNotEmptyException)1 LdapEntryAlreadyExistException (com.zimbra.cs.ldap.LdapException.LdapEntryAlreadyExistException)1 LdapEntryNotFoundException (com.zimbra.cs.ldap.LdapException.LdapEntryNotFoundException)1 LdapInvalidAttrNameException (com.zimbra.cs.ldap.LdapException.LdapInvalidAttrNameException)1 LdapInvalidSearchFilterException (com.zimbra.cs.ldap.LdapException.LdapInvalidSearchFilterException)1