Index: src/edu/ucsb/nceas/metacat/AuthLdap.java
===================================================================
--- src/edu/ucsb/nceas/metacat/AuthLdap.java	(revision 725)
+++ src/edu/ucsb/nceas/metacat/AuthLdap.java	(revision 726)
@@ -152,10 +152,13 @@
         // Specify the ids of the attributes to return
         String[] attrIDs = {"uid"};
 
+        // Specify the attributes to match.
+        // Users are objects that have the attribute objectclass=InetOrgPerson.
+        Attributes matchAttrs = new BasicAttributes(true); // ignore case
+        matchAttrs.put(new BasicAttribute("objectclass", "inetOrgPerson"));
+
         // Search for objects in the current context
-        // All users should be put in subcontext like "ou=Users"
-        // NamingEnumeration answer = ctx.search("ou=Users", null, attrIDs);
-        NamingEnumeration enum = ctx.search("", null, attrIDs);
+        NamingEnumeration enum = ctx.search("", matchAttrs, attrIDs);
 
         // Print the users
         Vector uvec = new Vector();
@@ -165,8 +168,6 @@
           NamingEnumeration enum1 = attrs.getAll(); // only "uid" attr
           while (enum1.hasMore()) {
             Attribute attr = (Attribute)enum1.next();
-            //System.out.print(attr.getID() + "=");
-            //System.out.println((String)attr.get());
             uvec.add(attr.get());
           }
         }
@@ -223,16 +224,18 @@
         DirContext ctx = new InitialDirContext(env);
 
         // Specify the ids of the attributes to return
-        String[] attrIDs = {"uid"};
+        String[] attrIDs = {"uniquemember"};
 
+        // Get the dn for this group
+        identifier = getIdentifyingName(group);
+
         // Specify the attributes to match.
-        // Ask for objects that have the attribute gid == @group.
+        // Groups are objects with attribute objectclass=groupofuniquenames.
         Attributes matchAttrs = new BasicAttributes(true); // ignore case
-        matchAttrs.put(new BasicAttribute("gid", group));
+        matchAttrs.put(new BasicAttribute("objectclass", "groupofuniquenames"));
+        matchAttrs.put(new BasicAttribute("cn", group));
 
         // Search for objects in the current context
-        // All users should be put in subcontext like "ou=Users"
-        // NamingEnumeration answer=ctx.search("ou=Users",matchAttrs,attrIDs);
         NamingEnumeration enum = ctx.search("", matchAttrs, attrIDs);
 
         // Print the users
@@ -240,12 +243,15 @@
         while (enum.hasMore()) {
           SearchResult sr = (SearchResult)enum.next();
           Attributes attrs = sr.getAttributes();
-          NamingEnumeration enum1 = attrs.getAll(); // only "uid" attr
+          // return all attributes
+          NamingEnumeration enum1 = attrs.getAll(); // only "uniquemember" attr
           while (enum1.hasMore()) {
             Attribute attr = (Attribute)enum1.next();
-            //System.out.print(attr.getID() + "=");
-            //System.out.println((String)attr.get());
-            uvec.add(attr.get());
+            // return all values of that attribute
+            NamingEnumeration enum2 = attr.getAll();
+            while (enum2.hasMore()) {
+              uvec.add((String)enum2.next());
+            }
           }
         }
 
@@ -301,19 +307,15 @@
         DirContext ctx = new InitialDirContext(env);
 
         // Specify the ids of the attributes to return
-        String[] attrIDs = {"gid"};
-        SearchControls ctls = new SearchControls();
-        ctls.setReturningAttributes(attrIDs);
+        String[] attrIDs = {"cn"};
 
-        // Specify the search filter to match.
-        // Ask for objects that do not have "uid".
-        // This will assure that the directory entries are groups.
-        String filter = "(!(uid=*))";
-          
+        // Specify the attributes to match.
+        // Groups are objects with attribute objectclass=groupofuniquenames.
+        Attributes matchAttrs = new BasicAttributes(true); // ignore case
+        matchAttrs.put(new BasicAttribute("objectclass", "groupofuniquenames"));
+
         // Search for objects in the current context
-        // All users should be put in subcontext like "ou=Users"
-        // NamingEnumeration answer = ctx.search("ou=Users", filter,ctls);
-        NamingEnumeration enum = ctx.search("", filter, ctls);
+        NamingEnumeration enum = ctx.search("", matchAttrs, attrIDs);
 
         // Print the users
         Vector uvec = new Vector();
@@ -320,11 +322,9 @@
         while (enum.hasMore()) {
           SearchResult sr = (SearchResult)enum.next();
           Attributes attrs = sr.getAttributes();
-          NamingEnumeration enum1 = attrs.getAll(); // only "gid" attr
+          NamingEnumeration enum1 = attrs.getAll(); // only "cn" attr
           while (enum1.hasMore()) {
             Attribute attr = (Attribute)enum1.next();
-            //System.out.print(attr.getID() + "=");
-            //System.out.println((String)attr.get());
             uvec.add(attr.get());
           }
         }
