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.15 by ajm, Sat Mar 3 14:52:56 2001 UTC vs.
Revision 1.20 by tdb, Mon Dec 10 22:49:19 2001 UTC

# Line 1 | Line 1
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.*;
# Line 47 | Line 47 | class ConfigurationManagerServant extends Configuratio
47       */
48      ConfigurationManagerServant() {
49          // assign some local variables
50 <        _configPath = System.getProperty("uk.ac.ukc.iscream.ConfigurationLocation");
51 <        _systemConfigFile = System.getProperty("uk.ac.ukc.iscream.SystemConfigurationFile");
50 >        _configPath = System.getProperty("uk.org.iscream.cms.server.ConfigurationLocation");
51 >        _systemConfigFile = System.getProperty("uk.org.iscream.cms.server.SystemConfigurationFile");
52  
53          // load the system config
54          loadSystemConfig();
# Line 92 | Line 92 | class ConfigurationManagerServant extends Configuratio
92          }
93  
94          // search config for group membership
95 <        LinkedList groups = getGroupMembership(source);
95 >        // and obain a list of groups by name
96 >        LinkedList nameGroups = getGroupMembership(source);
97 >        // add the hosts individual config to the start of the list
98 >        nameGroups.addFirst(source);
99          
100 +        // this list will be used to compile the groupings
101 +        LinkedList groups = new LinkedList();
102 +                    
103          // if we are dealing with a Host.<hostname> request, then we also
104          // want to look for ip address details, as configuration entries may relate to it
105          // if we can't resolve it, we don't look.
106 +        LinkedList ipGroups = null;
107          if (source.startsWith("Host.")) {
108              // hostname is after Host.
109              String hostname = source.substring(5);
110              try {
111                  String ip = "Host." + InetAddress.getByName(hostname).getHostAddress();
112 <                LinkedList ipGroups = getGroupMembership(ip);
113 <                groups.addFirst(ip);
112 >                ipGroups = getGroupMembership(ip);
113 >                ipGroups.addFirst(ip);
114 >                // add to our list of groups
115                  groups.addAll(ipGroups);
116              } catch (UnknownHostException e) {
117                  _logger.write(toString(), Logger.ERROR, "could not resolve hostname - " + hostname);
118              }
119          }
120 +        
121 +        // add the rest of the groups to the end        
122 +        groups.addAll(nameGroups);
123  
113        // add the hosts individual config to the start of the list
114        groups.addFirst(source);
115
124          Iterator i = groups.iterator();
125          String fileList = "";
126          while (i.hasNext()) {
# Line 181 | Line 189 | class ConfigurationManagerServant extends Configuratio
189       * Overrides the {@link java.lang.Object#toString() Object.toString()}
190       * method to provide clean logging (every class should have this).
191       *
192 <     * This uses the uk.ac.ukc.iscream.util.FormatName class
192 >     * This uses the uk.org.iscream.cms.server.util.FormatName class
193       * to format the toString()
194       *
195       * @return the name of this class and its CVS revision
# Line 299 | Line 307 | class ConfigurationManagerServant extends Configuratio
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()) {
# Line 309 | Line 317 | class ConfigurationManagerServant extends Configuratio
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;
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;
334      }
402
335  
336      /**
337       * Build the properties as a Configuration to be

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines