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);
}
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);
}
*/
}
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;
}
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;
}
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;
}
Aggregations