r4627 - in trunk/src/edu/ucsb/nceas/metacat: . util

daigle at ecoinformatics.org daigle at ecoinformatics.org
Mon Nov 24 15:42:55 PST 2008


Author: daigle
Date: 2008-11-24 15:42:55 -0800 (Mon, 24 Nov 2008)
New Revision: 4627

Modified:
   trunk/src/edu/ucsb/nceas/metacat/AuthSession.java
   trunk/src/edu/ucsb/nceas/metacat/util/AuthUtil.java
Log:
Added code to populate moderators from metacat.properties

Modified: trunk/src/edu/ucsb/nceas/metacat/AuthSession.java
===================================================================
--- trunk/src/edu/ucsb/nceas/metacat/AuthSession.java	2008-11-24 23:42:04 UTC (rev 4626)
+++ trunk/src/edu/ucsb/nceas/metacat/AuthSession.java	2008-11-24 23:42:55 UTC (rev 4627)
@@ -232,10 +232,15 @@
 				logMetacat.error("Could not determine if user is administrator. "
 						+ "Omitting from xml output: " + ue.getMessage());
 			}
-
-			// insert <isModerator> tag if the user is a Moderator
-			if (AuthUtil.isModerator(username, groups)) {
-				out.append("\n  <isModerator></isModerator>\n");
+			
+			try {
+				// insert <isModerator> tag if the user is a Moderator
+				if (AuthUtil.isModerator(username, groups)) {
+					out.append("\n  <isModerator></isModerator>\n");
+				}
+			} catch (UtilException ue) {
+				logMetacat.error("Could not determine if user is moderator. "
+						+ "Omitting from xml output: " + ue.getMessage());
 			}
 		}
 		out.append("</" + tag + ">");

Modified: trunk/src/edu/ucsb/nceas/metacat/util/AuthUtil.java
===================================================================
--- trunk/src/edu/ucsb/nceas/metacat/util/AuthUtil.java	2008-11-24 23:42:04 UTC (rev 4626)
+++ trunk/src/edu/ucsb/nceas/metacat/util/AuthUtil.java	2008-11-24 23:42:55 UTC (rev 4627)
@@ -91,6 +91,18 @@
 	}
 	
 	/**
+	 * Get the moderators from metacat.properties
+	 * 
+	 * @return a Vector of Strings holding the moderators
+	 */
+	public static Vector<String> getModerators() throws UtilException {
+		if (moderators == null) {
+			populateModerators();
+		}
+		return moderators;
+	}
+	
+	/**
 	 * Get the vector of administrator credentials from metacat.properties
 	 * and put into global administrators list
 	 */
@@ -137,6 +149,23 @@
 		}		
 		deniedSubmitters = StringUtil.toVector(deniedSubmitterString, ':');		
 	}
+	
+	/**
+	 * Get the vector of moderator credentials from metacat.properties
+	 * and put into global administrators list
+	 */
+	private static void populateModerators() throws UtilException {
+		String moderatorString = null;
+		try {
+			moderatorString = 
+				PropertyService.getProperty("auth.moderators");
+		} catch (PropertyNotFoundException pnfe) {
+			throw new UtilException("Could not get metacat property: auth.moderators. "
+							+ "There will be no registered metacat moderators: "
+							+ pnfe.getMessage());
+		}
+		moderators = StringUtil.toVector(moderatorString, ':');
+	}
 
 //	/**
 //	 * Validate connectivity to the ldap server. This does not test user
@@ -378,8 +407,8 @@
 	 * @param groups
 	 *            a list of the user's groups
 	 */
-	public static boolean isModerator(String username, String[] groups) {
-		return onAccessList(moderators, username, groups);
+	public static boolean isModerator(String username, String[] groups) throws UtilException{
+		return onAccessList(getModerators(), username, groups);
 	}
 
 	/**



More information about the Metacat-cvs mailing list