From 9020a676bbe359cb158e96761ef6f1a3c32c80e5 Mon Sep 17 00:00:00 2001
From: Yannick Lecaillez <yannick.lecaillez@forgerock.com>
Date: Tue, 10 May 2016 16:42:27 +0000
Subject: [PATCH] REST2LDAP Refactoring

---
 opendj-server-legacy/src/main/java/org/opends/server/protocols/http/LDAPContext.java |   54 ++++++++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 44 insertions(+), 10 deletions(-)

diff --git a/opendj-server-legacy/src/main/java/org/opends/server/protocols/http/LDAPContext.java b/opendj-server-legacy/src/main/java/org/opends/server/protocols/http/LDAPContext.java
index 4c46a36..bb99b76 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/protocols/http/LDAPContext.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/protocols/http/LDAPContext.java
@@ -13,30 +13,64 @@
  *
  * Copyright 2016 ForgeRock AS.
  */
+
 package org.opends.server.protocols.http;
 
-import org.forgerock.opendj.ldap.ConnectionFactory;
+import org.forgerock.opendj.ldap.Connection;
+import org.forgerock.opendj.ldap.DN;
+import org.forgerock.opendj.ldap.LdapException;
 import org.forgerock.services.context.AbstractContext;
 import org.forgerock.services.context.Context;
 
-/** Context provided by this LDAP server to the embedded {@link org.forgerock.http.HttpApplication}s. */
+/**
+ * Context provided by a Directory Server. It contains a reference to a
+ * {@link InternalConnectionFactory} which can be used to perform direct LDAP
+ * operation on this Directory Server without the network overhead.
+ */
 public final class LDAPContext extends AbstractContext
 {
-  private final ConnectionFactory ldapConnectionFactory;
+  private final InternalConnectionFactory internalConnectionFactory;
 
-  LDAPContext(final Context parent, ConnectionFactory ldapConnectionFactory)
+  /**
+   * Create a new LDAPContext.
+   *
+   * @param parent
+   *          The parent context.
+   * @param internalConnectionFactory
+   *          Internal connection factory of this LDAP server.
+   */
+  public LDAPContext(final Context parent, InternalConnectionFactory internalConnectionFactory)
   {
     super(parent, "LDAP context");
-    this.ldapConnectionFactory = ldapConnectionFactory;
+    this.internalConnectionFactory = internalConnectionFactory;
   }
 
   /**
-   * Get the {@link org.forgerock.opendj.ldap.LDAPConnectionFactory} attached to this context.
+   * Get the {@link InternalConnectionFactory} attached to this context.
    *
-   * @return The {@link org.forgerock.opendj.ldap.LDAPConnectionFactory} attached to this context.
+   * @return The {@link InternalConnectionFactory} attached to this context.
    */
-  public ConnectionFactory getLdapConnectionFactory()
+  public InternalConnectionFactory getInternalConnectionFactory()
   {
-    return ldapConnectionFactory;
+    return internalConnectionFactory;
   }
-}
+
+  /**
+   * An internal connection factory providing direct connection to this Directory
+   * Server without the network overhead.
+   */
+  public interface InternalConnectionFactory
+  {
+    /**
+     * Get a direct {@link Connection} to this Directory Server.
+     *
+     * @param userDN
+     *          DN of the user's used to validate authorization.
+     * @return A direct {@link Connection} to this Directory Server.
+     * @throws LdapException
+     *           If a connection cannot be create (i.e: because the userDN
+     *           doesn't exists).
+     */
+    Connection getConnection(DN userDN) throws LdapException;
+  }
+}
\ No newline at end of file

--
Gitblit v1.10.0