Search in sources :

Example 11 with ZSearchResultEnumeration

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

the class TestLdapHelper method searchDir.

@Test
public void searchDir() throws Exception {
    LdapDIT dit = prov.getDIT();
    String base = dit.configBranchBaseDN();
    ZLdapFilter filter = filterFactory.anyEntry();
    String[] returnAttrs = new String[] { "objectClass" };
    ZSearchControls searchControls = ZSearchControls.createSearchControls(ZSearchScope.SEARCH_SCOPE_ONELEVEL, ZSearchControls.SIZE_UNLIMITED, returnAttrs);
    ZSearchResultEnumeration ne = ldapHelper.searchDir(base, filter, searchControls);
    Set<String> expected = new HashSet<String>();
    expected.add(dit.adminBaseDN());
    expected.add(dit.appAdminBaseDN());
    expected.add(dit.zimletBaseDN());
    expected.add(dit.cosBaseDN());
    expected.add(dit.globalDynamicGroupBaseDN());
    expected.add(dit.serverBaseDN());
    expected.add(dit.xmppcomponentBaseDN());
    expected.add(dit.globalGrantDN());
    expected.add(dit.configDN());
    expected.add(dit.shareLocatorBaseDN());
    expected.add(dit.ucServiceBaseDN());
    int numFound = 0;
    while (ne.hasMore()) {
        ZSearchResultEntry sr = ne.next();
        assertTrue(expected.contains(sr.getDN()));
        numFound++;
    }
    ne.close();
    assertEquals(expected.size(), numFound);
}
Also used : ZLdapFilter(com.zimbra.cs.ldap.ZLdapFilter) ZSearchControls(com.zimbra.cs.ldap.ZSearchControls) LdapDIT(com.zimbra.cs.account.ldap.LdapDIT) ZSearchResultEnumeration(com.zimbra.cs.ldap.ZSearchResultEnumeration) HashSet(java.util.HashSet) ZSearchResultEntry(com.zimbra.cs.ldap.ZSearchResultEntry)

Example 12 with ZSearchResultEnumeration

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

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

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

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

the class LdapProvisioning method getEmptyAliasDomainIds.

public List<String> getEmptyAliasDomainIds(ZLdapContext zlc, Domain targetDomain, boolean suboridinateCheck) throws ServiceException {
    List<String> aliasDomainIds = new ArrayList<String>();
    ZSearchResultEnumeration ne = null;
    try {
        ZSearchControls searchControls = ZSearchControls.createSearchControls(ZSearchScope.SEARCH_SCOPE_SUBTREE, ZSearchControls.SIZE_UNLIMITED, new String[] { Provisioning.A_zimbraId, Provisioning.A_zimbraDomainName });
        ne = helper.searchDir(mDIT.domainBaseDN(), filterFactory.domainAliases(targetDomain.getId()), searchControls, zlc, LdapServerType.MASTER);
        while (ne.hasMore()) {
            ZSearchResultEntry sr = ne.next();
            String aliasDomainId = sr.getAttributes().getAttrString(Provisioning.A_zimbraId);
            String aliasDomainName = sr.getAttributes().getAttrString(Provisioning.A_zimbraDomainName);
            // make sure the alias domain is ready to be deleted
            String aliasDomainDn = sr.getDN();
            String acctBaseDn = mDIT.domainDNToAccountBaseDN(aliasDomainDn);
            String dynGroupsBaseDn = mDIT.domainDNToDynamicGroupsBaseDN(aliasDomainDn);
            if (suboridinateCheck && (hasSubordinates(zlc, acctBaseDn) || hasSubordinates(zlc, dynGroupsBaseDn))) {
                throw ServiceException.FAILURE("alias domain " + aliasDomainName + " of doamin " + targetDomain.getName() + " is not empty", null);
            }
            if (aliasDomainId != null) {
                aliasDomainIds.add(aliasDomainId);
            }
        }
    } finally {
        ne.close();
    }
    return aliasDomainIds;
}
Also used : ZSearchControls(com.zimbra.cs.ldap.ZSearchControls) ZSearchResultEnumeration(com.zimbra.cs.ldap.ZSearchResultEnumeration) ArrayList(java.util.ArrayList) ZSearchResultEntry(com.zimbra.cs.ldap.ZSearchResultEntry)

Aggregations

ZSearchResultEnumeration (com.zimbra.cs.ldap.ZSearchResultEnumeration)27 ZSearchResultEntry (com.zimbra.cs.ldap.ZSearchResultEntry)25 ServiceException (com.zimbra.common.service.ServiceException)15 AccountServiceException (com.zimbra.cs.account.AccountServiceException)14 AuthFailedServiceException (com.zimbra.cs.account.AccountServiceException.AuthFailedServiceException)14 ArrayList (java.util.ArrayList)14 ZLdapFilter (com.zimbra.cs.ldap.ZLdapFilter)11 ZSearchControls (com.zimbra.cs.ldap.ZSearchControls)11 ZLdapContext (com.zimbra.cs.ldap.ZLdapContext)4 LdapSizeLimitExceededException (com.zimbra.cs.ldap.LdapException.LdapSizeLimitExceededException)3 Account (com.zimbra.cs.account.Account)2 Cos (com.zimbra.cs.account.Cos)2 GuestAccount (com.zimbra.cs.account.GuestAccount)2 LdapDIT (com.zimbra.cs.account.ldap.LdapDIT)2 LdapAccount (com.zimbra.cs.account.ldap.entry.LdapAccount)2 LdapCos (com.zimbra.cs.account.ldap.entry.LdapCos)2 LdapMimeType (com.zimbra.cs.account.ldap.entry.LdapMimeType)2 MimeTypeInfo (com.zimbra.cs.mime.MimeTypeInfo)2 AlwaysOnCluster (com.zimbra.cs.account.AlwaysOnCluster)1 DataSource (com.zimbra.cs.account.DataSource)1