@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); }
checkState(connection.isConnected(), "not connected"); checkState(connection.isAuthenticated(), "not authenticated"); connection.bind();
/** * 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 boolean isConnected() { return connection.isConnected(); }
/** * {@inheritDoc} */ @Override public boolean isConnected() { return connection.isConnected(); }
/** * {@inheritDoc} */ @Override public boolean isConnected() { return connection.isConnected(); }
/** * Check if we are authenticated * * @return <code>true</code> if we are connected. */ public boolean isAuthenticated() { return isConnected() && authenticated.get(); }
/** * {@inheritDoc} */ public boolean validateObject( Object obj ) { LOG.debug( "validating {}", obj ); LdapConnection connection = ( LdapConnection ) obj; return connection.isConnected(); }
/** * 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(); } }
/** * 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(); } }
/** * 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(); } }
/** * Returns true if {@code connection} is connected, authenticated, and * a lookup on the rootDSE returns a non-null response. * * @param connection The connection to validate * @return True, if the connection is still valid */ public boolean validate(LdapConnection connection) { try { return connection.isConnected() && (connection.lookup(Dn.ROOT_DSE, SchemaConstants.NO_ATTRIBUTE) != null); } catch (LdapException e) { log.info("validating failed: {}", e); return false; } } }
/** * {@inheritDoc} * * There is nothing to do to activate a connection. */ @Override public void activateObject( PooledObject<LdapConnection> connection ) throws LdapException { if ( LOG.isDebugEnabled() ) { LOG.debug( I18n.msg( I18n.MSG_04146_ACTIVATING, connection ) ); } if ( !connection.getObject().isConnected() || !connection.getObject().isAuthenticated() ) { if ( LOG.isDebugEnabled() ) { LOG.debug( I18n.msg( I18n.MSG_04147_REBIND_CONNECTION_DROPPED, connection ) ); } connectionFactory.bindConnection( connection.getObject() ); } }
/** * {@inheritDoc} * * There is nothing to do to activate a connection. */ @Override public void activateObject( PooledObject<LdapConnection> connection ) throws LdapException { if ( LOG.isDebugEnabled() ) { LOG.debug( I18n.msg( I18n.MSG_04146_ACTIVATING, connection ) ); } if ( !connection.getObject().isConnected() || !connection.getObject().isAuthenticated() ) { if ( LOG.isDebugEnabled() ) { LOG.debug( I18n.msg( I18n.MSG_04147_REBIND_CONNECTION_DROPPED, connection ) ); } connectionFactory.bindConnection( connection.getObject() ); } }
@Test public void testValidate() throws Exception { LdapConnection connection = Mockito.mock(LdapConnection.class); when(connection.isConnected()).thenReturn(true); when(connection.lookup(Dn.ROOT_DSE, SchemaConstants.NO_ATTRIBUTE)).thenReturn(Mockito.mock(Entry.class)); assertTrue(validator.validate(connection)); } }
@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)); }
@Test public void testValidateNotConnectedLookupReturnsNull() throws Exception { LdapConnection connection = Mockito.mock(LdapConnection.class); when(connection.isConnected()).thenReturn(false); when(connection.lookup(Dn.ROOT_DSE, SchemaConstants.NO_ATTRIBUTE)).thenReturn(null); assertFalse(validator.validate(connection)); }
@Test public void testValidateNotConnected() { LdapConnection connection = Mockito.mock(LdapConnection.class); when(connection.isConnected()).thenReturn(false); assertFalse(validator.validate(connection)); }