1 |
|
//---PACKAGE DECLARATION--- |
2 |
< |
package uk.ac.ukc.iscream.core; |
2 |
> |
package uk.org.iscream.cms.server.core; |
3 |
|
|
4 |
|
//---IMPORTS--- |
5 |
< |
import uk.ac.ukc.iscream.util.*; |
6 |
< |
import uk.ac.ukc.iscream.componentmanager.*; |
5 |
> |
import uk.org.iscream.cms.server.util.*; |
6 |
> |
import uk.org.iscream.cms.server.componentmanager.*; |
7 |
|
import java.net.InetAddress; |
8 |
|
import java.net.UnknownHostException; |
9 |
|
import java.util.*; |
20 |
|
* |
21 |
|
* It also relies on the System.properties to set internal values. |
22 |
|
* |
23 |
– |
* ### |
24 |
– |
* A point to note is that this class does NOT yet manage |
25 |
– |
* created configurations which may cause memory problems! |
26 |
– |
* ### |
27 |
– |
* |
23 |
|
* @author $Author$ |
24 |
|
* @version $Id$ |
25 |
|
*/ |
42 |
|
*/ |
43 |
|
ConfigurationManagerServant() { |
44 |
|
// assign some local variables |
45 |
< |
_configPath = System.getProperty("uk.ac.ukc.iscream.ConfigurationLocation"); |
46 |
< |
_systemConfigFile = System.getProperty("uk.ac.ukc.iscream.SystemConfigurationFile"); |
45 |
> |
_configPath = System.getProperty("uk.org.iscream.cms.server.ConfigurationLocation"); |
46 |
> |
_systemConfigFile = System.getProperty("uk.org.iscream.cms.server.SystemConfigurationFile"); |
47 |
|
|
48 |
|
// load the system config |
49 |
|
loadSystemConfig(); |
87 |
|
} |
88 |
|
|
89 |
|
// search config for group membership |
90 |
< |
LinkedList groups = getGroupMembership(source); |
90 |
> |
// and obain a list of groups by name |
91 |
> |
LinkedList nameGroups = getGroupMembership(source); |
92 |
> |
// add the hosts individual config to the start of the list |
93 |
> |
nameGroups.addFirst(source); |
94 |
|
|
95 |
+ |
// this list will be used to compile the groupings |
96 |
+ |
LinkedList groups = new LinkedList(); |
97 |
+ |
|
98 |
|
// if we are dealing with a Host.<hostname> request, then we also |
99 |
|
// want to look for ip address details, as configuration entries may relate to it |
100 |
|
// if we can't resolve it, we don't look. |
101 |
+ |
LinkedList ipGroups = null; |
102 |
|
if (source.startsWith("Host.")) { |
103 |
|
// hostname is after Host. |
104 |
|
String hostname = source.substring(5); |
105 |
|
try { |
106 |
|
String ip = "Host." + InetAddress.getByName(hostname).getHostAddress(); |
107 |
< |
LinkedList ipGroups = getGroupMembership(ip); |
108 |
< |
groups.addFirst(ip); |
107 |
> |
ipGroups = getGroupMembership(ip); |
108 |
> |
ipGroups.addFirst(ip); |
109 |
> |
// add to our list of groups |
110 |
|
groups.addAll(ipGroups); |
111 |
|
} catch (UnknownHostException e) { |
112 |
|
_logger.write(toString(), Logger.ERROR, "could not resolve hostname - " + hostname); |
113 |
|
} |
114 |
|
} |
115 |
+ |
|
116 |
+ |
// add the rest of the groups to the end |
117 |
+ |
groups.addAll(nameGroups); |
118 |
|
|
113 |
– |
// add the hosts individual config to the start of the list |
114 |
– |
groups.addFirst(source); |
115 |
– |
|
119 |
|
Iterator i = groups.iterator(); |
120 |
|
String fileList = ""; |
121 |
|
while (i.hasNext()) { |
184 |
|
* Overrides the {@link java.lang.Object#toString() Object.toString()} |
185 |
|
* method to provide clean logging (every class should have this). |
186 |
|
* |
187 |
< |
* This uses the uk.ac.ukc.iscream.util.FormatName class |
187 |
> |
* This uses the uk.org.iscream.cms.server.util.FormatName class |
188 |
|
* to format the toString() |
189 |
|
* |
190 |
|
* @return the name of this class and its CVS revision |
302 |
|
* @return the list of groups that this source is a member of |
303 |
|
*/ |
304 |
|
private LinkedList getGroupMembership(String source) { |
305 |
< |
_logger.write(toString(), Logger.DEBUG, "searching group members for - " + source); |
305 |
> |
_logger.write(toString(), Logger.DEBUG, "searching groups for - " + source); |
306 |
|
LinkedList groupMembership = new LinkedList(); |
307 |
|
Iterator i = new TreeSet(_systemConfigHolder.keySet()).iterator(); |
308 |
|
while(i.hasNext()) { |
312 |
|
// if it is in the group |
313 |
|
if (group.indexOf(source) != -1) { |
314 |
|
groupMembership.add(key.substring(6)); |
315 |
+ |
_logger.write(toString(), Logger.DEBUG, "group match found for - " + source + " in - " + key); |
316 |
|
|
317 |
|
// if there are wildcards in the group |
318 |
|
} else if (group.indexOf("*") != -1) { |
319 |
|
// check the wildcards apply to this srce |
320 |
< |
if( wildcardCheck(source, group)) { |
320 |
> |
if(StringUtils.wildcardCheck(source, group)) { |
321 |
|
groupMembership.add(key.substring(6)); |
322 |
+ |
_logger.write(toString(), Logger.DEBUG, "wildcard group match found for - " + source + " in - " + key); |
323 |
|
} |
324 |
|
} |
325 |
|
|
326 |
|
} |
327 |
|
} |
328 |
|
return groupMembership; |
324 |
– |
} |
325 |
– |
|
326 |
– |
/** |
327 |
– |
* Checks that a given string is not matched within the |
328 |
– |
* given list of strings. eg:<br> |
329 |
– |
* <br> |
330 |
– |
* Given "stue5de.ukc.ac.uk"<br> |
331 |
– |
* And "raptor.ukc.ac.uk;stue*.ukc.ac.uk<br> |
332 |
– |
* <br> |
333 |
– |
* This method would return true as there is a match |
334 |
– |
* |
335 |
– |
* @param source the string to look for |
336 |
– |
* @param group the group to search for a wilcard entry |
337 |
– |
* |
338 |
– |
* @return if there is a match |
339 |
– |
*/ |
340 |
– |
private boolean wildcardCheck(String source, String group) { |
341 |
– |
boolean foundMatch = false; |
342 |
– |
StringTokenizer st = new StringTokenizer(group, ";"); |
343 |
– |
// go through all the hosts in the group |
344 |
– |
while (st.hasMoreTokens()) { |
345 |
– |
String host = st.nextToken(); |
346 |
– |
// this host has wildcards |
347 |
– |
if(host.indexOf("*") != -1) { |
348 |
– |
StringTokenizer hostst = new StringTokenizer(host, "*"); |
349 |
– |
String part = ""; |
350 |
– |
int index = 0; |
351 |
– |
// the first token will be everything at the start |
352 |
– |
// unless it starts with a wildcard |
353 |
– |
if(!host.startsWith("*")) { |
354 |
– |
part = hostst.nextToken(); |
355 |
– |
if (source.startsWith(part)) { |
356 |
– |
foundMatch = true; |
357 |
– |
index = part.length(); |
358 |
– |
} |
359 |
– |
// all of the start of the string is matched |
360 |
– |
} else { |
361 |
– |
foundMatch = true; |
362 |
– |
} |
363 |
– |
// if the start matched, we want to check the rest... |
364 |
– |
if (foundMatch) { |
365 |
– |
while (hostst.hasMoreTokens()) { |
366 |
– |
part = hostst.nextToken(); |
367 |
– |
// if the next section can't be matched |
368 |
– |
// then this isn't in the source |
369 |
– |
if(source.substring(index).indexOf(part) == -1) { |
370 |
– |
foundMatch = false; |
371 |
– |
// we don't want to look through any more of it |
372 |
– |
break; |
373 |
– |
} else { |
374 |
– |
foundMatch = true; |
375 |
– |
index += source.substring(index).indexOf(part) + part.length(); |
376 |
– |
} |
377 |
– |
} |
378 |
– |
// if we reach here and we've found a match |
379 |
– |
// we want to check that the last part |
380 |
– |
// of the wildcard string is the last part |
381 |
– |
// of the source, if it is, we break out |
382 |
– |
// and finish as we've found a match. |
383 |
– |
// if the end of the wildcard is a *, then |
384 |
– |
// we don't care |
385 |
– |
if (!host.endsWith("*") && foundMatch) { |
386 |
– |
if ((source.endsWith(part))) { |
387 |
– |
_logger.write(toString(), Logger.DEBUG, "wildcard match found for - " + source + " in - " + host); |
388 |
– |
break; |
389 |
– |
// if there is no match, say so so we go round again |
390 |
– |
} else { |
391 |
– |
foundMatch = false; |
392 |
– |
} |
393 |
– |
} else if (foundMatch) { |
394 |
– |
_logger.write(toString(), Logger.DEBUG, "wildcard match found for - " + source + " in - " + host); |
395 |
– |
break; |
396 |
– |
} |
397 |
– |
} |
398 |
– |
} |
399 |
– |
} |
400 |
– |
return foundMatch; |
329 |
|
} |
402 |
– |
|
330 |
|
|
331 |
|
/** |
332 |
|
* Build the properties as a Configuration to be |