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.12 by tdb, Thu Mar 1 20:22:21 2001 UTC vs.
Revision 1.19 by tdb, Mon Dec 10 22:20:23 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.*;
10   import java.io.*;
11  
# Line 45 | 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 90 | Line 92 | class ConfigurationManagerServant extends Configuratio
92          }
93  
94          // search config for group membership
95 <        LinkedList groups = getGroupMembership(source);
96 <
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 <        groups.addFirst(source);
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 >                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  
124          Iterator i = groups.iterator();
125          String fileList = "";
# Line 123 | Line 149 | class ConfigurationManagerServant extends Configuratio
149              }
150          }
151          // add the system config as the final check
152 <        fileList += _systemConfigFile + ";";
152 >        fileList = _systemConfigFile + ";" + fileList;
153          _logger.write(toString(), Logger.DEBUG, "config tree - " + fileList);
154          
155          // build the configuration
# Line 163 | 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 281 | 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);
311          LinkedList groupMembership = new LinkedList();        
312          Iterator i = new TreeSet(_systemConfigHolder.keySet()).iterator();
313          while(i.hasNext()) {
314              String key = (String) i.next();
315              if (key.startsWith("group.")) {
316                  String group = _systemConfig.getProperty(key);
317 +                // if it is in the group
318                  if (group.indexOf(source) != -1) {
319                      groupMembership.add(key.substring(6));
320 +                
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 +                    }
327                  }
328 +                
329              }  
330          }
331          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;
409 +    }
410 +
411 +
412 +    /**
413       * Build the properties as a Configuration to be
414       * returned to the caller
415       *
# Line 315 | Line 429 | class ConfigurationManagerServant extends Configuratio
429                  
430                  // some holders for variables
431                  File currentFile;
432 <                long lastModified, newLastModified;
433 <                Properties properties, prevProperties;
432 >                long lastModified = 0, newLastModified = 0;
433 >                Properties properties = null, prevProperties = null;
434                  
435                  // the root of all configurations will be the system config
436                  // so we need to open the properties of that
437                  Properties defaultProperties = new Properties();
324                currentFile = new File(_configPath, _systemConfigFile);
325                lastModified = currentFile.lastModified();
326                defaultProperties.load(new FileInputStream(currentFile));
438                  
439                  // This loop then iterates over the file list
440                  // creates the properties to be passed to the
441                  // Configuration constructor
442 <                do {
442 >                while (st.hasMoreTokens()) {
443                      properties = new Properties(defaultProperties);
444                      currentFile = new File(_configPath, st.nextToken());
445                      newLastModified = currentFile.lastModified();
# Line 337 | Line 448 | class ConfigurationManagerServant extends Configuratio
448                      }
449                      properties.load(new FileInputStream(currentFile));
450                      defaultProperties = properties;
451 <                } while (st.hasMoreTokens());
451 >                }
452  
453                  // this creates the configuration, all nice, ready to be returned
454                  ConfigurationServant ref = new ConfigurationServant(properties, fileList, lastModified);
455                  org.omg.CORBA.Object objRef = _refman.getRootPOA().servant_to_reference(ref);
456                  config = ConfigurationHelper.narrow(objRef);
457 <
457 >                _logger.write(toString(), Logger.DEBUG, "returning built configuration");
458              } catch (Exception e) {
459                  // not sure what to do here
460                  // so we just log the error

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines