Project

General

Profile

Revision 4627

Added by daigle about 12 years ago

Added code to populate moderators from metacat.properties

View differences:

src/edu/ucsb/nceas/metacat/util/AuthUtil.java
91 91
	}
92 92
	
93 93
	/**
94
	 * Get the moderators from metacat.properties
95
	 * 
96
	 * @return a Vector of Strings holding the moderators
97
	 */
98
	public static Vector<String> getModerators() throws UtilException {
99
		if (moderators == null) {
100
			populateModerators();
101
		}
102
		return moderators;
103
	}
104
	
105
	/**
94 106
	 * Get the vector of administrator credentials from metacat.properties
95 107
	 * and put into global administrators list
96 108
	 */
......
137 149
		}		
138 150
		deniedSubmitters = StringUtil.toVector(deniedSubmitterString, ':');		
139 151
	}
152
	
153
	/**
154
	 * Get the vector of moderator credentials from metacat.properties
155
	 * and put into global administrators list
156
	 */
157
	private static void populateModerators() throws UtilException {
158
		String moderatorString = null;
159
		try {
160
			moderatorString = 
161
				PropertyService.getProperty("auth.moderators");
162
		} catch (PropertyNotFoundException pnfe) {
163
			throw new UtilException("Could not get metacat property: auth.moderators. "
164
							+ "There will be no registered metacat moderators: "
165
							+ pnfe.getMessage());
166
		}
167
		moderators = StringUtil.toVector(moderatorString, ':');
168
	}
140 169

  
141 170
//	/**
142 171
//	 * Validate connectivity to the ldap server. This does not test user
......
378 407
	 * @param groups
379 408
	 *            a list of the user's groups
380 409
	 */
381
	public static boolean isModerator(String username, String[] groups) {
382
		return onAccessList(moderators, username, groups);
410
	public static boolean isModerator(String username, String[] groups) throws UtilException{
411
		return onAccessList(getModerators(), username, groups);
383 412
	}
384 413

  
385 414
	/**
src/edu/ucsb/nceas/metacat/AuthSession.java
232 232
				logMetacat.error("Could not determine if user is administrator. "
233 233
						+ "Omitting from xml output: " + ue.getMessage());
234 234
			}
235

  
236
			// insert <isModerator> tag if the user is a Moderator
237
			if (AuthUtil.isModerator(username, groups)) {
238
				out.append("\n  <isModerator></isModerator>\n");
235
			
236
			try {
237
				// insert <isModerator> tag if the user is a Moderator
238
				if (AuthUtil.isModerator(username, groups)) {
239
					out.append("\n  <isModerator></isModerator>\n");
240
				}
241
			} catch (UtilException ue) {
242
				logMetacat.error("Could not determine if user is moderator. "
243
						+ "Omitting from xml output: " + ue.getMessage());
239 244
			}
240 245
		}
241 246
		out.append("</" + tag + ">");

Also available in: Unified diff