KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mr > kernel > security > impl > management > ACLManagementFactory


1 package org.mr.kernel.security.impl.management;
2
3 import org.mr.MantaAgent;
4 import org.mr.core.configuration.ConfigurationElement;
5 import org.mr.core.cmc.MantaJMXManagement;
6 import org.mr.kernel.security.MantaSecurityException;
7 import org.mr.kernel.security.SecurityConfigurationPaths;
8 import org.apache.commons.logging.Log;
9 import org.apache.commons.logging.LogFactory;
10
11 import java.lang.reflect.Constructor JavaDoc;
12 import java.util.Collection JavaDoc;
13 import java.util.ArrayList JavaDoc;
14 import java.util.Map JavaDoc;
15 import java.util.HashMap JavaDoc;
16
17 /**
18  * This class is a factory class for instances of ACLManagement.
19  * It creates an instance of ACLManagement object according to the configuration name supplied.
20  *
21  * The configuration name should exist in default_config.xml under security.acl.configurations.
22  *
23  * @author Shirley Sasson
24  * @version 1.0
25  * @since May 23, 2006
26  */

27 public class ACLManagementFactory implements SecurityConfigurationPaths {
28     private static Log _logger;
29     private static Map JavaDoc _instances;
30
31     /**
32      * Returns an instance of ACLManagement according to the configuration name supplied.
33      * When a new object is instantiated, it is put in the _instances map.
34      * When this method is called, an instance is searched in the _instances map, and if found,
35      * it is returned. Else, a new instance is created. This is done in order to have just one
36      * instance per configuration in system.
37      *
38      * @param name the configuration name
39      * @return an instance of ACLManagement
40      * @throws MantaSecurityException if an error occured
41      */

42     public static ACLManagement getACLManagement(String JavaDoc name) throws MantaSecurityException {
43         if (_instances != null && _instances.containsKey(name))
44             return (ACLManagement) _instances.get(name);
45
46         ACLManagement management;
47         try {
48             String JavaDoc managementImplementationClass = MantaAgent.getInstance().getSingletonRepository().getConfigManager().getStringProperty(ACL_CONFIGURATIONS + "." + name + "." + MANAGEMENT_IMPLEMENTATION);
49             Class JavaDoc[] parameters = {String JavaDoc.class};
50             Constructor JavaDoc constructor = Class.forName(managementImplementationClass).getConstructor(parameters);
51             String JavaDoc[] args = {name};
52             management = (ACLManagement) constructor.newInstance(args);
53
54             // register the JMX object of the ACLManagement instance to the MantaJMXManagement
55
MantaJMXManagement.getInstance().addManagedObject(management.getManagedObject(), "MantaRay:type=securityManagement,configurationName="+name);
56
57             // put the new created instance in the map
58
if (_instances == null)
59                 _instances = new HashMap JavaDoc();
60             _instances.put(name, management);
61         }
62         catch (Exception JavaDoc e){
63             if (getLogger().isErrorEnabled())
64                 getLogger().error("[getACLManagement] Error instantiating ACLManagement class for configuration with name " + name + ". " + e.getMessage());
65             throw new MantaSecurityException("Error instantiating ACLManagement class for configuration with name " + name);
66         }
67         return management;
68     }
69
70     /**
71      * Returns a collection of available configuration names. It returns all tag names from default_config.xml
72      * that appear under security.acl.configurations.
73      *
74      * @return a collection of available configuration names
75      * @throws MantaSecurityException if an error occured
76      */

77     public static Collection JavaDoc getAvailableConfigurationNames() throws MantaSecurityException {
78         Collection JavaDoc c = new ArrayList JavaDoc();
79         ArrayList JavaDoc configurations = MantaAgent.getInstance().getSingletonRepository().getConfigManager().getConfigurationElements(ACL_CONFIGURATIONS);
80         if (configurations == null){
81             if (getLogger().isErrorEnabled())
82                 getLogger().error("[getAvailableConfigurationNames] Unable to find configuration element: " + ACL_CONFIGURATIONS);
83             throw new MantaSecurityException("Unable to find configuration element: " + ACL_CONFIGURATIONS);
84         }
85         ConfigurationElement element = (ConfigurationElement) configurations.get(0);
86         ArrayList JavaDoc subElements = element.getSubConfigurationElements();
87         for (int i=0 ; i<subElements.size() ; i++){
88             ConfigurationElement current = (ConfigurationElement) subElements.get(i);
89             c.add(current.getName());
90         }
91         return c;
92     }
93
94     /**
95      * Returns the instance of the logger for this class
96      *
97      * @return the instance of the logger
98      */

99     public static Log getLogger(){
100         if (_logger == null){
101             _logger = LogFactory.getLog("ACLManagementFactory");
102         }
103         return _logger;
104     }
105 }
106
Popular Tags