Project

General

Profile

« Previous | Next » 

Revision 4547

Added by daigle about 16 years ago

Added validation that configured ldap admins actually exist in ldap

View differences:

src/edu/ucsb/nceas/metacat/AuthLdap.java
901 901
   * @param foruser the user for which the attribute list is requested
902 902
   * @returns HashMap a map of attribute name to a Vector of values
903 903
   */
904
  public HashMap getAttributes(String foruser) throws ConnectException {
904
  public HashMap<String,Vector<String>> getAttributes(String foruser) throws ConnectException {
905 905
    return getAttributes(null, null, foruser);
906 906
  }
907 907

  
......
913 913
   * @param foruser the user whose attributes should be returned
914 914
   * @returns HashMap a map of attribute name to a Vector of values
915 915
   */
916
  public HashMap getAttributes(String user, String password, 
916
  public HashMap<String,Vector<String>> getAttributes(String user, String password, 
917 917
    String foruser) throws ConnectException {
918
    HashMap attributes = new HashMap();
918
    HashMap<String,Vector<String>> attributes = new HashMap<String,Vector<String>>();
919 919
    String ldapUrl = this.ldapUrl;
920 920
    String ldapBase = this.ldapBase;
921 921
    String userident = foruser;
......
940 940
      NamingEnumeration en = attrs.getAll();
941 941
      while (en.hasMore()) {
942 942
        Attribute att = (Attribute) en.next();
943
        Vector values = new Vector();
943
        Vector<String> values = new Vector();
944 944
        String attName = att.getID();
945 945
        NamingEnumeration attvalues = att.getAll();
946 946
        while (attvalues.hasMore()) {
src/edu/ucsb/nceas/metacat/admin/LDAPAdmin.java
27 27
package edu.ucsb.nceas.metacat.admin;
28 28

  
29 29
import java.io.IOException;
30
import java.net.ConnectException;
31
import java.util.HashMap;
30 32
import java.util.Set;
31 33
import java.util.SortedMap;
32 34
import java.util.Vector;
......
37 39

  
38 40
import org.apache.log4j.Logger;
39 41

  
42
import edu.ucsb.nceas.metacat.AuthLdap;
40 43
import edu.ucsb.nceas.metacat.service.PropertyService;
41 44
import edu.ucsb.nceas.metacat.util.RequestUtil;
42 45
import edu.ucsb.nceas.utilities.FileUtil;
......
45 48
import edu.ucsb.nceas.utilities.PropertiesMetaData;
46 49
import edu.ucsb.nceas.utilities.PropertyNotFoundException;
47 50
import edu.ucsb.nceas.utilities.SortedProperties;
51
import edu.ucsb.nceas.utilities.StringUtil;
48 52

  
49 53
/**
50 54
 * Control the display of the LDAP configuration page and the processing
......
234 238
	protected Vector<String> validateOptions(HttpServletRequest request) {
235 239
		Vector<String> errorVector = new Vector<String>();
236 240

  
237
		//TODO MCD validate options.
241
		String adminUsers = request.getParameter("ldap.administrators");
242
		Vector<String> adminUserList = StringUtil.toVector(adminUsers, ':');
238 243

  
244
		try {
245
			AuthLdap authLdap = new AuthLdap();
246
			for (String adminUser : adminUserList) {
247
				try {
248
					authLdap.getAttributes(adminUser);
249
				} catch (ConnectException ce) {
250
					if (ce.getMessage() != null
251
							&& ce.getMessage().contains("NameNotFoundException")) {
252
						errorVector.add("User : " + adminUser + " is not in LDAP.");
253
					} else {
254
						errorVector.add("Connection error while verifying Metacat " + 
255
								"Administrators : " + ce.getMessage());
256
					}
257
				}
258
			}
259
		} catch (InstantiationException ie) {
260
			errorVector
261
					.add("Instantiation error while verifying Metacat Administrators : "
262
							+ ie.getMessage());
263
		}
264

  
239 265
		return errorVector;
240 266
	}
241 267
}

Also available in: Unified diff