@Override public T getResult() { return getResponse().getResult(); }
@Override public void responseReceived(final Response<Void> response) { searchResponse = new Response<>( searchResult, response.getResultCode(), response.getMessage(), response.getMatchedDn(), response.getControls(), response.getReferralURLs(), response.getMessageId()); responseLock.release(); }
/** * Creates a new response. If the supplied response contains a {@link SyncDoneControl} it is made available via * {@link #getSyncDoneControl()}. * * @param res to search for sync done control in */ public Response(final org.ldaptive.Response<SearchResult> res) { response = res; syncDoneControl = (SyncDoneControl) response.getControl(SyncDoneControl.OID); }
@Override public HandlerResult<Response<S>> handle(final Connection conn, final Q request, final Response<S> response) throws LdapException { final HandlerResult<Response<S>> result; if (referralDepth > referralLimit) { result = new HandlerResult<>( new Response<>( response.getResult(), ResultCode.REFERRAL_LIMIT_EXCEEDED, response.getMessage(), response.getMatchedDn(), response.getControls(), response.getReferralURLs(), response.getMessageId())); } else { final Response<S> referralResponse = followReferral(conn, request, response.getReferralURLs()); if (referralResponse != null) { result = new HandlerResult<>(referralResponse); } else { result = new HandlerResult<>(response); } } return result; }
@Override protected Response<SearchResult> invoke(final SearchRequest request) throws LdapException { Response<SearchResult> response; if (cache != null) { final SearchResult sr = cache.get(request); if (sr == null) { response = executeSearch(request); cache.put(request, response.getResult()); logger.debug("invoke stored result={} in cache", response.getResult()); } else { logger.debug("invoke found result={} in cache", sr); response = new Response<>(sr, null); } } else { response = executeSearch(request); } return response; }
@Override protected AuthenticationHandlerResponse authenticateInternal( final Connection c, final AuthenticationCriteria criteria) throws LdapException { byte[] hash; try { final MessageDigest md = MessageDigest.getInstance(passwordScheme); md.update(criteria.getCredential().getBytes()); hash = md.digest(); } catch (NoSuchAlgorithmException e) { throw new LdapException(e); } final LdapAttribute la = new LdapAttribute( "userPassword", String.format("{%s}%s", passwordScheme, LdapUtils.base64Encode(hash)).getBytes()); final CompareOperation compare = new CompareOperation(c); final CompareRequest request = new CompareRequest(criteria.getDn(), la); request.setControls(getAuthenticationControls()); final Response<Boolean> compareResponse = compare.execute(request); return new AuthenticationHandlerResponse( compareResponse.getResult(), compareResponse.getResultCode(), c, compareResponse.getMessage(), compareResponse.getControls(), compareResponse.getMessageId()); }
/** * Downloads a CRL from given LDAP url. * * @param r the resource that is the ldap url. * @return the x 509 cRL * @throws Exception if connection to ldap fails, or attribute to get the revocation list is unavailable */ protected X509CRL fetchCRLFromLdap(final Object r) throws Exception { try { final String ldapURL = r.toString(); logger.debug("Fetching CRL from ldap {}", ldapURL); final Response<SearchResult> result = performLdapSearch(ldapURL); if (result.getResultCode() == ResultCode.SUCCESS) { final LdapEntry entry = result.getResult().getEntry(); final LdapAttribute attribute = entry.getAttribute(); logger.debug("Located entry [{}]. Retrieving first attribute [{}]", entry, attribute); return fetchX509CRLFromAttribute(attribute); } else { logger.debug("Failed to execute the search [{}]", result); } throw new CertificateException("Failed to establish a connection ldap and search."); } catch (final LdapException e) { logger.error(e.getMessage(), e); throw new CertificateException(e); } }
@Override public ResultCode getResultCode() { return getResponse().getResultCode(); }
if (searchResult.getResultCode() == ResultCode.SUCCESS) { return processSpnegoAttribute(searchResult); + searchResult.getMessage());
/** * Invokes the handlers for the supplied async request. Calls {@link #responseReceived(Response)} if a handler * aborts the operation. * * @param request to handle * * @throws LdapException if a handler throws */ protected void processAsyncRequest(final AsyncRequest request) throws LdapException { logger.trace("processing async request={}", request); final HandlerResult<AsyncRequest> hr = executeHandlers(getAsyncRequestHandlers(), searchRequest, request); if (hr.getAbort()) { logger.debug("Aborting search on async request=%s", request); responseReceived(new Response<>(null, null)); } }
@Override public String getMessage() { return getResponse().getMessage(); }
@Override protected AuthenticationHandlerResponse authenticateInternal( final Connection c, final AuthenticationCriteria criteria) throws LdapException { final byte[] hash = digestCredential(criteria.getCredential(), passwordScheme.getAlgorithm()); final LdapAttribute la = new LdapAttribute( passwordAttribute, String.format("{%s}%s", passwordScheme.getLabel(), LdapUtils.base64Encode(hash)).getBytes()); final CompareOperation compare = new CompareOperation(c); final CompareRequest request = new CompareRequest(criteria.getDn(), la); request.setControls(processRequestControls(criteria)); final Response<Boolean> compareResponse = compare.execute(request); return new AuthenticationHandlerResponse( compareResponse.getResult(), compareResponse.getResultCode(), c, compareResponse.getMessage(), compareResponse.getControls(), compareResponse.getMessageId()); }
/** * Downloads a CRL from given LDAP url. * * @param r the resource that is the ldap url. * @return the x 509 cRL * @throws IOException the exception thrown if resources cant be fetched * @throws CRLException the exception thrown if resources cant be fetched * @throws CertificateException if connection to ldap fails, or attribute to get the revocation list is unavailable */ protected X509CRL fetchCRLFromLdap(final Object r) throws CertificateException, IOException, CRLException { try { val ldapURL = r.toString(); LOGGER.debug("Fetching CRL from ldap [{}]", ldapURL); val result = performLdapSearch(ldapURL); if (result.getResultCode() == ResultCode.SUCCESS) { val entry = result.getResult().getEntry(); val attribute = entry.getAttribute(this.certificateAttribute); if (attribute.isBinary()) { LOGGER.debug("Located entry [{}]. Retrieving first attribute [{}]", entry, attribute); return fetchX509CRLFromAttribute(attribute); } LOGGER.warn("Found certificate attribute [{}] but it is not marked as a binary attribute", this.certificateAttribute); } LOGGER.debug("Failed to execute the search [{}]", result); throw new CertificateException("Failed to establish a connection ldap and search."); } catch (final LdapException e) { LOGGER.error(e.getMessage(), e); throw new CertificateException(e.getMessage()); } }
@Override public HandlerResult<Response<S>> handle(final Connection conn, final Q request, final Response<S> response) throws LdapException { final HandlerResult<Response<S>> result; if (referralDepth > referralLimit) { result = new HandlerResult<>( new Response<>( response.getResult(), ResultCode.REFERRAL_LIMIT_EXCEEDED, response.getMessage(), response.getMatchedDn(), response.getControls(), response.getReferralURLs(), response.getMessageId())); } else { final Response<S> referralResponse = followReferral(conn, request, response.getReferralURLs()); if (referralResponse != null) { result = new HandlerResult<>(referralResponse); } else { result = new HandlerResult<>(response); } } return result; }
@Override protected Response<SearchResult> invoke(final SearchRequest request) throws LdapException { final Response<SearchResult> response; if (cache != null) { final SearchResult sr = cache.get(request); if (sr == null) { response = executeSearch(request); cache.put(request, response.getResult()); logger.debug("invoke stored result={} in cache", response.getResult()); } else { logger.debug("invoke found result={} in cache", sr); response = new Response<>(sr, null); } } else { response = executeSearch(request); } return response; }
@Override public ResultCode getResultCode() { return getResponse().getResultCode(); }
request.setSearchFilter(new SearchFilter(configuration.getValidationFilter())); final Response<SearchResult> execute = new SearchOperation(conn).execute(request); if (execute.getResultCode() != ResultCode.SUCCESS) { description.append(" ").append(execute.getMessage()); return new CheckEvent("ldap", name, description.toString(), KO);
/** * Invokes the handlers for the supplied async request. Calls {@link #responseReceived(Response)} if a handler * aborts the operation. * * @param request to handle * * @throws LdapException if a handler throws */ protected void processAsyncRequest(final AsyncRequest request) throws LdapException { logger.trace("processing async request={}", request); final HandlerResult<AsyncRequest> hr = executeHandlers(getAsyncRequestHandlers(), searchRequest, request); if (hr.getAbort()) { logger.debug("Aborting search on async request=%s", request); responseReceived(new Response<Void>(null, null)); } }
@Override public String getMessage() { return getResponse().getMessage(); }
@Override protected AuthenticationHandlerResponse authenticateInternal( final Connection c, final AuthenticationCriteria criteria) throws LdapException { final byte[] hash = digestCredential(criteria.getCredential(), passwordScheme.getAlgorithm()); final LdapAttribute la = new LdapAttribute( passwordAttribute, String.format("{%s}%s", passwordScheme.getLabel(), LdapUtils.base64Encode(hash)).getBytes()); final CompareOperation compare = new CompareOperation(c); final CompareRequest request = new CompareRequest(criteria.getDn(), la); request.setControls(processRequestControls(criteria)); final Response<Boolean> compareResponse = compare.execute(request); return new AuthenticationHandlerResponse( compareResponse.getResult(), compareResponse.getResultCode(), c, compareResponse.getMessage(), compareResponse.getControls(), compareResponse.getMessageId()); }