Project

General

Profile

« Previous | Next » 

Revision 4159

Added by daigle over 15 years ago

Add support for separate LDAP and organization level configurations

View differences:

PropertyService.java
38 38

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

  
41
import edu.ucsb.nceas.metacat.util.LDAPUtil;
41
import edu.ucsb.nceas.metacat.util.OrganizationUtil;
42 42
import edu.ucsb.nceas.metacat.util.UtilException;
43 43
import edu.ucsb.nceas.utilities.FileUtil;
44 44
import edu.ucsb.nceas.utilities.GeneralPropertyException;
......
62 62
	
63 63
	private static final String MAIN_CONFIG_NAME = "metacat.properties";
64 64
	private static final String ORG_CONFIG_NAME = "org.properties";
65
	private static final String LDAP_CONFIG_NAME = "ldap.properties";
65 66
	
66 67
	private static boolean bypassAlreadyChecked = false;
67 68
	
......
80 81
	private static String orgMetaDataFilePath = null;
81 82
	private static PropertiesMetaData orgMetaData = null;
82 83
	
84
	private static String ldapBackupPropertiesFilePath = null;
85
	private static SortedProperties ldapBackupProperties = null;
86
	
87
	private static String ldapMetaDataFilePath = null;
88
	private static PropertiesMetaData ldapMetaData = null;
89
	
90
	
83 91
	private static Logger logMetacat = Logger.getLogger(PropertyService.class);
84 92

  
85 93
	/**
......
139 147
			}
140 148

  
141 149
			// orgMetaData holds configuration information about organization level 
142
			// properties.  these are mostly ldap information relative to an 
143
			// organization. This is primarily used to display input fields on 
150
			// properties.  This is primarily used to display input fields on 
144 151
			// the organization configuration page. The information is retrieved 
145
			// from an xml metadata file dedication just to organization properties.
152
			// from an xml metadata file dedicated just to organization properties.
146 153
			orgMetaDataFilePath = configDir + FileUtil.getFS() + ORG_CONFIG_NAME + ".metadata.xml";
147 154
			if (orgMetaData == null) {
148 155
				orgMetaData = new PropertiesMetaData(orgMetaDataFilePath);
149 156
			}
157
			
158

  
159
			// ldapMetaData holds configuration information about organization level 
160
			// properties.  This is primarily used to display input fields on 
161
			// the ldap configuration page. The information is retrieved 
162
			// from an xml metadata file dedicated just to ldap properties.
163
			ldapMetaDataFilePath = configDir + FileUtil.getFS() + LDAP_CONFIG_NAME + ".metadata.xml";
164
			if (ldapMetaData == null) {
165
				ldapMetaData = new PropertiesMetaData(ldapMetaDataFilePath);
166
			}
150 167
		} catch (TransformerException te) {
151 168
			throw new GeneralPropertyException(te.getMessage());
152 169
		}
......
174 191
				new SortedProperties(orgBackupPropertiesFilePath);
175 192
			orgBackupProperties.load();
176 193
		}
194
		
195
		// The ldapBackupProperties hold properties that were backed up the 
196
		// last time the LDAP was configured.  On disk, the file will
197
		// look like a smaller version of metacat.properties.  It is stored 
198
		// in the data storage directory outside the application directories.
199
		ldapBackupPropertiesFilePath = backupDirPath + FileUtil.getFS() +  LDAP_CONFIG_NAME + ".backup";
200
		if (ldapBackupProperties == null) {
201
			ldapBackupProperties = 
202
				new SortedProperties(ldapBackupPropertiesFilePath);
203
			ldapBackupProperties.load();
204
		}
177 205
	
178 206
	}
179 207

  
......
284 312
	}
285 313
	
286 314
	/**
315
	 * Get the LDAP backup properties file. These are configurable 
316
	 * properties that are stored outside the metacat install directories so 
317
	 * the user does not need to re-enter all the configuration information 
318
	 * every time they do an upgrade.
319
	 * 
320
	 * @return a SortedProperties object with the backup properties
321
	 */
322
	public static SortedProperties getLDAPBackupProperties() {
323
		return ldapBackupProperties;
324
	}
325
	
326
	/**
287 327
	 * Get the main properties metadata. This is retrieved from an xml file that
288 328
	 * describes the attributes of configurable properties.
289 329
	 * 
......
305 345
	}
306 346
	
307 347
	/**
348
	 * Get the LDAP properties metadata. This is retrieved from an xml
349
	 * file that describes the attributes of configurable properties.
350
	 * 
351
	 * @return a PropertiesMetaData object with the organization properties
352
	 *         metadata
353
	 */
354
	public static PropertiesMetaData getLDAPMetaData() {
355
		return ldapMetaData;
356
	}
357
	
358
	/**
308 359
	 * Writes out backup configurable properties to a file.
309 360
	 */
310 361
	public static void persistMainBackupProperties(ServletContext servletContext)
