@Override public com.google.common.base.Optional<Boolean> isHealthy() { try { final LdapConnection connection = connectionPool.getConnection(); try { if (connection.isConnected() && connection.isAuthenticated()) { connection.bind(); try { return com.google.common.base.Optional.of(true); } finally { connection.unBind(); } } } finally { connectionPool.releaseConnection(connection); } } catch (LdapException e) { LOG.warn("LdapException caught when checking health", e); exceptionNotifier.notify(String.format("LdapException caught when checking health (%s)", e.getMessage()), e); } return com.google.common.base.Optional.of(false); }
/** * {@inheritDoc} */ @Override public SearchCursor search( SearchRequest searchRequest ) throws LdapException { return connection.search( searchRequest ); }
/** * {@inheritDoc} */ @Override public Entry lookup( String dn, String... attributes ) throws LdapException { return connection.lookup( dn, attributes ); }
/** * Returns true if <code>connection</code> is connected, and authenticated. * * @param connection The connection to validate * @return True, if the connection is still valid */ @Override public boolean validate( LdapConnection connection ) { return connection.isConnected() && connection.isAuthenticated(); } }
/** * Close the connection for stop() */ private void closeConnection() throws IOException { if (connection.isConnected()) { connection.close(); } }
boolean wasConnected = connection.isConnected(); connection.connect(); Entry rootDse = connection.lookup( Dn.ROOT_DSE, SchemaConstants.SUBSCHEMA_SUBENTRY_AT, SchemaConstants.VENDOR_NAME_AT ); subschemaSubentryDn = new Dn( connection.getSchemaManager(), subschemaSubentryAttribute.getString() ); subschemaSubentryDn = new Dn( connection.getSchemaManager(), subschemaSubentryAttribute.getString() ); if ( ( !wasConnected ) && ( connection.isConnected() ) ) connection.close();
/** * {@inheritDoc} */ @Override public void bind( String name ) throws LdapException { connection.bind( name ); bindCalled = true; }
@JsonIgnore public Entry getEntry(final LdapConnection connection, final String filter, final String... attributes) throws LdapException, CursorException, IOException { connection.bind(); try (final EntryCursor cursor = connection.search(baseDn, filter, SearchScope.SUBTREE, attributes)) { if (!cursor.next()) return null; return cursor.get(); } }
public void updateString(final LdapConnection connection, final String dn, final String attr, final String... values) throws LdapException { connection.bind(); final Modification modif = new DefaultModification(ModificationOperation.REPLACE_ATTRIBUTE, attr, values); connection.modify(dn + ", " + baseDn, modif); }
@Test public void testValidateLookupReturnsNull() throws Exception { LdapConnection connection = Mockito.mock(LdapConnection.class); when(connection.isConnected()).thenReturn(true); when(connection.lookup(Dn.ROOT_DSE, SchemaConstants.NO_ATTRIBUTE)).thenReturn(null); assertFalse(validator.validate(connection)); }
public LdapConnection connect() throws Exception { final LdapConnection connection = getConnection(); if (!connection.connect()) { log.error("Cannot establish a connection to LDAP server"); throw new DlabException("Login user failed. LDAP server is not available"); } connection.bind(); return connection; } }
/** * {@inheritDoc} */ @Override public void add( Entry entry ) throws LdapException { connection.add( entry ); }
/** * {@inheritDoc} */ @Override public ModifyResponse modify( ModifyRequest modRequest ) throws LdapException { return connection.modify( modRequest ); }
/** * {@inheritDoc} */ @Override public DeleteResponse delete( DeleteRequest deleteRequest ) throws LdapException { return connection.delete( deleteRequest ); }
/** * Returns true if {@code connection} is connected * * @param connection The connection to validate * @return True, if the connection is still valid */ @Override public boolean validate( LdapConnection connection ) { return connection.isConnected(); } }
/** * {@inheritDoc} */ @Override public void close() throws IOException { connection.close(); }
ldapConnection.connect(); if (!ldapConnection.isConnected()) { continue; } else { if (ldapConnection == null || !ldapConnection.isConnected()) { throw new LdapException("Unable to connect to any of those ldap servers " + Arrays.toString(ldapHosts));