From 2b1ccc8723b7cce6708c6f2ac8c10fc1c670b708 Mon Sep 17 00:00:00 2001
From: neil_a_wilson <neil_a_wilson@localhost>
Date: Fri, 02 Feb 2007 19:51:36 +0000
Subject: [PATCH] Add initial support for static groups.  At present, this does not allow for nested static groups, but it does handle changes to the set of available groups and to group membership while the server is online.  It also includes a backend initialization listener API, which makes it possible for components to perform custom processing when a backend is brought online or offline, and this is used to identify all groups at the time that the server is started.

---
 opends/src/server/org/opends/server/api/ClientConnection.java |   49 ++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 46 insertions(+), 3 deletions(-)

diff --git a/opends/src/server/org/opends/server/api/ClientConnection.java b/opends/src/server/org/opends/server/api/ClientConnection.java
index b689c53..4bfd6e6 100644
--- a/opends/src/server/org/opends/server/api/ClientConnection.java
+++ b/opends/src/server/org/opends/server/api/ClientConnection.java
@@ -22,7 +22,7 @@
  * CDDL HEADER END
  *
  *
- *      Portions Copyright 2006 Sun Microsystems, Inc.
+ *      Portions Copyright 2006-2007 Sun Microsystems, Inc.
  */
 package org.opends.server.api;
 
@@ -31,6 +31,7 @@
 import java.net.InetAddress;
 import java.nio.ByteBuffer;
 import java.util.Collection;
+import java.util.HashSet;
 import java.util.Set;
 import java.util.concurrent.CopyOnWriteArrayList;
 
@@ -45,6 +46,8 @@
 import org.opends.server.types.CancelResult;
 import org.opends.server.types.DirectoryException;
 import org.opends.server.types.DisconnectReason;
+import org.opends.server.types.DN;
+import org.opends.server.types.Entry;
 import org.opends.server.types.IntermediateResponse;
 import org.opends.server.types.SearchResultEntry;
 import org.opends.server.types.SearchResultReference;
@@ -980,8 +983,48 @@
     assert debugEnter(CLASS_NAME, "getGroups",
                       String.valueOf(operation));
 
-    // NYI -- Add a mechanism for making this determination.
-    return java.util.Collections.<Group>emptySet();
+
+    // FIXME -- This probably isn't the most efficient implementation.
+    DN authzDN;
+    if (operation == null)
+    {
+      if ((authenticationInfo == null) ||
+          (! authenticationInfo.isAuthenticated()))
+      {
+        authzDN = null;
+      }
+      else
+      {
+        authzDN = authenticationInfo.getAuthorizationDN();
+      }
+    }
+    else
+    {
+      authzDN = operation.getAuthorizationDN();
+    }
+
+    if ((authzDN == null) || authzDN.isNullDN())
+    {
+      return java.util.Collections.<Group>emptySet();
+    }
+
+    Entry userEntry = DirectoryServer.getEntry(authzDN);
+    if (userEntry == null)
+    {
+      return java.util.Collections.<Group>emptySet();
+    }
+
+    HashSet<Group> groupSet = new HashSet<Group>();
+    for (Group g :
+         DirectoryServer.getGroupManager().getGroupInstances())
+    {
+      if (g.isMember(userEntry))
+      {
+        groupSet.add(g);
+      }
+    }
+
+    return groupSet;
   }
 
 

--
Gitblit v1.10.0