use of com.zimbra.cs.ldap.LdapTODO.TODOEXCEPTIONMAPPING 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;
}
Aggregations