From 7324c9d93c3eb95c53a095a2fa7e402d9ec345e7 Mon Sep 17 00:00:00 2001
From: Mark Craig <mark.craig@forgerock.com>
Date: Fri, 28 Oct 2011 15:46:42 +0000
Subject: [PATCH] Some stuff lying around

---
 opendj3/src/main/docbkx/dev-guide/chap-authenticating.xml |   55 +++++++++++++++++++++++++++++++------------------------
 1 files changed, 31 insertions(+), 24 deletions(-)

diff --git a/opendj3/src/main/docbkx/dev-guide/chap-authenticating.xml b/opendj3/src/main/docbkx/dev-guide/chap-authenticating.xml
index 09edac5..2205a03 100644
--- a/opendj3/src/main/docbkx/dev-guide/chap-authenticating.xml
+++ b/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

--
Gitblit v1.10.0