Index: src/edu/ucsb/nceas/metacat/AuthLdap.java
===================================================================
--- src/edu/ucsb/nceas/metacat/AuthLdap.java	(revision 727)
+++ src/edu/ucsb/nceas/metacat/AuthLdap.java	(revision 728)
@@ -56,7 +56,23 @@
  * is authenticated, and whether they are a member of a particular group.
  */
 public class AuthLdap implements AuthInterface {
+  
+  private MetaCatUtil util;
+  private String ldapUrl;
+  private String ldapBase;
 
+  /** 
+   * Construct an AuthLdap
+   */
+  public AuthLdap() {
+
+    // Read LDAP URI for directory service information
+    this.util = new MetaCatUtil();
+    this.ldapUrl = util.getOption("ldapurl");
+    this.ldapBase = util.getOption("ldapbase");
+    
+  }
+
   /**
    * Determine if a user/password are valid according to the authentication
    * service.
@@ -68,10 +84,6 @@
   public boolean authenticate(String user, String password)
                     throws ConnectException
   {
-    MetaCatUtil util = new MetaCatUtil();
-    String ldapUrl = util.getOption("ldapurl");
-    String ldapBase = util.getOption("ldapbase");
-
     String distName = null;
     boolean authenticated = false;
 
@@ -125,10 +137,6 @@
   public String[] getUsers(String user, String password) 
          throws ConnectException
   {
-    MetaCatUtil util = new MetaCatUtil();
-    String ldapUrl = util.getOption("ldapurl");
-    String ldapBase = util.getOption("ldapbase");
-
     String[] users = null;
 
     // Identify service provider to use
@@ -187,7 +195,7 @@
     } catch (NamingException e) {
       System.err.println("Problem getting users in AuthLdap.getUsers:" + e);
       throw new ConnectException(
-      "Problem getting groups in AuthLdap.getUsers:" + e);
+      "Problem getting users in AuthLdap.getUsers:" + e);
     }
 
     return users;
@@ -199,10 +207,6 @@
   public String[] getUsers(String user, String password, String group) 
          throws ConnectException
   {
-    MetaCatUtil util = new MetaCatUtil();
-    String ldapUrl = util.getOption("ldapurl");
-    String ldapBase = util.getOption("ldapbase");
-
     String[] users = null;
 
     // Identify service provider to use
@@ -226,9 +230,6 @@
         // Specify the ids of the attributes to return
         String[] attrIDs = {"uniquemember"};
 
-        // Get the dn for this group
-        identifier = getIdentifyingName(group);
-
         // Specify the attributes to match.
         // Groups are objects with attribute objectclass=groupofuniquenames.
         Attributes matchAttrs = new BasicAttributes(true); // ignore case
@@ -243,14 +244,30 @@
         while (enum.hasMore()) {
           SearchResult sr = (SearchResult)enum.next();
           Attributes attrs = sr.getAttributes();
-          // return all attributes
-          NamingEnumeration enum1 = attrs.getAll(); // only "uniquemember" attr
+          // return all attributes (only "uniquemember" attr)
+          NamingEnumeration enum1 = attrs.getAll();
           while (enum1.hasMore()) {
             Attribute attr = (Attribute)enum1.next();
             // return all values of that attribute
             NamingEnumeration enum2 = attr.getAll();
             while (enum2.hasMore()) {
-              uvec.add((String)enum2.next());
+              // get DN of a member
+              String memberDN = (String)enum2.next();
+              try {
+                // we actually need RDN of the member
+                // try to get RDN (UID) of the member in case of a user
+                String memberID = getUserID(memberDN);
+                if ( memberID != null ) {
+                  uvec.add(memberID);
+                // CURRENTLY WE DON'T SUPPORT SUBGROUPING, THUS
+                // IGNORE SUBGROUPS AS MEMBERS OF THE GROUP
+                // // this is a group, not user
+                // // try to get RDN (CN) of the group
+                // } else {
+                //   memberID = getGroupID(memberDN);
+                //   uvec.add(memberID);
+                }
+              } catch (NamingException ne) {}
             }
           }
         }
@@ -268,9 +285,9 @@
       }
 
     } catch (NamingException e) {
-      System.err.println("Problem getting users in AuthLdap.getUsers:" + e);
+      System.err.println("Problem getting users for a group in AuthLdap.getUsers:" + e);
       throw new ConnectException(
-      "Problem getting groups in AuthLdap.getUsers:" + e);
+      "Problem getting users for a group in AuthLdap.getUsers:" + e);
     }
 
     return users;
@@ -277,15 +294,137 @@
   }
 
   /**
+   * Get UID by DN of a member
+   */
+  private String getUserID(String dn) 
+         throws NamingException
+  {
+    String[] users = null;
+
+    // Identify service provider to use
+    Hashtable env = new Hashtable(11);
+    env.put(Context.INITIAL_CONTEXT_FACTORY, 
+            "com.sun.jndi.ldap.LdapCtxFactory");
+    env.put(Context.PROVIDER_URL, ldapUrl); // + ldapBase);
+
+    try {
+
+        // Create the initial directory context
+        DirContext ctx = new InitialDirContext(env);
+
+        // Specify the ids of the attributes to return
+        String[] attrIDs = {"uid"};
+
+        // Ask for "uid" attributes of the user 
+        Attributes attrs = ctx.getAttributes(dn, attrIDs);
+
+        // Print all of the attributes (only "uid" attr)
+        Vector uvec = new Vector();
+        NamingEnumeration en = attrs.getAll();
+        while (en.hasMore()) {
+          Attribute att = (Attribute)en.next();
+          Vector values = new Vector();
+          String attName = att.getID();
+          NamingEnumeration attvalues = att.getAll();
+          while (attvalues.hasMore()) {
+            String value = (String)attvalues.next();
+            values.add(value);
+          }
+          uvec.add(values.elementAt(0));
+        }
+
+        // initialize users[]; fill users[]
+        users = new String[uvec.size()];
+        for (int i=0; i < uvec.size(); i++) {
+          users[i] = (String)uvec.elementAt(i); 
+        }
+
+        // Close the context when we're done
+        ctx.close();
+
+    } catch (NamingException ne) {
+      System.err.println("Problem getting userID by \"dn\" in AuthLdap.getUserID:" + ne);
+      throw ne;
+      //throw new ConnectException(
+      //"Problem getting userID searching by \"dn\" in AuthLdap.getUserID:" + e);
+      //return null;
+    }
+
+    if ( users.length > 0 ) {
+      return users[0];
+    }
+    return null;
+  }
+
+  /**
+   * Get CN by DN of a member
+   */
+  private String getGroupID(String dn) 
+         throws NamingException
+  {
+    String[] groups = null;
+
+    // Identify service provider to use
+    Hashtable env = new Hashtable(11);
+    env.put(Context.INITIAL_CONTEXT_FACTORY, 
+            "com.sun.jndi.ldap.LdapCtxFactory");
+    env.put(Context.PROVIDER_URL, ldapUrl); // + ldapBase);
+
+    try {
+
+        // Create the initial directory context
+        DirContext ctx = new InitialDirContext(env);
+
+        // Specify the ids of the attributes to return
+        String[] attrIDs = {"cn"};
+
+        // Ask for "uid" attributes of the user 
+        Attributes attrs = ctx.getAttributes(dn, attrIDs);
+
+        // Print all of the attributes (only "cn" attr)
+        Vector uvec = new Vector();
+        NamingEnumeration en = attrs.getAll();
+        while (en.hasMore()) {
+          Attribute att = (Attribute)en.next();
+          Vector values = new Vector();
+          String attName = att.getID();
+          NamingEnumeration attvalues = att.getAll();
+          while (attvalues.hasMore()) {
+            String value = (String)attvalues.next();
+            values.add(value);
+          }
+          uvec.add(values.elementAt(0));
+        }
+
+        // initialize users[]; fill users[]
+        groups = new String[uvec.size()];
+        for (int i=0; i < uvec.size(); i++) {
+          groups[i] = (String)uvec.elementAt(i); 
+        }
+
+        // Close the context when we're done
+        ctx.close();
+
+    } catch (NamingException ne) {
+      System.err.println("Problem getting groupID by \"dn\" in AuthLdap.getGroupID:" + ne);
+      throw ne;
+      //throw new ConnectException(
+      //"Problem getting groupID searching by \"dn\" in AuthLdap.getGroupID:" + e);
+      //return null;
+    }
+
+    if ( groups.length > 0 ) {
+      return groups[0];
+    }
+    return null;
+  }
+
+  /**
    * Get all groups from the authentication service
    */
   public String[] getGroups(String user, String password) 
          throws ConnectException
   {
-    MetaCatUtil util = new MetaCatUtil();
-    String ldapUrl = util.getOption("ldapurl");
-    String ldapBase = util.getOption("ldapbase");
-
     String[] groups = null;
 
     // Identify service provider to use
@@ -356,10 +495,6 @@
   public String[] getGroups(String user, String password, String foruser) 
          throws ConnectException
   {
-    MetaCatUtil util = new MetaCatUtil();
-    String ldapUrl = util.getOption("ldapurl");
-    String ldapBase = util.getOption("ldapbase");
-
     String[] groups = null;
 
     // Identify service provider to use
@@ -398,7 +533,7 @@
         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();
             uvec.add(attr.get());
@@ -420,7 +555,7 @@
     } catch (NamingException e) {
       System.err.println("Problem getting groups in AuthLdap.getGroups:" + e);
       throw new ConnectException(
-      "Problem getting groups in AuthLdap.getGroups:" + e);
+      "Problem getting groups for a user in AuthLdap.getGroups:" + e);
     }
 
     return groups;
@@ -449,10 +584,6 @@
   public HashMap getAttributes(String user, String password, String foruser) 
          throws ConnectException
   {
-    MetaCatUtil util = new MetaCatUtil();
-    String ldapUrl = util.getOption("ldapurl");
-    String ldapBase = util.getOption("ldapbase");
-
     HashMap attributes = new HashMap();
 
     // Identify service provider to use
@@ -519,10 +650,6 @@
   private String getIdentifyingName(String user) 
          throws NamingException
   {
-    MetaCatUtil util = new MetaCatUtil();
-    String ldapUrl = util.getOption("ldapurl");
-    String ldapBase = util.getOption("ldapbase");
-
     String identifier = null;
 
     // Identify service provider to use
@@ -590,7 +717,7 @@
     Vector usersIn = new Vector();
     
     out.append("<?xml version=\"1.0\"?>\n");
-    out.append("<principals>\n");
+    out.append("<principals authSystemURI=\"" + ldapUrl + ldapBase + "\">\n");
     
     // for the groups and users that belong to them
     if ( groups.length > 0 ) {
@@ -638,6 +765,7 @@
       if (isValid) {
         System.out.println("Authentication successful for: " + user );
         System.out.println(" ");
+        
       } else {
         System.out.println("Authentication failed for: " + user);
       }
Index: src/edu/ucsb/nceas/metacat/AuthSession.java
===================================================================
--- src/edu/ucsb/nceas/metacat/AuthSession.java	(revision 727)
+++ src/edu/ucsb/nceas/metacat/AuthSession.java	(revision 728)
@@ -41,6 +41,8 @@
   private String authClass = null;
   private HttpSession session = null;
   private AuthInterface authService = null;
+  private String ldapUrl;
+  private String ldapBase;
   private String statusMessage = null;
  
   /** 
@@ -51,8 +53,10 @@
     // Determine our session authentication method and
     // create an instance of the auth class
     MetaCatUtil util = new MetaCatUtil();
-    authClass = util.getOption("authclass");
-    authService = (AuthInterface)createObject(authClass);
+    this.authClass = util.getOption("authclass");
+    this.authService = (AuthInterface)createObject(authClass);
+    this.ldapUrl = util.getOption("ldapurl");
+    this.ldapBase = util.getOption("ldapbase");
     
   }
 
@@ -138,7 +142,7 @@
     String[] groups = authService.getGroups(user, password);
     
     out.append("<?xml version=\"1.0\"?>\n");
-    out.append("<principals>\n");
+    out.append("<principals authSystemURI=\"" + ldapUrl + ldapBase + "\">\n");
     
     // for the groups and users that belong to them
     if ( groups.length > 0 ) {
