KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ofbiz > base > config > SecurityConfigUtil


1 /*
2  * $Id: SecurityConfigUtil.java 5462 2005-08-05 18:35:48Z jonesde $
3  *
4  * Copyright (c) 2002 The Open For Business Project and repected authors.
5  * Permission is hereby granted, free of charge, to any person obtaining a
6  * copy of this software and associated documentation files (the "Software"),
7  * to deal in the Software without restriction, including without limitation
8  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9  * and/or sell copies of the Software, and to permit persons to whom the
10  * Software is furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be included
13  * in all copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
20  * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
21  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22  */

23 package org.ofbiz.base.config;
24
25 import java.util.*;
26 import org.w3c.dom.*;
27 import org.ofbiz.base.util.*;
28
29 /**
30  * <code>SecurityConfigUtil</code>
31  *
32  * This class allows the loading of a security implementation by a security context name.
33  * The security context name has to be specified in security.properties by the property name:
34  * security.context=
35  *
36  * The setup of custom security implementations can be customized in the security.xml file.
37  *
38  * @author <a HREF="mailto:hermanns@aixcept.de">Rainer Hermanns</a>
39  * @version $Rev: 5462 $
40  */

41 public class SecurityConfigUtil {
42     
43     public static final String JavaDoc module = SecurityConfigUtil.class.getName();
44
45     /** The security config filename */
46     public static final String JavaDoc SECURITY_CONFIG_XML_FILENAME = "security.xml";
47
48     protected static Map securityInfos = new HashMap();
49
50     /**
51      * Returns the XmlRootElement for the security config
52      *
53      * @return
54      * @throws GenericConfigException
55      */

56     public static Element getXmlRootElement() throws GenericConfigException {
57         return ResourceLoader.getXmlRootElement(SecurityConfigUtil.SECURITY_CONFIG_XML_FILENAME);
58     }
59
60     /**
61      * Returns the XmlDocument for the security config
62      *
63      * @return
64      * @throws GenericConfigException
65      */

66     public static Document getXmlDocument() throws GenericConfigException {
67         return ResourceLoader.getXmlDocument(SecurityConfigUtil.SECURITY_CONFIG_XML_FILENAME);
68     }
69
70     static {
71         try {
72             initialize(getXmlRootElement());
73         } catch (Exception JavaDoc e) {
74             Debug.logError(e, "Error loading Security config XML file " + SECURITY_CONFIG_XML_FILENAME, module);
75         }
76     }
77
78     /**
79      * Initializes the security configuration
80      *
81      * @param rootElement
82      * @throws GenericConfigException
83      */

84     public static void initialize(Element rootElement) throws GenericConfigException {
85         List childElements = null;
86         Iterator elementIter = null;
87
88         // security-config - securityInfos
89
childElements = UtilXml.childElementList(rootElement, "security");
90         elementIter = childElements.iterator();
91         while (elementIter.hasNext()) {
92             Element curElement = (Element) elementIter.next();
93             SecurityConfigUtil.SecurityInfo securityInfo = new SecurityConfigUtil.SecurityInfo(curElement);
94
95             if (Debug.verboseOn()) Debug.logVerbose("LOADED SECURITY CONFIG FROM XML - NAME: " + securityInfo.name + " ClassName: " + securityInfo.className, module);
96             SecurityConfigUtil.securityInfos.put(securityInfo.name, securityInfo);
97         }
98     }
99
100     /**
101      * Returns the security config for a given name
102      *
103      * @param name
104      * @return
105      */

106     public static SecurityConfigUtil.SecurityInfo getSecurityInfo(String JavaDoc name) {
107         return (SecurityConfigUtil.SecurityInfo) securityInfos.get(name);
108     }
109
110     /**
111      * <code>SecurityInfo</code>
112      */

113     public static class SecurityInfo {
114         public String JavaDoc name;
115         public String JavaDoc className;
116
117         /**
118          * Creates a SecurityInfo for a given element
119          *
120          * @param element
121          */

122         public SecurityInfo(Element element) {
123             this.name = element.getAttribute("name");
124             this.className = element.getAttribute("class");
125         }
126     }
127 }
128
Popular Tags