KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > security > auth > login > XMLLoginConfig


1
2 /*
3  * JBoss, the OpenSource J2EE WebOS
4  *
5  * Distributable under LGPL license.
6  * See terms of license at gnu.org.
7  */

8 package org.jboss.security.auth.login;
9
10 import java.util.Iterator JavaDoc;
11 import java.util.Map JavaDoc;
12 import java.util.Map.Entry;
13 import java.io.IOException JavaDoc;
14 import java.net.URL JavaDoc;
15 import javax.security.auth.login.Configuration JavaDoc;
16 import javax.security.auth.login.AppConfigurationEntry JavaDoc;
17
18 import org.jboss.system.ServiceMBeanSupport;
19
20 /** An MBean for managing a XMLLoginConfigImpl instance.
21
22  @author Scott.Stark@jboss.org
23  @version $Revision: 1.9.6.1 $
24  */

25 public class XMLLoginConfig extends ServiceMBeanSupport
26       implements XMLLoginConfigMBean
27 {
28    private XMLLoginConfigImpl config;
29    private boolean passSecurityDomainName;
30
31    public XMLLoginConfig()
32    {
33       config = new XMLLoginConfigImpl();
34    }
35
36 // --- Begin XMLLoginConfigMBean interface methods
37

38    /** Set the URL of the XML login configuration file that should
39     be loaded by this mbean on startup.
40     */

41    public URL JavaDoc getConfigURL()
42    {
43       return config.getConfigURL();
44    }
45    /** Set the URL of the XML login configuration file that should
46     be loaded by this mbean on startup.
47     */

48    public void setConfigURL(URL JavaDoc configURL)
49    {
50       config.setConfigURL(configURL);
51    }
52
53    /** Set the resource name of the XML login configuration file that should
54     be loaded by this mbean on startup.
55     */

56    public void setConfigResource(String JavaDoc resourceName)
57       throws IOException JavaDoc
58    {
59       config.setConfigResource(resourceName);
60    }
61
62    /** Get whether the login config xml document is validated againsts its DTD
63     */

64    public boolean getValidateDTD()
65    {
66       return config.getValidateDTD();
67    }
68    /** Set whether the login config xml document is validated againsts its DTD
69     */

70    public void setValidateDTD(boolean flag)
71    {
72       config.setValidateDTD(flag);
73    }
74
75    public boolean getPassSecurityDomainName()
76    {
77       return passSecurityDomainName;
78    }
79    public void setPassSecurityDomainName(boolean flag)
80    {
81       this.passSecurityDomainName = flag;
82    }
83
84    /** Add an application login configuration. Any existing configuration for
85     the given appName will be replaced.
86     */

87    public void addAppConfig(String JavaDoc appName, AppConfigurationEntry JavaDoc[] entries)
88    {
89       config.addAppConfig(appName, entries);
90    }
91    /** Remove an application login configuration.
92     */

93    public void removeAppConfig(String JavaDoc appName)
94    {
95       config.removeAppConfig(appName);
96    }
97
98    /** Get the XML based configuration given the Configuration it should
99     delegate to when an application cannot be found.
100     */

101    public Configuration JavaDoc getConfiguration(Configuration JavaDoc prevConfig)
102    {
103       config.setParentConfig(prevConfig);
104       return config;
105    }
106
107    /** Load the login configuration information from the given config URL.
108     * @param configURL A URL to an XML or Sun login config file.
109     * @throws Exception on failure to load the configuration
110     */

111    public String JavaDoc[] loadConfig(URL JavaDoc configURL) throws Exception JavaDoc
112    {
113       return config.loadConfig(configURL);
114    }
115
116    public void removeConfigs(String JavaDoc[] appNames)
117    {
118       int count = appNames == null ? 0 : appNames.length;
119       for(int a = 0; a < count; a ++)
120          removeAppConfig(appNames[a]);
121    }
122
123    /** Display the login configuration for the given application.
124     */

125    public String JavaDoc displayAppConfig(String JavaDoc appName)
126    {
127       StringBuffer JavaDoc buffer = new StringBuffer JavaDoc("<h2>"+appName+" LoginConfiguration</h2>\n");
128       AppConfigurationEntry JavaDoc[] appEntry = config.getAppConfigurationEntry(appName);
129       if( appEntry == null )
130          buffer.append("No Entry\n");
131       else
132       {
133          for(int c = 0; c < appEntry.length; c ++)
134          {
135             AppConfigurationEntry JavaDoc entry = appEntry[c];
136             buffer.append("LoginModule Class: "+entry.getLoginModuleName());
137             buffer.append("\n<br>ControlFlag: "+entry.getControlFlag());
138             buffer.append("\n<br>Options:<ul>");
139             Map JavaDoc options = entry.getOptions();
140             Iterator JavaDoc iter = options.entrySet().iterator();
141             while( iter.hasNext() )
142             {
143                Entry e = (Entry) iter.next();
144                buffer.append("<li>");
145                buffer.append("name="+e.getKey());
146                buffer.append(", value="+e.getValue());
147                buffer.append("</li>\n");
148             }
149             buffer.append("</ul>\n");
150          }
151       }
152       return buffer.toString();
153    }
154 // --- End XMLLoginConfigMBean interface methods
155

156 // --- Begin ServiceMBeanSupport overriden methods
157

158    /** Load the configuration
159     */

160    protected void startService() throws Exception JavaDoc
161    {
162       config.loadConfig();
163    }
164
165    /** Clear all configuration entries
166     */

167    protected void destroyService()
168    {
169       config.clear();
170    }
171
172 // --- End ServiceMBeanSupport overriden methods
173

174 }
175
Popular Tags