From 06b521335fbe2a64d9d0840fedd8bc2fdd52e535 Mon Sep 17 00:00:00 2001
From: neil_a_wilson <neil_a_wilson@localhost>
Date: Thu, 16 Aug 2007 21:37:56 +0000
Subject: [PATCH] Add a new convenience constructor for the InternalClientConnection class that allows you to create a new internal client connection authenticated as a given user by providing only that user's DN (as opposed to having to create an AuthenticationInfo object for the user in order to use the other constructor).
---
opends/src/server/org/opends/server/protocols/internal/InternalClientConnection.java | 61 ++++++++++++++++++++++++++++++
1 files changed, 61 insertions(+), 0 deletions(-)
diff --git a/opends/src/server/org/opends/server/protocols/internal/InternalClientConnection.java b/opends/src/server/org/opends/server/protocols/internal/InternalClientConnection.java
index fe888a4..d90aaca 100644
--- a/opends/src/server/org/opends/server/protocols/internal/InternalClientConnection.java
+++ b/opends/src/server/org/opends/server/protocols/internal/InternalClientConnection.java
@@ -311,6 +311,67 @@
/**
+ * Creates a new internal client connection that will be
+ * authenticated as the specified user.
+ *
+ * @param userDN The DN of the entry to use as the
+ * authentication and authorization identity.
+ *
+ * @throws DirectoryException If a problem occurs while trying to
+ * get the entry for the provided user
+ * DN.
+ */
+ public InternalClientConnection(DN userDN)
+ throws DirectoryException
+ {
+ this(getAuthInfoForDN(userDN));
+ }
+
+
+
+ /**
+ * Creates an authentication information object for the user with
+ * the specified DN.
+ *
+ * @param userDN The DN of the user for whom to create an
+ * authentication information object.
+ *
+ * @return The appropriate authentication information object.
+ *
+ * @throws DirectoryException If a problem occurs while trying to
+ * create the authentication
+ * information object, or there is no
+ * such user in the directory.
+ */
+ private static AuthenticationInfo getAuthInfoForDN(DN userDN)
+ throws DirectoryException
+ {
+ if ((userDN == null) || userDN.isNullDN())
+ {
+ return new AuthenticationInfo();
+ }
+
+ DN rootUserDN = DirectoryServer.getActualRootBindDN(userDN);
+ if (rootUserDN != null)
+ {
+ userDN = rootUserDN;
+ }
+
+ Entry userEntry = DirectoryServer.getEntry(userDN);
+ if (userEntry == null)
+ {
+ Message m =
+ ERR_INTERNALCONN_NO_SUCH_USER.get(String.valueOf(userDN));
+ throw new DirectoryException(ResultCode.NO_SUCH_OBJECT, m);
+ }
+
+ boolean isRoot = DirectoryServer.isRootDN(userDN);
+ return new AuthenticationInfo(userEntry, isRoot);
+ }
+
+
+
+ /**
* Retrieves a shared internal client connection that is
* authenticated as a root user.
*
--
Gitblit v1.10.0