0

I am creating a LDAP Connection using ldap connect function. Then I authenticate the user with username and password using bind.

I want to ask if the bind fails then, does the Connection is terminated or I need to disconnect it explicitly using disconnect?

P.S.: I am using Java LDAP.

UPDATE:

I am using connect and bind functions from class LDAPConnection in com.novell.ldap.*.

0xF1
  • 6,046
  • 2
  • 27
  • 50

2 Answers2

0

As you have not mentioned any library I am assuming you are using javax.naming.ldap.LdapContext.

When using LdapContext, you usually connect/bind with new InitialLdapContext(environment, null);

If that's the case, and the bind fails, you won't even get the object of LdapContext as the code will throw exception. So you don't need to (if fact you can't) call ldapContext.close()

If there is some library that is being used, you may need to refer that library's documentation.

Update:

Looking at the javadoc of the library that you are using, it seems that the connection is not closed when the bind fails as it tries to make an anonymous connection first. I feel you should explicitly close the connection.

kdabir
  • 9,623
  • 3
  • 43
  • 45
  • Thanks for your answer, but I am not using this library and I have updated my question mentioning proper API. – 0xF1 Feb 18 '14 at 08:14
0

If you have a object you can close or disconnect, you must close or disconnect it.

user207421
  • 305,947
  • 44
  • 307
  • 483