/** * * @param ldapConnection */ private void closeConnection(LDAPConnection ldapConnection) { if (ldapConnection != null) { ldapConnection.close(); } }
/** * Disconnect from the LDAP directory server. */ public void disconnect() { connection.close(); }
/** * {@inheritDoc} */ @Override() public void closeInstance() { ldapConnection.close(); }
@Override public void close() { connection.close(); }
/** * Unbinds from the server and closes the connection. * <BR><BR> * If this method is invoked while any operations are in progress on this * connection, then the directory server may or may not abort processing for * those operations, depending on the type of operation and how far along the * server has already gotten while processing that operation. It is * recommended that all active operations be abandoned, canceled, or allowed * to complete before attempting to close an active connection. */ public void close() { close(NO_CONTROLS); }
/** * Closes the connection to the server if the client forgets to do so. * * @throws Throwable If a problem occurs. */ @Override() protected void finalize() throws Throwable { conn.close(); super.finalize(); }
/** * Unbinds from the server and closes the connection. * <BR><BR> * If this method is invoked while any operations are in progress on this * connection, then the directory server may or may not abort processing for * those operations, depending on the type of operation and how far along the * server has already gotten while processing that operation. It is * recommended that all active operations be abandoned, canceled, or allowed * to complete before attempting to close an active connection. */ @ThreadSafety(level=ThreadSafetyLevel.METHOD_NOT_THREADSAFE) public void close() { close(NO_CONTROLS); }
try { final LDAPConnection ldapConnection = new LDAPConnection(hostname,port,bindDN,bindPassword); final DeleteRequest deleteRequest = new DeleteRequest("cn=entry to delete,dc=example,dc=com"); try { LDAPResult deleteResult = connection.delete(deleteRequest); System.out.println("The entry was successfully deleted."); } catch (LDAPException le) { // The delete request failed } finally { ldapConnection.close(); } } catch(final LDAPException ex) { // failed to connect to to the server }
/** * Closes this LDAP entry source. * * @param abandon Indicates whether to attempt to abandon the search. */ private void closeInternal(final boolean abandon) { addToQueue(END_OF_RESULTS); if (closed.compareAndSet(false, true)) { if (abandon) { try { connection.abandon(asyncRequestID); } catch (Exception e) { debugException(e); } } if (closeConnection) { connection.close(); } } }
/** * Creates a new LDAP connection based on the JSON specification. The * connection will be authenticated if appropriate. * * @return The LDAP connection that was created. * * @throws LDAPException If a problem is encountered while trying to * establish or authenticate the connection. */ public LDAPConnection createConnection() throws LDAPException { final LDAPConnection connection = createUnauthenticatedConnection(); if (bindRequest != null) { try { connection.bind(bindRequest); } catch (final LDAPException le) { Debug.debugException(le); connection.close(); throw le; } } return connection; }
/** * Unbinds and disconnects from the directory server. * * @throws LDAPException If a problem occurs. */ public void disconnect() throws LDAPException { authDN = null; authPW = null; conn.close(); if (socketFactory == null) { conn = new com.unboundid.ldap.sdk.LDAPConnection(); } else { conn = new com.unboundid.ldap.sdk.LDAPConnection( new LDAPToJavaSocketFactory(socketFactory)); } }
connection.close(); throw le;
connection.close(); throw le;
protected SearchResult execute(SearchRequest request, String bindDN, String password) { LDAPConnection connection = null; try { if (allowAllSocketFactory) { SSLUtil sslUtil = new SSLUtil(new TrustAllTrustManager()); connection = new LDAPConnection(sslUtil.createSSLSocketFactory(), serverHost, serverPort); } else { connection = new LDAPConnection(serverHost, serverPort); } if (bindDN != null) { BindResult auth = connection.bind(bindDN, password); if (!auth.getResultCode().isConnectionUsable()) { log.error("Connection not usable, result code : " + auth.getResultCode()); } } return connection.search(request); } catch (LDAPException le) { String message = le.getMessage(); if (!message.startsWith("Unable to bind as user ")) { log.error(le.getMessage(), le); } } catch (GeneralSecurityException gse) { log.error(gse.getMessage(), gse); } finally { if (null != connection) { connection.close(); } } return null; }
public AuthToken auth(String username, String password, String token) throws AuthException { String ldapHost = config.get(Config.LDAP_HOST); try { LDAPConnection connection = new LDAPConnection( ldapHost, Integer.valueOf(config.get(Config.LDAP_PORT)), username + "@" + ldapHost, password); if (connection.isConnected()) { return new LDAPToken(connection, username, token); } else { connection.close(); throw new AuthException("Connection not connected."); } } catch (LDAPException e) { throw new AuthException(e.getExceptionMessage()); } } }
private void insertTestUsers() throws LDAPException { LDAPConnection connection = null; try { connection = new LDAPConnection("localhost", 10389); // entry tim/sausages List<Attribute> addRequest = new ArrayList<Attribute>(); addRequest.add(new Attribute("objectClass", "top")); addRequest.add(new Attribute("objectClass", "person")); addRequest.add(new Attribute("objectClass", "organizationalPerson")); addRequest.add(new Attribute("objectClass", "inetOrgPerson")); addRequest.add(new Attribute("cn", "Tim Fox")); addRequest.add(new Attribute("sn", "Fox")); addRequest.add(new Attribute("mail", "tim@example.com")); addRequest.add(new Attribute("uid", "tim")); addRequest.add(new Attribute("userPassword", "{ssha}d0M5Z2qjOOCSCQInvZHgVAleCqU5I+ag9ZHXMw==")); connection.add("uid=tim,ou=users,dc=foo,dc=com", addRequest); } finally { if (connection != null) { connection.close(); } } }
private void insertTestUsers() throws LDAPException { LDAPConnection connection = null; try { connection = new LDAPConnection("localhost", 10389); // entry tim/sausages List<Attribute> addRequest = new ArrayList<>(); addRequest.add(new Attribute("objectClass", "top")); addRequest.add(new Attribute("objectClass", "person")); addRequest.add(new Attribute("objectClass", "organizationalPerson")); addRequest.add(new Attribute("objectClass", "inetOrgPerson")); addRequest.add(new Attribute("cn", "Tim Fox")); addRequest.add(new Attribute("sn", "Fox")); addRequest.add(new Attribute("mail", "tim@example.com")); addRequest.add(new Attribute("uid", "tim")); addRequest.add(new Attribute("userPassword", "{ssha}d0M5Z2qjOOCSCQInvZHgVAleCqU5I+ag9ZHXMw==")); connection.add("uid=tim,ou=users,dc=foo,dc=com", addRequest); } finally { if (connection != null) { connection.close(); } } }
} finally { if (ldapConnection != null) { ldapConnection.close();
connection.close(); throw le;