mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

Mark Craig
28.46.2011 7324c9d93c3eb95c53a095a2fa7e402d9ec345e7
opendj3/src/main/docbkx/dev-guide/chap-authenticating.xml
@@ -65,31 +65,38 @@
  the directory determines authorization for operations on the connection
  based on the users identity.</para>
  
  <programlisting language="java">// LDAP simple authentication
final LDAPConnectionFactory factory = new LDAPConnectionFactory(
    hostName, port);
Connection connection = null;
try
{
  connection = factory.getConnection();
  connection.bind(userName, password.toCharArray());
  System.out.println("Authenticated as " + userName + ".");
  // Perform LDAP operations here.
}
// Catch any exceptions here, and then close the connection.
finally
{
  if (connection != null)
  <programlisting language="java">  /**
   * Authenticate over LDAP.
   */
  private static void connect()
  {
    connection.close();
  }
}</programlisting>
    final LDAPConnectionFactory factory = new LDAPConnectionFactory(
      host, port);
    Connection connection = null;
    try
    {
      connection = factory.getConnection();
      connection.bind(bindDN, bindPassword.toCharArray());
      System.out.println("Authenticated as " + bindDN + ".");
    }
    catch (final ErrorResultException e)
    {
      System.err.println(e.getMessage());
      System.exit(e.getResult().getResultCode().intValue());
      return;
    }
    catch (final InterruptedException e)
    {
      System.err.println(e.getMessage());
      System.exit(ResultCode.CLIENT_SIDE_USER_CANCELLED.intValue());
      return;
    }
    finally
    {
      if (connection != null) connection.close();
    }
  }</programlisting>
  
  <para>If the password values do not match, a directory might nevertheless
  authenticate the client application. The LDAP specifications say that in this