307 |
|
* @return the list of groups that this source is a member of |
308 |
|
*/ |
309 |
|
private LinkedList getGroupMembership(String source) { |
310 |
< |
_logger.write(toString(), Logger.DEBUG, "searching group members for - " + source); |
310 |
> |
_logger.write(toString(), Logger.DEBUG, "searching groups for - " + source); |
311 |
|
LinkedList groupMembership = new LinkedList(); |
312 |
|
Iterator i = new TreeSet(_systemConfigHolder.keySet()).iterator(); |
313 |
|
while(i.hasNext()) { |
317 |
|
// if it is in the group |
318 |
|
if (group.indexOf(source) != -1) { |
319 |
|
groupMembership.add(key.substring(6)); |
320 |
+ |
_logger.write(toString(), Logger.DEBUG, "group match found for - " + source + " in - " + key); |
321 |
|
|
322 |
|
// if there are wildcards in the group |
323 |
|
} else if (group.indexOf("*") != -1) { |
324 |
|
// check the wildcards apply to this srce |
325 |
< |
if( wildcardCheck(source, group)) { |
325 |
> |
if(StringUtils.wildcardCheck(source, group)) { |
326 |
|
groupMembership.add(key.substring(6)); |
327 |
+ |
_logger.write(toString(), Logger.DEBUG, "wildcard group match found for - " + source + " in - " + key); |
328 |
|
} |
329 |
|
} |
330 |
|
|
331 |
|
} |
332 |
|
} |
333 |
|
return groupMembership; |
332 |
– |
} |
333 |
– |
|
334 |
– |
/** |
335 |
– |
* Checks that a given string is not matched within the |
336 |
– |
* given list of strings. For example:<br> |
337 |
– |
* <br> |
338 |
– |
* Given "stue5de.ukc.ac.uk"<br> |
339 |
– |
* And "raptor.ukc.ac.uk;stue*.ukc.ac.uk<br> |
340 |
– |
* <br> |
341 |
– |
* This method would return true as there is a match |
342 |
– |
* |
343 |
– |
* @param source the string to look for |
344 |
– |
* @param group the group to search for a wilcard entry |
345 |
– |
* |
346 |
– |
* @return if there is a match |
347 |
– |
*/ |
348 |
– |
private boolean wildcardCheck(String source, String group) { |
349 |
– |
boolean foundMatch = false; |
350 |
– |
StringTokenizer st = new StringTokenizer(group, ";"); |
351 |
– |
// go through all the hosts in the group |
352 |
– |
while (st.hasMoreTokens()) { |
353 |
– |
String host = st.nextToken(); |
354 |
– |
// this host has wildcards |
355 |
– |
if(host.indexOf("*") != -1) { |
356 |
– |
StringTokenizer hostst = new StringTokenizer(host, "*"); |
357 |
– |
String part = ""; |
358 |
– |
int index = 0; |
359 |
– |
// the first token will be everything at the start |
360 |
– |
// unless it starts with a wildcard |
361 |
– |
if(!host.startsWith("*")) { |
362 |
– |
part = hostst.nextToken(); |
363 |
– |
if (source.startsWith(part)) { |
364 |
– |
foundMatch = true; |
365 |
– |
index = part.length(); |
366 |
– |
} |
367 |
– |
// all of the start of the string is matched |
368 |
– |
} else { |
369 |
– |
foundMatch = true; |
370 |
– |
} |
371 |
– |
// if the start matched, we want to check the rest... |
372 |
– |
if (foundMatch) { |
373 |
– |
while (hostst.hasMoreTokens()) { |
374 |
– |
part = hostst.nextToken(); |
375 |
– |
// if the next section can't be matched |
376 |
– |
// then this isn't in the source |
377 |
– |
if(source.substring(index).indexOf(part) == -1) { |
378 |
– |
foundMatch = false; |
379 |
– |
// we don't want to look through any more of it |
380 |
– |
break; |
381 |
– |
} else { |
382 |
– |
foundMatch = true; |
383 |
– |
index += source.substring(index).indexOf(part) + part.length(); |
384 |
– |
} |
385 |
– |
} |
386 |
– |
// if we reach here and we've found a match |
387 |
– |
// we want to check that the last part |
388 |
– |
// of the wildcard string is the last part |
389 |
– |
// of the source, if it is, we break out |
390 |
– |
// and finish as we've found a match. |
391 |
– |
// if the end of the wildcard is a *, then |
392 |
– |
// we don't care |
393 |
– |
if (!host.endsWith("*") && foundMatch) { |
394 |
– |
if ((source.endsWith(part))) { |
395 |
– |
_logger.write(toString(), Logger.DEBUG, "wildcard match found for - " + source + " in - " + host); |
396 |
– |
break; |
397 |
– |
// if there is no match, say so so we go round again |
398 |
– |
} else { |
399 |
– |
foundMatch = false; |
400 |
– |
} |
401 |
– |
} else if (foundMatch) { |
402 |
– |
_logger.write(toString(), Logger.DEBUG, "wildcard match found for - " + source + " in - " + host); |
403 |
– |
break; |
404 |
– |
} |
405 |
– |
} |
406 |
– |
} |
407 |
– |
} |
408 |
– |
return foundMatch; |
334 |
|
} |
410 |
– |
|
335 |
|
|
336 |
|
/** |
337 |
|
* Build the properties as a Configuration to be |