use of com.zimbra.cs.ldap.ZSearchResultEntry 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.ZSearchResultEntry in project zm-mailbox by Zimbra.
the class LdapExample method search.
public void search() throws Exception {
String base = "cn=servers,cn=zimbra";
String filter = "(objectClass=zimbraServer)";
String[] returnAttrs = new String[] { "objectClass", "cn" };
ZLdapFilter zFilter = ZLdapFilterFactory.getInstance().fromFilterString(FilterId.ZMCONFIGD, filter);
ZSearchControls searchControls = ZSearchControls.createSearchControls(ZSearchScope.SEARCH_SCOPE_SUBTREE, ZSearchControls.SIZE_UNLIMITED, returnAttrs);
GenericLdapConfig ldapConfig = getLdapConfig();
ZLdapContext zlc = null;
try {
zlc = LdapClient.getContext(ldapConfig, LdapUsage.SEARCH);
ZSearchResultEnumeration ne = zlc.searchDir(base, zFilter, searchControls);
while (ne.hasMore()) {
ZSearchResultEntry entry = ne.next();
String dn = entry.getDN();
ZAttributes attrs = entry.getAttributes();
String cn = attrs.getAttrString("cn");
String[] objectClasses = attrs.getMultiAttrString("objectClass");
System.out.println("dn = " + dn);
System.out.println("cn = " + cn);
for (String objectClass : objectClasses) {
System.out.println("objetClass = " + objectClass);
}
}
ne.close();
} catch (LdapSizeLimitExceededException e) {
e.printStackTrace();
throw e;
} finally {
// Note: this is important!!
LdapClient.closeContext(zlc);
}
}
use of com.zimbra.cs.ldap.ZSearchResultEntry 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.ZSearchResultEntry 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.ZSearchResultEntry in project zm-mailbox by Zimbra.
the class LdapProvisioning method getSignaturesByQuery.
private List<Signature> getSignaturesByQuery(Account acct, LdapEntry entry, ZLdapFilter filter, ZLdapContext initZlc, List<Signature> result) throws ServiceException {
if (result == null) {
result = new ArrayList<Signature>();
}
try {
String base = entry.getDN();
ZSearchResultEnumeration ne = helper.searchDir(base, filter, ZSearchControls.SEARCH_CTLS_SUBTREE(), initZlc, LdapServerType.REPLICA);
while (ne.hasMore()) {
ZSearchResultEntry sr = ne.next();
result.add(new LdapSignature(acct, sr.getDN(), sr.getAttributes(), this));
}
ne.close();
} catch (ServiceException e) {
throw ServiceException.FAILURE("unable to lookup signature via query: " + filter.toFilterString() + " message: " + e.getMessage(), e);
}
return result;
}
Aggregations