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