@Override public String toString() { return String.format( "[%s@%d::resultCode=%s, matchedDn=%s, responseControls=%s, " + "referralURLs=%s, messageId=%s, message=%s, providerException=%s]", getClass().getName(), hashCode(), resultCode, matchedDn, Arrays.toString(responseControls), Arrays.toString(referralURLs), messageId, getMessage(), getCause()); } }
e.getResultCode(), c, e.getMessage(), e.getControls(), e.getMessageId());
@Override public String toString() { return String.format( "[%s@%d::resultCode=%s, matchedDn=%s, responseControls=%s, " + "referralURLs=%s, messageId=%s, message=%s, providerException=%s]", getClass().getName(), hashCode(), resultCode, matchedDn, Arrays.toString(responseControls), Arrays.toString(referralURLs), messageId, getMessage(), getCause()); } }
e.getResultCode(), c, e.getMessage(), e.getControls(), e.getMessageId());
@Override public String toString() { return String.format( "[%s@%d::resultCode=%s, matchedDn=%s, responseControls=%s, " + "referralURLs=%s, messageId=%s, message=%s, providerException=%s]", getClass().getName(), hashCode(), resultCode, matchedDn, Arrays.toString(responseControls), Arrays.toString(referralURLs), messageId, getMessage(), getCause()); } }
e.getResultCode(), c, e.getMessage(), e.getControls(), e.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()); } }
e.getResultCode(), c, e.getMessage(), e.getControls(), e.getMessageId());
logger.debug("Error occurred attempting DN lookup", e); loginSuccess = false; throw new LoginException(e != null ? e.getMessage() : "DN resolution error");
e.getResultCode(), c, e.getMessage(), e.getControls(), e.getMessageId());
logger.debug("Error occurred attempting DN lookup", e); loginSuccess = false; throw new LoginException(e != null ? e.getMessage() : "DN resolution error");
/** * 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 Check check() { final StringBuilder description = new StringBuilder(); description.append(String.format("LDAP bind to %s as %s checked.", url, bindDn)); final Connection conn = DefaultConnectionFactory.getConnection(url); try { conn.open(); BindOperation bind = new BindOperation(conn); bind.execute(new BindRequest(bindDn, new Credential(bindPassword))); } catch (LdapException e) { description.append(" ").append(e.getMessage()); LOGGER.warning(HealthCheckCodes.HS_LDAP_FAILED, "Healthcheck failed, unable to bind as {0} to {1}. Error {2}", e, bindDn, url, e.getMessage()); return new Check(getName(), description.toString(), Status.DOWN); } catch (Throwable t) { description.append(" ").append(t.getMessage()); LOGGER.severe(HealthCheckCodes.HS_LDAP_FAILED_ERROR, "Healthcheck failed, unexpected error, unable to bind as {0} to {1}. Error {2}", t, bindDn, url, t.getMessage()); return new Check(getName(), description.toString(), Status.DOWN); } finally { conn.close(); } return new Check(getName(), description.toString(), Status.UP); }
private AuthenticationResponse getLdapAuthenticationResponse(final UsernamePasswordCredential upc) throws PreventedException { try { LOGGER.debug("Attempting LDAP authentication for [{}]. Authenticator pre-configured attributes are [{}], " + "additional requested attributes for this authentication request are [{}]", upc, authenticator.getReturnAttributes(), authenticatedEntryAttributes); val request = new AuthenticationRequest(upc.getUsername(), new org.ldaptive.Credential(upc.getPassword()), authenticatedEntryAttributes); return authenticator.authenticate(request); } catch (final LdapException e) { LOGGER.trace(e.getMessage(), e); throw new PreventedException("Unexpected LDAP error", e); } }
/** * Execute modify operation boolean. * * @param currentDn the current dn * @param connectionFactory the connection factory * @param attributes the attributes * @return the boolean */ public static boolean executeModifyOperation(final String currentDn, final ConnectionFactory connectionFactory, final Map<String, Set<String>> attributes) { try (Connection modifyConnection = createConnection(connectionFactory)) { final ModifyOperation operation = new ModifyOperation(modifyConnection); final List<AttributeModification> mods = new ArrayList<>(); for (final Map.Entry<String, Set<String>> entry : attributes.entrySet()) { mods.add(new AttributeModification(AttributeModificationType.REPLACE, new LdapAttribute(entry.getKey(), entry.getValue().toArray(new String[]{})))); } final ModifyRequest request = new ModifyRequest(currentDn, mods.toArray(new AttributeModification[]{})); request.setReferralHandler(new ModifyReferralHandler()); operation.execute(request); return true; } catch (final LdapException e) { LOGGER.error(e.getMessage(), e); } return false; }
/** * Execute add operation boolean. * * @param connectionFactory the connection factory * @param entry the entry * @return the boolean * @throws LdapException the ldap exception */ public static boolean executeAddOperation(final ConnectionFactory connectionFactory, final LdapEntry entry) throws LdapException { try (Connection connection = createConnection(connectionFactory)) { final AddOperation operation = new AddOperation(connection); operation.execute(new AddRequest(entry.getDn(), entry.getAttributes())); return true; } catch (final LdapException e) { LOGGER.error(e.getMessage(), e); } return false; }
logger.error(e.getMessage(), e); throw new RuntimeException(e); } finally {
/** * Execute delete operation boolean. * * @param connectionFactory the connection factory * @param entry the entry * @return the boolean * @throws LdapException the ldap exception */ public static boolean executeDeleteOperation(final ConnectionFactory connectionFactory, final LdapEntry entry) throws LdapException { try (Connection connection = createConnection(connectionFactory)) { final DeleteOperation delete = new DeleteOperation(connection); final DeleteRequest request = new DeleteRequest(entry.getDn()); request.setReferralHandler(new DeleteReferralHandler()); final Response<Void> res = delete.execute(request); return res.getResultCode() == ResultCode.SUCCESS; } catch (final LdapException e) { LOGGER.error(e.getMessage(), e); } return false; } }
emitter.onError(new InternalAuthenticationServiceException(e.getMessage(), e));
response = this.authenticator.authenticate(request); } catch (final LdapException e) { logger.trace(e.getMessage(), e); throw new PreventedException("Unexpected LDAP error", e);