@Override public void exceptionReceived(final Exception exception) { logger.trace("received exception={}", exception); if (exception instanceof LdapException) { searchException = (LdapException) exception; } else { searchException = new LdapException(exception); } responseLock.release(); }
@Override public void exceptionReceived(final Exception exception) { logger.trace("received exception={}", exception); if (exception instanceof LdapException) { searchException = (LdapException) exception; } else { searchException = new LdapException(exception); } responseLock.release(); }
@Override public void exceptionReceived(final Exception exception) { logger.trace("received exception={}", exception); if (exception instanceof LdapException) { searchException = (LdapException) exception; } else { searchException = new LdapException(exception); } responseLock.release(); }
/** * Digests the supplied credential using the supplied algorithm. * * @param credential to digest * @param algorithm type of digest to use * * @return digested credential * * @throws LdapException if the supplied algorithm cannot be found */ protected byte[] digestCredential(final Credential credential, final String algorithm) throws LdapException { try { final MessageDigest md = MessageDigest.getInstance(algorithm); md.update(credential.getBytes()); return md.digest(); } catch (NoSuchAlgorithmException e) { throw new LdapException(e); } }
/** * Digests the supplied credential using the supplied algorithm. * * @param credential to digest * @param algorithm type of digest to use * * @return digested credential * * @throws LdapException if the supplied algorithm cannot be found */ protected byte[] digestCredential(final Credential credential, final String algorithm) throws LdapException { try { final MessageDigest md = MessageDigest.getInstance(algorithm); md.update(credential.getBytes()); return md.digest(); } catch (NoSuchAlgorithmException e) { throw new LdapException(e); } }
@Override public void handle(final AuthenticationResponse response) throws LdapException { final String[] labeledDn = response.getResolvedDn().split(":", 2); final org.ldaptive.auth.AuthenticationResponseHandler[] handlers = responseHandlers.get(labeledDn[0]); if (handlers == null) { throw new LdapException("Could not find response handlers for label: " + labeledDn[0]); } if (handlers.length > 0) { for (org.ldaptive.auth.AuthenticationResponseHandler ah : handlers) { ah.handle(response); } } } }
@Override public void handle(final AuthenticationResponse response) throws LdapException { final String[] labeledDn = response.getResolvedDn().split(":", 2); final org.ldaptive.auth.AuthenticationResponseHandler[] handlers = responseHandlers.get(labeledDn[0]); if (handlers == null) { throw new LdapException("Could not find response handlers for label: " + labeledDn[0]); } if (handlers.length > 0) { for (org.ldaptive.auth.AuthenticationResponseHandler ah : handlers) { ah.handle(response); } } } }
@Override public AuthenticationHandlerResponse authenticate(final AuthenticationCriteria criteria) throws LdapException { final String[] labeledDn = criteria.getDn().split(":", 2); final org.ldaptive.auth.AuthenticationHandler ah = authenticationHandlers.get(labeledDn[0]); if (ah == null) { throw new LdapException("Could not find authentication handler for label: " + labeledDn[0]); } criteria.setDn(labeledDn[1]); return ah.authenticate(criteria); } }
@Override public LdapEntry resolve(final AuthenticationCriteria criteria, final AuthenticationHandlerResponse response) throws LdapException { logger.debug("resolve criteria={}", criteria); final SearchResult result = performLdapSearch(criteria, response); logger.debug("resolved result={} for criteria={}", result, criteria); LdapEntry entry = null; final Iterator<LdapEntry> answer = result.getEntries().iterator(); if (answer != null && answer.hasNext()) { entry = answer.next(); if (answer.hasNext()) { logger.debug("multiple results found for user={}", criteria.getDn()); if (!allowMultipleEntries) { throw new LdapException("Found more than (1) entry for: " + criteria.getDn()); } } } return entry; } }
@Override public AuthenticationHandlerResponse authenticate(final AuthenticationCriteria criteria) throws LdapException { final String[] labeledDn = criteria.getDn().split(":", 2); final org.ldaptive.auth.AuthenticationHandler ah = authenticationHandlers.get(labeledDn[0]); if (ah == null) { throw new LdapException("Could not find authentication handler for label: " + labeledDn[0]); } return ah.authenticate(new AuthenticationCriteria(labeledDn[1], criteria.getAuthenticationRequest())); } }
@Override public void close(final RequestControl[] controls) throws LdapException { if (controls != null) { throw new UnsupportedOperationException("Provider does not support unbind with controls"); } try { if (context != null) { context.close(); } } catch (NamingException e) { ResultCode rc = NamingExceptionUtils.getResultCode(e.getClass()); if (rc == null) { rc = NamingExceptionUtils.getResultCode(e.getMessage()); } throw new LdapException(e, rc); } finally { context = null; } }
@Override public LdapEntry resolve(final AuthenticationCriteria criteria, final AuthenticationHandlerResponse response) throws LdapException { logger.debug("resolve criteria={}", criteria); final SearchResult result = performLdapSearch(criteria, response); logger.debug("resolved result={} for criteria={}", result, criteria); LdapEntry entry = null; final Iterator<LdapEntry> answer = result.getEntries().iterator(); if (answer != null && answer.hasNext()) { entry = answer.next(); if (answer.hasNext()) { logger.debug("multiple results found for user={}", criteria.getDn()); if (!allowMultipleEntries) { throw new LdapException("Found more than (1) entry for: " + criteria.getDn()); } } } return entry; } }
@Override public LdapEntry resolve(final AuthenticationCriteria criteria, final AuthenticationHandlerResponse response) throws LdapException { final String[] labeledDn = criteria.getDn().split(":", 2); final org.ldaptive.auth.EntryResolver er = entryResolvers.get(labeledDn[0]); if (er == null) { throw new LdapException("Could not find entry resolver for label: " + labeledDn[0]); } return er.resolve(new AuthenticationCriteria(labeledDn[1], criteria.getAuthenticationRequest()), response); } }
@Override public AuthenticationHandlerResponse authenticate(final AuthenticationCriteria criteria) throws LdapException { final String[] labeledDn = criteria.getDn().split(":", 2); final org.ldaptive.auth.AuthenticationHandler ah = authenticationHandlers.get(labeledDn[0]); if (ah == null) { throw new LdapException("Could not find authentication handler for label: " + labeledDn[0]); } return ah.authenticate(new AuthenticationCriteria(labeledDn[1], criteria.getAuthenticationRequest())); } }
@Override public LdapEntry resolve(final AuthenticationCriteria criteria, final AuthenticationHandlerResponse response) throws LdapException { final String[] labeledDn = criteria.getDn().split(":", 2); final org.ldaptive.auth.EntryResolver er = entryResolvers.get(labeledDn[0]); if (er == null) { throw new LdapException("Could not find entry resolver for label: " + labeledDn[0]); } return er.resolve(new AuthenticationCriteria(labeledDn[1], criteria.getAuthenticationRequest()), response); } }
@Override public void close(final RequestControl[] controls) throws LdapException { if (controls != null) { throw new UnsupportedOperationException("Provider does not support unbind with controls"); } try { if (context != null) { context.close(); } } catch (NamingException e) { ResultCode rc = NamingExceptionUtils.getResultCode(e.getClass()); if (rc == null) { rc = NamingExceptionUtils.getResultCode(e.getMessage()); } throw new LdapException(e, rc); } finally { context = null; } }
@Override public void close(final RequestControl[] controls) throws LdapException { if (controls != null) { throw new UnsupportedOperationException("Provider does not support unbind with controls"); } try { if (context != null) { context.close(); } } catch (NamingException e) { ResultCode rc = NamingExceptionUtils.getResultCode(e.getClass()); if (rc == null) { rc = NamingExceptionUtils.getResultCode(e.getMessage()); } throw new LdapException(e, rc); } finally { context = null; } }
@Override protected Response<SearchResult> invoke(final SearchRequest request) throws LdapException { final AsyncSearchListener listener = new AsyncSearchListener(request); getConnection().getProviderConnection().searchAsync(request, listener); try { return listener.getResponse(); } catch (InterruptedException e) { throw new LdapException("Asynchronous search interrupted", e); } }
@Override protected Response<SearchResult> invoke(final SearchRequest request) throws LdapException { final AsyncSearchListener listener = new AsyncSearchListener(request); getConnection().getProviderConnection().searchAsync(request, listener); try { return listener.getResponse(); } catch (InterruptedException e) { throw new LdapException("Asynchronous search interrupted", e); } }
@Override protected Response<SearchResult> invoke(final SearchRequest request) throws LdapException { final AsyncSearchListener listener = new AsyncSearchListener(request); getConnection().getProviderConnection().searchAsync(request, listener); try { return listener.getResponse(); } catch (InterruptedException e) { throw new LdapException("Asynchronous search interrupted", e); } }