Index: src/edu/ucsb/nceas/metacat/AuthLdap.java
===================================================================
--- src/edu/ucsb/nceas/metacat/AuthLdap.java	(revision 2057)
+++ src/edu/ucsb/nceas/metacat/AuthLdap.java	(revision 2058)
@@ -58,7 +58,7 @@
 /**
  * An implementation of the AuthInterface interface that
  * allows Metacat to use the LDAP protocol for directory services.
- * The LDAP authentication service is used to determine if a user 
+ * The LDAP authentication service is used to determine if a user
  * is authenticated, and whether they are a member of a particular group.
  */
 public class AuthLdap implements AuthInterface, Runnable {
@@ -75,7 +75,7 @@
   ReferralException refExc;
   //String uid=null;
 
-  /** 
+  /**
    * Construct an AuthLdap
    */
   public AuthLdap() {
@@ -104,7 +104,7 @@
     String identifier = user;
     //get uid here.
     //uid=user.substring(0, user.indexOf(","));
-  
+
     try {
         // Check the usename as passed in
         authenticated = ldapAuthenticate(identifier, password);
@@ -138,16 +138,16 @@
             }
             //authenticated = ldapAuthenticate(identifier, password);
         }
-     
+
     } catch (NullPointerException e) {
       util.debugMessage("NullPointerException b' password is null", 30);
-      util.debugMessage("NullPointerException while authenticating in " + 
+      util.debugMessage("NullPointerException while authenticating in " +
                         "AuthLdap.authenticate: " + e, 30);
       throw new ConnectException(
-      "NullPointerException while authenticating in " + 
+      "NullPointerException while authenticating in " +
                         "AuthLdap.authenticate: " + e);
     } catch (NamingException e) {
-      util.debugMessage("Naming exception while authenticating in " + 
+      util.debugMessage("Naming exception while authenticating in " +
                         "AuthLdap.authenticate: " + e, 30);
       e.printStackTrace();
     } catch (Exception e) {
@@ -166,7 +166,7 @@
   private boolean ldapAuthenticate(String identifier, String password)
             throws ConnectException, NamingException, NullPointerException
   {
-      return ldapAuthenticate(identifier, password, 
+      return ldapAuthenticate(identifier, password,
                               this.ldapsUrl, this.ldapBase);
   }
 
@@ -184,13 +184,13 @@
     double totStartTime = System.currentTimeMillis();
     boolean authenticated = false;
     if (identifier != null && !password.equals("")) {
-    
+
         //Pass the username and password to run() method
         userName=identifier;
         userPassword=password;
         // Identify service provider to use
         Hashtable env = new Hashtable(11);
-        env.put(Context.INITIAL_CONTEXT_FACTORY, 
+        env.put(Context.INITIAL_CONTEXT_FACTORY,
               "com.sun.jndi.ldap.LdapCtxFactory");
         env.put(Context.REFERRAL, "throw");
         env.put(Context.PROVIDER_URL, directoryUrl + searchBase);
@@ -233,7 +233,7 @@
 
             Thread t = new Thread(this);
             t.start();
-            Thread.sleep(5000); //this is a manual override of ldap's 
+            Thread.sleep(5000); //this is a manual override of ldap's
                                 //hideously long time out period.
             util.debugMessage("Awake after 5 seconds.", 35);
             if (referralContext == null) {
@@ -246,17 +246,17 @@
             authenticated = false;
           }
         }
-    } else { 
+    } else {
         util.debugMessage("User not found", 30);
     }
     double totStopTime = System.currentTimeMillis();
-    util.debugMessage("total ldap authentication time: " + 
+    util.debugMessage("total ldap authentication time: " +
                       (totStopTime - totStartTime)/1000 + " seconds", 35);
     return authenticated;
   }
-  
-  
 
+
+
   /**
    * Get the identifying name for a given userid or name.  This is the name
    * that is used in conjunction withthe LDAP BaseDN to create a
@@ -263,7 +263,7 @@
    * distinguished name (dn) for the record
    *
    * @param user the user for which the identifying name is requested
-   * @returns String the identifying name for the user, 
+   * @returns String the identifying name for the user,
    *          or null if not found
    */
   private String getIdentifyingName(String user, String ldapUrl,
@@ -279,13 +279,13 @@
     env.put(Context.PROVIDER_URL, ldapUrl + ldapBase);
     //    non-secure LDAP context; dn are publicly readable
     try {
-      
+
       // Bind to the LDAP server, in order to search for the right
       // distinguished name (dn) based on userid (uid) or common name (cn)
       DirContext ctx = new InitialDirContext(env);
       SearchControls ctls = new SearchControls();
       ctls.setSearchScope(SearchControls.SUBTREE_SCOPE);
-      // Search for the user id or name using the uid, then cn and sn 
+      // Search for the user id or name using the uid, then cn and sn
       //attributes
       // If we find a record, determine the dn for the record
       // The following blocks need to be refactored into a subroutine
@@ -296,7 +296,7 @@
       int position = user.indexOf(",");
       String comp1 = user.substring(0, position);
       MetaCatUtil.debugMessage("First comp is: " + comp1, 35);
-      String comp2 = user.substring(position+1, 
+      String comp2 = user.substring(position+1,
                                     user.indexOf(",", position+1));
       MetaCatUtil.debugMessage("Second comp is: " + comp2, 35);
 
@@ -331,7 +331,7 @@
         if (answer.hasMore()) {
           SearchResult sr = (SearchResult)answer.next();
           identifier = sr.getName();
-          if ( !sr.isRelative() ) { 
+          if ( !sr.isRelative() ) {
             this.ldapUrl = identifier.substring(0,
                                                 identifier.lastIndexOf("/")+1);
             this.ldapBase = identifier.substring(identifier.indexOf(",")+1);
@@ -350,7 +350,7 @@
       if (answer.hasMore()) {
         SearchResult sr = (SearchResult)answer.next();
         identifier = sr.getName();
-        if ( !sr.isRelative() ) { 
+        if ( !sr.isRelative() ) {
           this.ldapUrl = identifier.substring(0,identifier.lastIndexOf("/")+1);
           this.ldapBase = identifier.substring(identifier.indexOf(",")+1);
           identifier = identifier.substring(identifier.lastIndexOf("/")+1,
@@ -366,7 +366,7 @@
         if (answer2.hasMore()) {
           SearchResult sr = (SearchResult)answer2.next();
           identifier = sr.getName();
-          if ( !sr.isRelative() ) { 
+          if ( !sr.isRelative() ) {
             this.ldapUrl = identifier.substring(0,
                                                 identifier.lastIndexOf("/")+1);
             this.ldapBase = identifier.substring(identifier.indexOf(",")+1);
@@ -383,7 +383,7 @@
           if (answer3.hasMore()) {
             SearchResult sr = (SearchResult)answer3.next();
             identifier = sr.getName();
-            if ( !sr.isRelative() ) { 
+            if ( !sr.isRelative() ) {
               this.ldapUrl = identifier.substring(0,
                                                 identifier.lastIndexOf("/")+1);
               this.ldapBase = identifier.substring(identifier.indexOf(",")+1);
@@ -412,18 +412,18 @@
    * @param password the password for authenticating against the service
    * @returns string array of all of the user names
    */
-  public String[] getUsers(String user, String password) 
+  public String[][] getUsers(String user, String password)
          throws ConnectException
   {
-    String[] users = null;
+    String[][] users = null;
 
     // Identify service provider to use
     Hashtable env = new Hashtable(11);
-    env.put(Context.INITIAL_CONTEXT_FACTORY, 
+    env.put(Context.INITIAL_CONTEXT_FACTORY,
             "com.sun.jndi.ldap.LdapCtxFactory");
     env.put(Context.REFERRAL, referral);
     env.put(Context.PROVIDER_URL, ldapUrl);
- 
+
     try {
 
         // Create the initial directory context
@@ -432,18 +432,35 @@
         // Specify the attributes to match.
         // Users are objects that have the attribute objectclass=InetOrgPerson.
         SearchControls ctls = new SearchControls();
-        String[] attrIDs = {"dn"};
+        String[] attrIDs = {"dn", "cn", "mail"};
         ctls.setReturningAttributes(attrIDs);
         ctls.setSearchScope(SearchControls.SUBTREE_SCOPE);
         //ctls.setCountLimit(1000);
         String filter = "(objectClass=inetOrgPerson)";
         NamingEnumeration enum = ctx.search(ldapBase, filter, ctls);
-        
+
         // Store the users in a vector
         Vector uvec = new Vector();
+        Vector uname = new Vector();
+        Vector umail = new Vector();
+        Attributes tempAttr = null;
         try {
             while (enum.hasMore()) {
                 SearchResult sr = (SearchResult)enum.next();
+                tempAttr = sr.getAttributes();
+
+                if((tempAttr.get("cn")+"").startsWith("cn: ")){
+                  uname.add( (tempAttr.get("cn") + "").substring(4));
+                } else {
+                  uname.add( tempAttr.get("cn") + "");
+                }
+
+                if((tempAttr.get("mail")+"").startsWith("mail: ")){
+                  umail.add((tempAttr.get("mail") + "").substring(6));
+                } else {
+                  umail.add(tempAttr.get("mail") + "");
+                }
+
                 uvec.add(sr.getName()+","+ldapBase);
             }
         } catch (SizeLimitExceededException slee) {
@@ -452,9 +469,11 @@
         }
 
         // initialize users[]; fill users[]
-        users = new String[uvec.size()];
+        users = new String[uvec.size()][3];
         for (int i=0; i < uvec.size(); i++) {
-          users[i] = (String)uvec.elementAt(i); 
+          users[i][0] = (String)uvec.elementAt(i);
+          users[i][1] = (String)uname.elementAt(i);
+          users[i][2] = (String)umail.elementAt(i);
         }
 
         // Close the context when we're done
@@ -478,7 +497,7 @@
    * @param group the group whose user list should be returned
    * @returns string array of the user names belonging to the group
    */
-  public String[] getUsers(String user, String password, String group) 
+  public String[] getUsers(String user, String password, String group)
          throws ConnectException
   {
     String[] users = null;
@@ -485,7 +504,7 @@
 
     // Identify service provider to use
     Hashtable env = new Hashtable(11);
-    env.put(Context.INITIAL_CONTEXT_FACTORY, 
+    env.put(Context.INITIAL_CONTEXT_FACTORY,
             "com.sun.jndi.ldap.LdapCtxFactory");
     env.put(Context.REFERRAL, referral);
     env.put(Context.PROVIDER_URL, ldapUrl);
@@ -504,9 +523,9 @@
         try {
             for (NamingEnumeration ae = answer.getAll(); ae.hasMore();) {
                 Attribute attr = (Attribute)ae.next();
-                for (NamingEnumeration e = attr.getAll(); 
+                for (NamingEnumeration e = attr.getAll();
                      e.hasMore();
-                     uvec.add(e.next()) 
+                     uvec.add(e.next())
                     );
             }
         } catch (SizeLimitExceededException slee) {
@@ -517,7 +536,7 @@
         // initialize users[]; fill users[]
         users = new String[uvec.size()];
         for (int i=0; i < uvec.size(); i++) {
-          users[i] = (String)uvec.elementAt(i); 
+          users[i] = (String)uvec.elementAt(i);
         }
 
         // Close the context when we're done
@@ -540,7 +559,7 @@
    * @param password the password for authenticating against the service
    * @returns string array of the group names
    */
-  public String[] getGroups(String user, String password) 
+  public String[][] getGroups(String user, String password)
          throws ConnectException
   {
       return getGroups(user, password, null);
@@ -554,15 +573,18 @@
    * @param foruser the user whose group list should be returned
    * @returns string array of the group names
    */
-  public String[] getGroups(String user, String password, String foruser) 
+  public String[][] getGroups(String user, String password, String foruser)
          throws ConnectException
   {
     Vector uvec = new Vector();
+    Vector desc = new Vector();
+    Attributes tempAttr = null;
+
     //Pass the username and password to run() method
     userName=user;
     userPassword=password;
     // Identify service provider to use
-    env.put(Context.INITIAL_CONTEXT_FACTORY, 
+    env.put(Context.INITIAL_CONTEXT_FACTORY,
             "com.sun.jndi.ldap.LdapCtxFactory");
     env.put(Context.REFERRAL, "throw");
     env.put(Context.PROVIDER_URL, ldapUrl);
@@ -570,7 +592,7 @@
         // Create the initial directory context
         DirContext ctx = new InitialDirContext(env);
         // Specify the ids of the attributes to return
-        String[] attrIDs = {"cn"};
+        String[] attrIDs = {"cn", "description"};
         // Specify the attributes to match.
         // Groups are objects with attribute objectclass=groupofuniquenames.
         // and have attribute uniquemember: uid=foruser,ldapbase.
@@ -577,7 +599,7 @@
         SearchControls ctls = new SearchControls();
         ctls.setReturningAttributes(attrIDs);
         ctls.setSearchScope(SearchControls.SUBTREE_SCOPE);
-        
+
         String filter = null;
         String gfilter = "(objectClass=groupOfUniqueNames)";
         if (null == foruser) {
@@ -591,16 +613,24 @@
         // Print the groups
         MetaCatUtil.debugMessage("getting group results.", 50);
         while (enum.hasMore()) {
-          SearchResult sr = (SearchResult)enum.next();          
+          SearchResult sr = (SearchResult)enum.next();
+          tempAttr = sr.getAttributes();
+
+          if((tempAttr.get("description")+"").startsWith("description: ")){
+            desc.add( (tempAttr.get("description") + "").substring(13));
+          } else {
+            desc.add( tempAttr.get("description") + "");
+          }
+
           uvec.add(sr.getName()+","+ldapBase);
-          MetaCatUtil.debugMessage("group " + sr.getName() + 
+          MetaCatUtil.debugMessage("group " + sr.getName() +
                                   " added to Group vector", 35);
         }
         // Close the context when we're done
         ctx.close();
 
-    } 
-    catch (ReferralException re) 
+    }
+    catch (ReferralException re)
     {
       refExc = re;
       Thread t = new Thread(new GetGroup());
@@ -621,16 +651,17 @@
       if (referralContext == null)
       {
         util.debugMessage("thread timed out...returning groups: " + uvec.toString(), 35);
-        String groups[] = new String[uvec.size()];
+        String groups[][] = new String[uvec.size()][2];
         for(int i=0; i<uvec.size(); i++)
         {
-          groups[i] = (String)uvec.elementAt(i);
+          groups[i][0] = (String)uvec.elementAt(i);
+          groups[i][1] = (String)desc.elementAt(i);
         }
         t.interrupt();
         return groups;
       }
       DirContext dc = (DirContext)referralContext;
-      String[] attrIDs = {"cn"};
+      String[] attrIDs = {"cn", "description"};
       // Specify the attributes to match.
       // Groups are objects with attribute objectclass=groupofuniquenames.
       // and have attribute uniquemember: uid=foruser,ldapbase.
@@ -637,7 +668,7 @@
       SearchControls ctls = new SearchControls();
       ctls.setReturningAttributes(attrIDs);
       ctls.setSearchScope(SearchControls.SUBTREE_SCOPE);
-      
+
       String filter = null;
       String gfilter = "(objectClass=groupOfUniqueNames)";
       if (null == foruser) {
@@ -645,7 +676,7 @@
       } else {
           filter = "(& " + gfilter + "(uniqueMember=" + foruser + "))";
       }
-      
+
       try
       {
         NamingEnumeration enum = dc.search(ldapBase, filter, ctls);
@@ -652,34 +683,44 @@
         // Print the groups
         while (enum.hasMore()) {
           SearchResult sr = (SearchResult)enum.next();
+          tempAttr = sr.getAttributes();
+
+          if((tempAttr.get("description")+"").startsWith("description: ")){
+            desc.add( (tempAttr.get("description") + "").substring(13));
+          } else {
+            desc.add( tempAttr.get("description") + "");
+          }
+
           uvec.add(sr.getName()+","+ldapBase);
         }
-        
+
         referralContext.close();
         dc.close();
       }
       catch(NamingException ne)
       {
-        MetaCatUtil.debugMessage("Naming Exception in AuthLdap.getGroups", 30);
+        MetaCatUtil.debugMessage("Naming Exception in AuthLdap.getGroups" + ne.getExplanation() + ne.getMessage(), 30);
       }
     } catch (NamingException e) {
       e.printStackTrace(System.err);
-      String groups[] = new String[uvec.size()];
+      String groups[][] = new String[uvec.size()][2];
       for(int i=0; i<uvec.size(); i++)
       {
-        groups[i] = (String)uvec.elementAt(i);
+        groups[i][0] = (String)uvec.elementAt(i);
+        groups[i][1] = (String)desc.elementAt(i);
       }
       return groups;
        /*throw new ConnectException(
       "Problem getting groups for a user in AuthLdap.getGroups:" + e);*/
-    } 
-    
-    MetaCatUtil.debugMessage("The user is in the following groups: " + 
+    }
+
+    MetaCatUtil.debugMessage("The user is in the following groups: " +
                               uvec.toString(), 35);
-    String groups[] = new String[uvec.size()];
+    String groups[][] = new String[uvec.size()][2];
     for(int i=0; i<uvec.size(); i++)
     {
-      groups[i] = (String)uvec.elementAt(i);
+      groups[i][0] = (String)uvec.elementAt(i);
+      groups[i][1] = (String)desc.elementAt(i);
     }
     return groups;
   }
@@ -690,7 +731,7 @@
    * @param foruser the user for which the attribute list is requested
    * @returns HashMap a map of attribute name to a Vector of values
    */
-  public HashMap getAttributes(String foruser) 
+  public HashMap getAttributes(String foruser)
          throws ConnectException
   {
     return getAttributes(null, null, foruser);
@@ -704,7 +745,7 @@
    * @param foruser the user whose attributes should be returned
    * @returns HashMap a map of attribute name to a Vector of values
    */
-  public HashMap getAttributes(String user, String password, String foruser) 
+  public HashMap getAttributes(String user, String password, String foruser)
          throws ConnectException
   {
     HashMap attributes = new HashMap();
@@ -711,23 +752,23 @@
     String ldapUrl = this.ldapUrl;
     String ldapBase = this.ldapBase;
     String userident = foruser;
-   
+
     // Identify service provider to use
     Hashtable env = new Hashtable(11);
-    env.put(Context.INITIAL_CONTEXT_FACTORY, 
+    env.put(Context.INITIAL_CONTEXT_FACTORY,
         "com.sun.jndi.ldap.LdapCtxFactory");
     env.put(Context.REFERRAL, referral);
     env.put(Context.PROVIDER_URL, ldapUrl);
 
     try {
-      
+
       // Create the initial directory context
       DirContext ctx = new InitialDirContext(env);
-        
-      // Ask for all attributes of the user 
+
+      // Ask for all attributes of the user
       //Attributes attrs = ctx.getAttributes(userident);
       Attributes attrs = ctx.getAttributes(foruser);
- 
+
       // Print all of the attributes
       NamingEnumeration en = attrs.getAll();
       while (en.hasMore()) {
@@ -741,11 +782,11 @@
         }
         attributes.put(attName, values);
       }
-  
+
       // Close the context when we're done
       ctx.close();
     } catch (NamingException e) {
-      util.debugMessage("Problem getting attributes in " + 
+      util.debugMessage("Problem getting attributes in " +
               "AuthLdap.getAttributes:" + e, 35);
       throw new ConnectException(
       "Problem getting attributes in AuthLdap.getAttributes:" + e);
@@ -756,7 +797,7 @@
 
   /**
    * Get list of all subtrees holding Metacat's groups and users
-   * starting from the Metacat LDAP root, 
+   * starting from the Metacat LDAP root,
    * i.e. ldap://dev.nceas.ucsb.edu/dc=ecoinformatics,dc=org
    */
   private Hashtable getSubtrees(String user, String password,
@@ -767,7 +808,7 @@
 
     // Identify service provider to use
     Hashtable env = new Hashtable(11);
-    env.put(Context.INITIAL_CONTEXT_FACTORY, 
+    env.put(Context.INITIAL_CONTEXT_FACTORY,
             "com.sun.jndi.ldap.LdapCtxFactory");
     env.put(Context.REFERRAL, referral);
     env.put(Context.PROVIDER_URL, ldapUrl + ldapBase);
@@ -782,7 +823,7 @@
         SearchControls ctls = new SearchControls();
         ctls.setReturningAttributes(attrIDs);
         ctls.setSearchScope(SearchControls.SUBTREE_SCOPE);
-          
+
         // Specify the attributes to match.
         // Subtrees from the main server are found as objects with attribute
         // objectclass=organization or objectclass=referral to the subtree
@@ -801,7 +842,7 @@
             Attribute attr = (Attribute)enum1.next();
             String attrValue = (String)attr.get();
             String attrName = (String)attr.getID();
- 
+
             if ( enum1.hasMore() ) {
               attr = (Attribute)enum1.next();
               String refValue = (String)attr.get();
@@ -813,11 +854,11 @@
                 trees.put(refName + "=" + refValue + "," + ldapBase,
                          attrValue.substring(0,attrValue.lastIndexOf("/")+1) );
               }
- 
+
             } else if ( ldapBase.startsWith(attrName + "=" + attrValue) ) {
                 trees.put(ldapBase, ldapUrl);
-            } else {              
-                trees.put(attrName + "=" + attrValue + "," + ldapBase, ldapUrl);               
+            } else {
+                trees.put(attrName + "=" + attrValue + "," + ldapBase, ldapUrl);
             }
           }
         }
@@ -826,7 +867,7 @@
         ctx.close();
 
     } catch (NamingException e) {
-      util.debugMessage("Problem getting subtrees in AuthLdap.getSubtrees:" 
+      util.debugMessage("Problem getting subtrees in AuthLdap.getSubtrees:"
                         + e, 30);
       throw new ConnectException(
       "Problem getting subtrees in AuthLdap.getSubtrees:" + e);
@@ -846,65 +887,93 @@
   {
     StringBuffer out = new StringBuffer();
     Vector usersIn = new Vector();
-    
-    out.append("<?xml version=\"1.0\"?>\n");
+
+    out.append("<?xml version=\"1.0\" encoding=\"US-ASCII\"?>\n");
     out.append("<principals>\n");
-    
+
     /*
-     * get all subtrees first in the current dir context 
+     * get all subtrees first in the current dir context
      * and then the Metacat users under them
      */
     Hashtable subtrees = getSubtrees(user,password,this.ldapUrl,this.ldapBase);
-    
+
     Enumeration enum = subtrees.keys();
     while ( enum.hasMoreElements() ) {
       this.ldapBase = (String)enum.nextElement();
       this.ldapUrl = (String)subtrees.get(ldapBase);
-      
-      out.append("  <authSystem URI=\"" + 
+
+      out.append("  <authSystem URI=\"" +
                  this.ldapUrl + this.ldapBase + "\">\n");
 
       // get all groups for directory context
-      String[] groups = getGroups(user, password);
+      String[][] groups = getGroups(user, password);
+      String[][] users = getUsers(user, password);
+      int userIndex = 0;
 
       // for the groups and users that belong to them
       if ( groups!=null && groups.length > 0 ) {
         for (int i=0; i < groups.length; i++ ) {
           out.append("    <group>\n");
-          out.append("      <groupname>" + groups[i] + "</groupname>\n");
-          String[] usersForGroup = getUsers(user,password,groups[i]);
+          out.append("      <groupname>" + groups[i][0] + "</groupname>\n");
+          out.append("      <description>" + groups[i][1] + "</description>\n");
+          String[] usersForGroup = getUsers(user,password,groups[i][0]);
           for (int j=0; j < usersForGroup.length; j++ ) {
             usersIn.addElement(usersForGroup[j]);
+
+            userIndex = searchUser(usersForGroup[j], users);
             out.append("      <user>\n");
-            out.append("        <username>" + usersForGroup[j] + 
-                        "</username>\n");
+
+            if(userIndex < 0){
+              out.append("        <userdn>" + usersForGroup[j] +
+                         "</userdn>\n");
+            } else {
+              out.append("      <username>" + users[userIndex][0] + "</username>\n");
+              out.append("      <name>" + users[userIndex][1] + "</name>\n");
+              out.append("      <email>" + users[userIndex][2] + "</email>\n");
+            }
+
             out.append("      </user>\n");
           }
           out.append("    </group>\n");
         }
       }
+
       // 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]) ) {
+        if ( !usersIn.contains(users[j][0]) ) {
           out.append("    <user>\n");
-          out.append("      <username>" + users[j] + "</username>\n");
+          out.append("      <username>" + users[j][0] + "</username>\n");
+          out.append("      <name>" + users[j][1] + "</name>\n");
+          out.append("      <email>" + users[j][2] + "</email>\n");
           out.append("    </user>\n");
         }
       }
-    
+
       out.append("  </authSystem>\n");
       if ( !usersIn.isEmpty() ) {
         usersIn.removeAllElements();
         usersIn.trimToSize();
       }
-    
+
     }
     out.append("</principals>");
     return out.toString();
   }
 
+
   /**
+   * Method for getting index of user DN in User info array
+   */
+  int searchUser(String user, String userGroup[][]){
+    for (int j=0; j < userGroup.length; j++ ) {
+      if (user.compareTo(userGroup[j][0]) == 0){
+        return j;
+      }
+    }
+    return -1;
+  }
+
+  /**
    * Test method for the class
    */
   public static void main(String[] args) {
@@ -916,7 +985,7 @@
     MetaCatUtil.debugMessage("Creating session...", 20);
     AuthLdap authservice = new AuthLdap();
     MetaCatUtil.debugMessage("Session exists...", 20);
-                
+
     boolean isValid = false;
     try {
       MetaCatUtil.debugMessage("Authenticating...", 20);
@@ -947,10 +1016,10 @@
       // get the groups
       if (isValid) {
         MetaCatUtil.debugMessage("\nGetting all groups....", 20);
-        String[] groups = authservice.getGroups(user, password);
+        String[][] groups = authservice.getGroups(user, password);
         MetaCatUtil.debugMessage("Groups found: " + groups.length, 20);
         for (int i=0; i < groups.length; i++) {
-            MetaCatUtil.debugMessage("Group " + i + ": " + groups[i], 20);
+            MetaCatUtil.debugMessage("Group " + i + ": " + groups[i][0], 20);
         }
       }
 
@@ -958,11 +1027,11 @@
       String savedGroup = null;
       if (isValid) {
         MetaCatUtil.debugMessage("\nGetting groups for user....", 20);
-        String[] groups = authservice.getGroups(user, password, user);
+        String[][] groups = authservice.getGroups(user, password, user);
         MetaCatUtil.debugMessage("Groups found: " + groups.length, 20);
         for (int i=0; i < groups.length; i++) {
-            MetaCatUtil.debugMessage("Group " + i + ": " + groups[i], 20);
-            savedGroup = groups[i];
+            MetaCatUtil.debugMessage("Group " + i + ": " + groups[i][0], 20);
+            savedGroup = groups[i][0];
         }
       }
 
@@ -980,9 +1049,9 @@
       // get all users
       if (isValid) {
         MetaCatUtil.debugMessage("\nGetting all users ....", 20);
-        String[] users = authservice.getUsers(user, password);
+        String[][] users = authservice.getUsers(user, password);
         MetaCatUtil.debugMessage("Users found: " + users.length, 20);
-        
+
       }
 
       // get the whole list groups and users in XML format
@@ -1006,11 +1075,11 @@
       MetaCatUtil.debugMessage("I/O Error writing to file principals.txt", 20);
     }
   }
-  
+
   /**
    * This method will be called by start a thread.
    * It can handle if a referral exception happend.
-   */ 
+   */
   public void run()
   {
     referralContext = null;
@@ -1022,7 +1091,7 @@
     while (moreReferrals)
     {
       try
-      {  
+      {
         //revise environment variable
         referralInfo=(String)refExc.getReferralInfo();
         util.debugMessage("Processing referral (pr0): ", 35);
@@ -1059,7 +1128,7 @@
       //catch a authentication exception
       catch (AuthenticationException ae)
       {
-        util.debugMessage("Error running referral handler thread (ae1): " + 
+        util.debugMessage("Error running referral handler thread (ae1): " +
                           ae.getMessage(), 20);
         //check if has another referral
         moreReferrals=refExc.skipReferral();
@@ -1069,16 +1138,16 @@
       //catch a naming exception
       catch (NamingException ne)
       {
-        util.debugMessage("Error running referral handler thread (ne1): " + 
+        util.debugMessage("Error running referral handler thread (ne1): " +
                           ne.getMessage(), 20);
         //check if has another referral
         moreReferrals=refExc.skipReferral();
         //don't get context
-        referralContext = null;		
+        referralContext = null;
       }
     }//while
   }//run()
-  
+
   private class GetGroup implements Runnable
   {
     public void run()
@@ -1087,7 +1156,7 @@
       MetaCatUtil.debugMessage("getting groups context", 50);
       DirContext refDirContext=null;
       boolean moreReferrals=true;
-      //set a while loop is because we don't know if a referral excption 
+      //set a while loop is because we don't know if a referral excption
       //contains another referral exception
       while (moreReferrals)
       {
@@ -1098,7 +1167,7 @@
           refInfo = (String)refExc.getReferralInfo();
           if(refInfo != null)
           {
-            MetaCatUtil.debugMessage("Referral in thread to: " + 
+            MetaCatUtil.debugMessage("Referral in thread to: " +
                               refInfo.toString(), 40);
           }
           else
@@ -1108,12 +1177,12 @@
                                                   get(Context.PROVIDER_URL);
           }
           MetaCatUtil.debugMessage("refInfo: " + refInfo, 40);
-        
-          env.put(Context.INITIAL_CONTEXT_FACTORY, 
+
+          env.put(Context.INITIAL_CONTEXT_FACTORY,
               "com.sun.jndi.ldap.LdapCtxFactory");
           env.put(Context.REFERRAL, "throw");
           env.put(Context.PROVIDER_URL, refInfo);
-        
+
           MetaCatUtil.debugMessage("creating referralContext", 40);
           referralContext = new InitialDirContext(env);
           MetaCatUtil.debugMessage("referralContext created", 40);
@@ -1129,7 +1198,7 @@
         }
         catch (AuthenticationException ae)
         {
-          util.debugMessage("Error running referral handler thread (ae2): " + 
+          util.debugMessage("Error running referral handler thread (ae2): " +
                           ae.getMessage(), 50);
           //check if has another referral
           moreReferrals=refExc.skipReferral();
@@ -1138,12 +1207,12 @@
         }
         catch (NamingException ne)
         {
-          util.debugMessage("Error running referral handler thread (ne2): " + 
+          util.debugMessage("Error running referral handler thread (ne2): " +
                           ne.getMessage(), 50);
           //check if has another referral
           moreReferrals=refExc.skipReferral();
           //don't get context
-          referralContext = null;		
+          referralContext = null;
         }
       }//while
     }//run()
Index: src/edu/ucsb/nceas/metacat/AuthSession.java
===================================================================
--- src/edu/ucsb/nceas/metacat/AuthSession.java	(revision 2057)
+++ src/edu/ucsb/nceas/metacat/AuthSession.java	(revision 2058)
@@ -42,8 +42,8 @@
   private HttpSession session = null;
   private AuthInterface authService = null;
   private String statusMessage = null;
- 
-  /** 
+
+  /**
    * Construct an AuthSession
    */
   public AuthSession() throws Exception {
@@ -53,7 +53,7 @@
     this.authClass = util.getOption("authclass");
     this.authService = (AuthInterface)createObject(authClass);
   }
-  
+
   /**
    * Get the new session
    */
@@ -62,8 +62,8 @@
     return this.session;
   }
 
-  /** 
-   * determine if the credentials for this session are valid by 
+  /**
+   * determine if the credentials for this session are valid by
    * authenticating them using the authService configured for this session.
    *
    * @param request the request made from the client
@@ -70,12 +70,22 @@
    * @param username the username entered when login
    * @param password the password entered when login
    */
-  public boolean authenticate(HttpServletRequest request, 
-                              String username, String password)  { 
+  public boolean authenticate(HttpServletRequest request,
+                              String username, String password)  {
     String message = null;
-    try { 
+    try {
       if ( authService.authenticate(username, password) ) {
-        String[] groups = authService.getGroups(username,password,username);
+
+        // getGroups returns groupname along with their description.
+        // hence groups[] is generated from groupsWithDescription[][]
+        String[][] groupsWithDescription =
+            authService.getGroups(username,password,username);
+        String groups[] = new String[groupsWithDescription.length];
+
+        for(int i=0; i<groupsWithDescription.length; i++){
+          groups[i] = groupsWithDescription[i][0];
+        }
+
         if(groups == null)
         {
           groups = new String[0];
@@ -85,11 +95,11 @@
         message = "Authentication successful for user: " + username;
         this.statusMessage = formatOutput("login", message, sessionId);
         return true;
-      } else {  
+      } else {
         message = "Authentication failed for user: " + username;
         this.statusMessage = formatOutput("unauth_login", message);
         return false;
-      }    
+      }
     } catch ( ConnectException ce ) {
       message = "Connection to the authentication service failed in " +
                 "AuthSession.authenticate: " + ce.getMessage();
@@ -96,15 +106,15 @@
     } catch ( IllegalStateException ise ) {
       message = ise.getMessage();
     }
- 
+
     this.statusMessage = formatOutput("error_login", message);
     return false;
   }
 
   /** Get new HttpSession and store username & password in it */
-  private HttpSession createSession(HttpServletRequest request, 
+  private HttpSession createSession(HttpServletRequest request,
                                  String username, String password,
-                                 String[] groups)  
+                                 String[] groups)
                       throws IllegalStateException {
 
     // get the current session object, create one if necessary
@@ -140,7 +150,7 @@
    * Get the message associated with authenticating this session. The
    * message is formatted in XML.
    */
-  public String getMessage() 
+  public String getMessage()
   {
     return this.statusMessage;
   }
@@ -157,18 +167,18 @@
     return authService.getPrincipals(user, password);
   }
 
-  /* 
+  /*
    * format the output in xml for processing from client applications
    *
    * @param tag the root element tag for the message (error or success)
    * @param message the message content of the root element
    */
-  private String formatOutput(String tag, String message) 
+  private String formatOutput(String tag, String message)
   {
       return formatOutput(tag, message, null);
   }
 
-  /* 
+  /*
    * format the output in xml for processing from client applications
    *
    * @param tag the root element tag for the message (error or success)
@@ -175,10 +185,10 @@
    * @param message the message content of the root element
    * @param sessionId the session identifier for a successful login
    */
-  private String formatOutput(String tag, String message, String sessionId) 
+  private String formatOutput(String tag, String message, String sessionId)
   {
     StringBuffer out = new StringBuffer();
-      
+
     out.append("<?xml version=\"1.0\"?>\n");
     out.append("<" + tag + ">");
     out.append("\n  <message>" + message + "</message>\n");
@@ -186,7 +196,7 @@
         out.append("\n  <sessionId>" + sessionId + "</sessionId>\n");
     }
     out.append("</" + tag + ">");
-    
+
     return out.toString();
   }
 
@@ -196,7 +206,7 @@
    * @param className the fully qualified name of the class to instantiate
    */
   private static Object createObject(String className) throws Exception {
- 
+
     Object object = null;
     try {
       Class classDefinition = Class.forName(className);
Index: src/edu/ucsb/nceas/metacat/AuthInterface.java
===================================================================
--- src/edu/ucsb/nceas/metacat/AuthInterface.java	(revision 2057)
+++ src/edu/ucsb/nceas/metacat/AuthInterface.java	(revision 2058)
@@ -1,6 +1,6 @@
 /**
  *  '$RCSfile$'
- *    Purpose: An interface representing the methods that should be 
+ *    Purpose: An interface representing the methods that should be
  *             implemented by an authentication service
  *  Copyright: 2000 Regents of the University of California and the
  *             National Center for Ecological Analysis and Synthesis
@@ -32,9 +32,9 @@
 import java.util.HashMap;
 
 /**
- * An interface representing the methods that should be 
+ * An interface representing the methods that should be
  * implemented by an authentication service.  The authentication service is
- * used to determine if a user is authenticated, and whether they are a member 
+ * used to determine if a user is authenticated, and whether they are a member
  * of a particular group.
  */
 public interface AuthInterface {
@@ -53,7 +53,7 @@
   /**
    * Get all users from the authentication service
    */
-  public String[] getUsers(String user, String password) 
+  public String[][] getUsers(String user, String password)
          throws ConnectException;
 
   /**
@@ -65,13 +65,13 @@
   /**
    * Get all groups from the authentication service
    */
-  public String[] getGroups(String user, String password)
+  public String[][] getGroups(String user, String password)
          throws ConnectException;
 
   /**
    * Get the groups for a particular user from the authentication service
    */
-  public String[] getGroups(String user, String password, String foruser)
+  public String[][] getGroups(String user, String password, String foruser)
          throws ConnectException;
 
   /**
@@ -80,7 +80,7 @@
    * @param user the user for which the attribute list is requested
    * @returns HashMap a map of attribute name to a Vector of values
    */
-  public HashMap getAttributes(String foruser) 
+  public HashMap getAttributes(String foruser)
          throws ConnectException;
 
   /**
@@ -91,7 +91,7 @@
    * @param password the password for authenticating against the service
    * @returns HashMap a map of attribute name to a Vector of values
    */
-  public HashMap getAttributes(String user, String password, String foruser) 
+  public HashMap getAttributes(String user, String password, String foruser)
          throws ConnectException;
 
   /**
