KickJava   Java API By Example, From Geeks To Geeks.

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


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
13 import org.mmbase.util.logging.Logger;
14 import org.mmbase.util.logging.Logging;
15
16 /**
17  * This class is the main class of the security system. It loads the authentication
18  * and authorization classes if needed, and they can be requested from this manager.
19  * @javadoc
20  * @author Eduard Witteveen
21  * @version $Id: MMBaseCop.java,v 1.22 2005/09/16 13:14:48 michiel Exp $
22  */

23 public class MMBaseCop extends SecurityManager JavaDoc {
24     private static final Logger log = Logging.getLoggerInstance(MMBaseCop.class);
25
26     /**
27      * The configuration used by our system
28      */

29     private MMBaseCopConfig config;
30
31     /**
32      * The constructor, will load the classes for authorization and authentication
33      * with their config files, as specied in the xml from configUrl
34      * @throws java.io.IOException When reading the file failed
35      * @throws java.lang.NoSuchMethodException When a tag was not specified
36      * @throws org.mmbase.security.SecurityException When the class could not be loaded
37      */

38     public MMBaseCop() throws java.io.IOException JavaDoc, NoSuchMethodException JavaDoc, SecurityException JavaDoc {
39         super();
40         config = new MMBaseCopConfig(this);
41         config.load();
42         log.service("Done loading security configuration");
43     }
44
45
46     /**
47      * reload, will load the classes for authorization and authentication
48      * with their config files, as specied in the xml from configUrl
49      * @throws java.io.IOException When reading the file failed
50      * @throws java.lang.NoSuchMethodException When a tag was not specified
51      * @throws org.mmbase.security.SecurityException When the class could not be loaded
52      */

53     public void reload() throws java.io.IOException JavaDoc, NoSuchMethodException JavaDoc, SecurityException JavaDoc {
54         log.debug("Retrieving a new security configuration...");
55         MMBaseCopConfig newConfig = new MMBaseCopConfig(this);
56         newConfig.load();
57         // if no exception happed, the configuration can be replaced
58
config.watcher.clear();
59         config = newConfig;
60         log.info("Done changing security configuration");
61     }
62
63     private final MMBaseCopConfig getConfig() {
64         if (config == null) throw new RuntimeException JavaDoc("No MMBaseCopConfig in MMBaseCop!!");
65         return config;
66     }
67
68     /**
69      * Returns the authentication class, which should be used.
70      * @return The authentication class which should be used.
71      */

72     public Authentication getAuthentication() {
73         return getConfig().getAuthentication();
74     }
75
76     /**
77      * Returns the authorization class, which should be used.
78      * @return The authorization class which should be used.
79      */

80     public Authorization getAuthorization() {
81         return getConfig().getAuthorization();
82     }
83
84     /**
85      * Returns the authorization class, which should be used(for optimizations)
86      * @return <code>true</code>When the SecurityManager should
87      * be used.
88      * <code>false</code>When not.
89      */

90     public boolean getActive() {
91         return getConfig().getActive();
92     }
93
94     /**
95      * checks if the received shared secret is equals to your own shared secret
96      * @param received shared secret
97      * @return true if received shared secret equals your own shared secret
98      * @return false if received shared secret not equals your own shared secret
99      */

100     public boolean checkSharedSecret(String JavaDoc received) {
101         return getConfig().checkSharedSecret(received);
102     }
103
104     /**
105      * get the shared Secret
106      * @return the shared Secret
107      */

108     public String JavaDoc getSharedSecret() {
109         return getConfig().getSharedSecret();
110     }
111 }
112
Popular Tags