Search in sources :

Example 1 with TODOEXCEPTIONMAPPING

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;
}
Also used : ZSearchControls(com.zimbra.cs.ldap.ZSearchControls) ZLdapContext(com.zimbra.cs.ldap.ZLdapContext) ZSearchResultEnumeration(com.zimbra.cs.ldap.ZSearchResultEnumeration) ZSearchResultEntry(com.zimbra.cs.ldap.ZSearchResultEntry) TODOEXCEPTIONMAPPING(com.zimbra.cs.ldap.LdapTODO.TODOEXCEPTIONMAPPING)

Aggregations

TODOEXCEPTIONMAPPING (com.zimbra.cs.ldap.LdapTODO.TODOEXCEPTIONMAPPING)1 ZLdapContext (com.zimbra.cs.ldap.ZLdapContext)1 ZSearchControls (com.zimbra.cs.ldap.ZSearchControls)1 ZSearchResultEntry (com.zimbra.cs.ldap.ZSearchResultEntry)1 ZSearchResultEnumeration (com.zimbra.cs.ldap.ZSearchResultEnumeration)1