/** * Create a new connection. If {@link #connectOnCreate} is true, the connection will be opened. * * @param throwOnFailure whether to throw illegal state exception * * @return pooled connection * * @throws IllegalStateException if {@link #connectOnCreate} is true and the connection cannot be opened */ protected PooledConnectionProxy createConnection(final boolean throwOnFailure) { Connection c = connectionFactory.getConnection(); Response<Void> r = null; if (connectOnCreate) { try { r = c.open(); } catch (LdapException e) { logger.error("{} unable to connect to the ldap", this, e); c = null; if (throwOnFailure) { throw new IllegalStateException("unable to connect to the ldap", e); } } } if (c != null) { return new DefaultPooledConnectionProxy(c, r); } else { return null; } }
/** * Create a new connection. If {@link #connectOnCreate} is true, the connection will be opened. * * @param throwOnFailure whether to throw illegal state exception * * @return pooled connection * * @throws IllegalStateException if {@link #connectOnCreate} is true and the connection cannot be opened */ protected PooledConnectionProxy createConnection(final boolean throwOnFailure) { Connection c = connectionFactory.getConnection(); Response<Void> r = null; if (connectOnCreate) { try { r = c.open(); } catch (LdapException e) { logger.error("{} unable to connect to the ldap", this, e); c = null; if (throwOnFailure) { throw new IllegalStateException("unable to connect to the ldap", e); } } } if (c != null) { return new DefaultPooledConnectionProxy(c, r); } else { return null; } }
/** * Create a new connection. If {@link #connectOnCreate} is true, the connection will be opened. * * @param throwOnFailure whether to throw illegal state exception * * @return pooled connection * * @throws IllegalStateException if {@link #connectOnCreate} is true and the connection cannot be opened */ protected PooledConnectionProxy createConnection(final boolean throwOnFailure) { Connection c = connectionFactory.getConnection(); Response<Void> r = null; if (connectOnCreate) { try { r = c.open(); } catch (LdapException e) { logger.error("{} unable to connect to the ldap", this, e); c = null; if (throwOnFailure) { throw new IllegalStateException("unable to connect to the ldap", e); } } } if (c != null) { return new DefaultPooledConnectionProxy(c, r); } else { return null; } }
@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); }