ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/server/uk/org/iscream/cms/server/core/ConfigurationManagerServant.java
(Generate patch)

Comparing projects/cms/source/server/uk/org/iscream/cms/server/core/ConfigurationManagerServant.java (file contents):
Revision 1.17 by tdb, Mon Mar 19 19:12:29 2001 UTC vs.
Revision 1.22 by tdb, Tue Dec 11 17:52:35 2001 UTC

# Line 1 | Line 1
1   //---PACKAGE DECLARATION---
2 < package uk.org.iscream.core;
2 > package uk.org.iscream.cms.server.core;
3  
4   //---IMPORTS---
5 < import uk.org.iscream.util.*;
6 < import uk.org.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.*;
# Line 20 | Line 20 | import java.io.*;
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   */
# Line 47 | Line 42 | class ConfigurationManagerServant extends Configuratio
42       */
43      ConfigurationManagerServant() {
44          // assign some local variables
45 <        _configPath = System.getProperty("uk.org.iscream.ConfigurationLocation");
46 <        _systemConfigFile = System.getProperty("uk.org.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();
# Line 189 | Line 184 | class ConfigurationManagerServant extends Configuratio
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.org.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
# Line 307 | Line 302 | class ConfigurationManagerServant extends Configuratio
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()) {
309              String key = (String) i.next();
310 +            // look for a key that's a group entry
311              if (key.startsWith("group.")) {
312 +                // get the list of hosts in the group
313                  String group = _systemConfig.getProperty(key);
314 <                // if it is in the group
318 <                if (group.indexOf(source) != -1) {
314 >                if(groupMatch(source, group)) {
315                      groupMembership.add(key.substring(6));
316 <                
321 <                // if there are wildcards in the group
322 <                } else if (group.indexOf("*") != -1) {
323 <                    // check the wildcards apply to this srce
324 <                    if( wildcardCheck(source, group)) {
325 <                        groupMembership.add(key.substring(6));
326 <                    }
316 >                    _logger.write(toString(), Logger.DEBUG, "group match found for - " + source + " in group - " + key);
317                  }
328                
318              }  
319          }
320          return groupMembership;
321 <    }    
322 <
321 >    }
322 >    
323      /**
324 <     * Checks that a given string is not matched within the
325 <     * given list of strings. eg:<br>
324 >     * Checks that a given source is matched within the
325 >     * given list of hosts. For example:<br>
326       * <br>
327       * Given "stue5de.ukc.ac.uk"<br>
328       * And   "raptor.ukc.ac.uk;stue*.ukc.ac.uk<br>
329       * <br>
330 <     * This method would return true as there is a match
331 <     *
330 >     * This method would return true as there is a match.
331 >     *
332 >     * This method will also match if the source is exactly
333 >     * matched within the group of hosts (ie. no wildcard).
334 >     *
335       * @param source the string to look for
336 <     * @param group the group to search for a wilcard entry
336 >     * @param group the group to search for a match
337       *
338       * @return if there is a match
339       */
340 <    private boolean wildcardCheck(String source, String group) {
349 <        boolean foundMatch = false;
340 >    public static boolean groupMatch(String source, String group) {
341          StringTokenizer st = new StringTokenizer(group, ";");
342          // go through all the hosts in the group
343          while (st.hasMoreTokens()) {
344              String host = st.nextToken();
345 <            // this host has wildcards
346 <            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 <                }
345 >            if(StringUtils.wildcardMatch(source, host)) {
346 >                return true;
347              }
348          }
349 <        return foundMatch;
349 >        // not had a match
350 >        return false;
351      }
410
352  
353      /**
354       * Build the properties as a Configuration to be

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines