KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mmbase > security > Configurable


1 /*
2
3 This software is OSI Certified Open Source Software.
4 OSI Certified is a certification mark of the Open Source Initiative.
5
6 The license (Mozilla version 1.0) can be read at the MMBase site.
7 See http://www.MMBase.org/license
8
9 */

10 package org.mmbase.security;
11
12 import org.mmbase.util.ResourceWatcher;
13
14 import org.mmbase.util.logging.Logger;
15 import org.mmbase.util.logging.Logging;
16
17 /**
18  * Both Authorization and Authentication are configurable.
19  * This class provides the shared functionality for that.
20  *
21  * @author Eduard Witteveen
22  * @author Michiel Meeuwissen
23  * @version $Id: Configurable.java,v 1.11 2005/09/09 15:07:50 michiel Exp $
24  * @since MMBase-1.7
25  */

26 public abstract class Configurable {
27     private static final Logger log = Logging.getLoggerInstance(Configurable.class);
28
29     /**
30      * The SecurityManager, which created this instance
31      */

32     protected MMBaseCop manager;
33
34     /**
35      * This specific security configuration file. The file is absolute. Might be
36      * null if the implementation does not have its own configuruation file.
37      * @since MMBase-1.8
38      */

39     protected String JavaDoc configResource; // relative to securityLoader
40

41
42     /**
43      * @deprecated
44      */

45     protected java.io.File JavaDoc configFile;
46
47
48     /**
49      * This filewatcher checks the configuration file for changes.
50      */

51     protected ResourceWatcher configWatcher;
52
53
54     /**
55      * The method which initialized an instance of this class. This method cannot be be overrided.
56      * This methods sets the member variables of this object and then
57      * calls the method load();
58      * @param manager The class that created this instance.
59      * @param configWatcher checks the files for changes
60      * @param configPath The url which contains the config information for the authorization (e.g. context/config.xml). Or null (if configured to be "")
61      * @see #load
62      */

63     public final void load(MMBaseCop manager, ResourceWatcher configWatcher, String JavaDoc configPath) {
64         if (log.isDebugEnabled()) {
65             log.debug("Calling load() with as config file:" + configPath);
66         }
67         this.manager = manager;
68         this.configWatcher = configWatcher;
69
70         configWatcher.setDelay(10 * 1000);
71
72         if (configPath != null && !configPath.equals("")) {
73             if (configPath.startsWith("/")) {
74                 configResource = "file://" + configPath;
75             } else {
76                 configResource = configPath;
77             }
78             
79             
80             java.util.List JavaDoc files = configWatcher.getResourceLoader().getFiles(configResource);
81             
82             if (files.size() > 0) {
83                 configFile = (java.io.File JavaDoc) files.get(0);
84             }
85             
86             configWatcher.add(configResource);
87         }
88
89
90         load();
91     }
92
93     /**
94      * This method should be overrided by an extending class. It should further initialize the
95      * class. It can optionally retrieve settings from the general security configuration file
96      * (available as the 'configFile' member). Security implementations with complicated
97      * configuration would typically retrieve a path to their own configuration file only.
98      */

99     protected abstract void load();
100 }
101
Popular Tags