......
351 402
			// the associated metadata file
352 403
			PropertiesMetaData orgMetadata = new PropertiesMetaData(orgMetaDataFilePath);
353 404
			
354
			// Here we get the group definition for group 1 from the org
355
			// metadata.  Group 1 should be global values across all 
356
			// organizations.  We then get all properties metadata associated 
357
			// with group 1, iterate through it and set it in the backup
358
			// properties.
359
			MetaDataGroup globalGroup = orgMetadata.getGroup(1);
360
			SortedMap<Integer, MetaDataProperty> globalPropertyMap = 
361
				orgMetadata.getPropertiesInGroup(globalGroup.getIndex());
362
			for (MetaDataProperty property : globalPropertyMap.values()) {
363
				String orgPropertyName = property.getKey();
364
				backupProperties.addProperty(orgPropertyName, getProperty(orgPropertyName));
365
			}
366
			
367 405
			// We do the same thing here for organization specific properies
368 406
			// with the addition that we need to iterate through all available 
369 407
			// organizations.  For instance, a metadata section that defines a 
370
			// property as "ldap.base" will be entered into the metacat.properties
371
			// file with a key of "ldap.base.NCEAS" for the NCEAS organization. 
408
			// property as "organization.base" will be entered into the metacat.properties
409
			// file with a key of "organization.base.NCEAS" for the NCEAS organization. 
372 410
			// This will be repeated for all available organizations.
373
			MetaDataGroup orgGroup = orgMetadata.getGroup(2);
374
			SortedMap<Integer, MetaDataProperty> orgPropertyMap = orgMetadata
375
					.getPropertiesInGroup(orgGroup.getIndex());
376
			for (String orgName : LDAPUtil.getOrganizations()) {
377
				for (MetaDataProperty property : orgPropertyMap.values()) {
378
					String orgPropertyName = property.getKey() + "." + orgName;
379
					backupProperties.addProperty(orgPropertyName, getProperty(orgPropertyName));
411
			Set<String> orgKeySet = orgMetadata.getKeys();
412
			for (String orgName : OrganizationUtil.getOrganizations()) {
413
				for (String propertyKey : orgKeySet) {
414
					String orgPropertyKey = propertyKey + "." + orgName;
415
					backupProperties.addProperty(orgPropertyKey, getProperty(orgPropertyKey));
380 416
				}
381 417
			}
382 418
			
......
393 429
			throw new GeneralPropertyException("Could not get organizations: " + ue.getMessage());
394 430
		}
395 431
	}
432
	
433
	/**
434
	 * Writes out backup configurable properties to a file.
435
	 */
436
	public static void persistLDAPBackupProperties(ServletContext servletContext)
437
			throws GeneralPropertyException {
396 438

  
439
		// Use the metadata to extract configurable properties from the 
440
		// overall properties list, and store those properties.
441
		try {
442
			SortedProperties backupProperties = 
443
				new SortedProperties(ldapBackupPropertiesFilePath);
444
			
445
			// Populate the backup properties for ldap properties using
446
			// the associated metadata file
447
			PropertiesMetaData ldapMetadata = new PropertiesMetaData(ldapMetaDataFilePath);
448

  
449
			Set<String> ldapKeySet = ldapMetadata.getKeys();
450
			for (String propertyKey : ldapKeySet) {
451
				backupProperties.addProperty(propertyKey, getProperty(propertyKey));
452
			}
453
			
454
			// store the properties to file
455
			backupProperties.store();
456

  
457
		} catch (TransformerException te) {
458
			throw new GeneralPropertyException("Could not transform backup properties xml: "
459
					+ te.getMessage());
460
		} catch (IOException ioe) {
461
			throw new GeneralPropertyException("Could not backup configurable properties: "
462
					+ ioe.getMessage());
463
		} 
464
	}
465

  
397 466
	/**
398 467
	 * Gets the backup properties directory
399 468
	 * 
......
473 542
				setPropertyNoPersist(orgBackupPropertyName, value);
474 543
			}
475 544
			
545
			SortedProperties ldapBackupProperties = getLDAPBackupProperties();
546
			Vector<String> ldapBackupPropertyNames = 
547
				ldapBackupProperties.getPropertyNames();
548
			for (String ldapBackupPropertyName : ldapBackupPropertyNames) {
549
				String value = ldapBackupProperties.getProperty(ldapBackupPropertyName);
550
				setPropertyNoPersist(ldapBackupPropertyName, value);
551
			}
552
			
476 553
			setPropertyNoPersist("configutil.propertiesConfigured", "true");
477 554
			setPropertyNoPersist("configutil.ldapConfigured", "true");
555
			setPropertyNoPersist("configutil.organizationsConfigured", "true");
478 556
			setPropertyNoPersist("configutil.skinsConfigured", "true");
479 557
			setPropertyNoPersist("configutil.databaseConfigured", "true");
480 558
				

Also available in: Unified diff