@@ -381,16 +381,16 @@
         DirContext ctx = new InitialDirContext(env);
 
         // Specify the ids of the attributes to return
-        String[] attrIDs = {"gid"};
+        String[] attrIDs = {"cn"};
 
         // Specify the attributes to match.
-        // Ask for objects that have the attribute uid == @foruser.
+        // Groups are objects with attribute objectclass=groupofuniquenames.
+        // and have attribute uniquemember=foruser,ldapbase.
         Attributes matchAttrs = new BasicAttributes(true); // ignore case
-        matchAttrs.put(new BasicAttribute("uid", foruser));
+        matchAttrs.put(new BasicAttribute("objectclass", "groupofuniquenames"));
+        matchAttrs.put(new BasicAttribute("uniquemember",foruser+","+ldapBase));
 
         // Search for objects in the current context
-        // All users should be put in subcontext like "ou=Users"
-        // NamingEnumeration answer=ctx.search("ou=Users",matchAttrs,attrIDs);
         NamingEnumeration enum = ctx.search("", matchAttrs, attrIDs);
 
         // Print the users
@@ -401,8 +401,6 @@
           NamingEnumeration enum1 = attrs.getAll(); // only "gid" attr
           while (enum1.hasMore()) {
             Attribute attr = (Attribute)enum1.next();
-            //System.out.print(attr.getID() + "=");
-            //System.out.println((String)attr.get());
             uvec.add(attr.get());
           }
         }
@@ -589,6 +587,7 @@
   {
     StringBuffer out = new StringBuffer();
     String[] groups = getGroups(user, password);
+    Vector usersIn = new Vector();
     
     out.append("<?xml version=\"1.0\"?>\n");
     out.append("<principals>\n");
@@ -599,17 +598,19 @@
         out.append("  <group>\n");
         out.append("    <groupname>" + groups[i] + "<groupname>\n");
         String[] usersForGroup = getUsers(user,password,groups[i]);
-        for (int j=0; j <= usersForGroup.length; j++ ) {
+        for (int j=0; j < usersForGroup.length; j++ ) {
+          usersIn.addElement(usersForGroup[j]);
           out.append("    <user>\n");
           out.append("      <username>" + usersForGroup[j] + "<username>\n");
           out.append("    </user>\n");
         }
-        out.append("</group>\n");
+        out.append("  </group>\n");
       }
-    // for the users only when there are no any groups defined
-    } else {
-      String[] users = getUsers(user, password);
-      for (int j=0; j < users.length; j++ ) {
+    }
+    // for the users not belonging to any group
+    String[] users = getUsers(user, password);
+    for (int j=0; j < users.length; j++ ) {
+      if ( !usersIn.contains(users[j]) ) {
         out.append("  <user>\n");
         out.append("    <username>" + users[j] + "<username>\n");
         out.append("  </user>\n");
@@ -642,8 +643,8 @@
       }
 
       if (isValid) {
+        //String group = args[2];
         HashMap userInfo = authservice.getAttributes(user, password, user);
-
         // Print all of the attributes
         Iterator attList = (Iterator)(((Set)userInfo.keySet()).iterator());
         while (attList.hasNext()) {
@@ -665,6 +666,7 @@
         for (int i=0; i < users.length; i++) {
           System.out.println(users[i]);          
         }
+        System.out.println("Total " + users.length + " users.");
       }
 */
 /*
@@ -677,7 +679,7 @@
         }
       }
 */
-/*      // get the whole list groups and users in XML format
+      // get the whole list groups and users in XML format
       if (isValid) {
         String out = authservice.getPrincipals(user, password);
         java.io.File f = new java.io.File("principals.txt");
@@ -688,7 +690,7 @@
         buff.close();
         fw.close();
       }
-*/
+
     } catch (ConnectException ce) {
       System.err.println("Error connecting to LDAP server in authldap.main");
     } catch (java.io.IOException ioe) {
Index: src/edu/ucsb/nceas/metacat/AuthSession.java
===================================================================
--- src/edu/ucsb/nceas/metacat/AuthSession.java	(revision 725)
+++ src/edu/ucsb/nceas/metacat/AuthSession.java	(revision 726)
@@ -146,7 +146,7 @@
         out.append("  <group>\n");
         out.append("    <groupname>" + groups[i] + "<groupname>\n");
         String[] usersForGroup = authService.getUsers(user,password,groups[i]);
-        for (int j=0; j <= usersForGroup.length; j++ ) {
+        for (int j=0; j < usersForGroup.length; j++ ) {
           out.append("    <user>\n");
           out.append("      <username>" + usersForGroup[j] + "<username>\n");
           out.append("    </user>\n");
