KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > console > securitymanager > realm > SecurityRealmPortlet


1 /**
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17 package org.apache.geronimo.console.securitymanager.realm;
18
19 import org.apache.commons.logging.Log;
20 import org.apache.commons.logging.LogFactory;
21 import org.apache.geronimo.console.BasePortlet;
22 import org.apache.geronimo.console.util.PortletManager;
23 import org.apache.geronimo.deployment.xbeans.ArtifactType;
24 import org.apache.geronimo.deployment.xbeans.AttributeType;
25 import org.apache.geronimo.deployment.xbeans.ModuleDocument;
26 import org.apache.geronimo.deployment.xbeans.ModuleType;
27 import org.apache.geronimo.deployment.xbeans.DependenciesType;
28 import org.apache.geronimo.deployment.xbeans.EnvironmentType;
29 import org.apache.geronimo.deployment.xbeans.GbeanType;
30 import org.apache.geronimo.deployment.xbeans.ReferenceType;
31 import org.apache.geronimo.deployment.xbeans.XmlAttributeType;
32 import org.apache.geronimo.deployment.xbeans.AbstractServiceType;
33 import org.apache.geronimo.deployment.xbeans.ServiceDocument;
34 import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
35 import org.apache.geronimo.kernel.Kernel;
36 import org.apache.geronimo.kernel.KernelRegistry;
37 import org.apache.geronimo.kernel.config.Configuration;
38 import org.apache.geronimo.kernel.config.ConfigurationManager;
39 import org.apache.geronimo.kernel.config.ConfigurationModuleType;
40 import org.apache.geronimo.kernel.config.ConfigurationUtil;
41 import org.apache.geronimo.kernel.management.State;
42 import org.apache.geronimo.kernel.proxy.GeronimoManagedBean;
43 import org.apache.geronimo.kernel.repository.Artifact;
44 import org.apache.geronimo.kernel.repository.ListableRepository;
45 import org.apache.geronimo.management.geronimo.JCAManagedConnectionFactory;
46 import org.apache.geronimo.security.jaas.JaasLoginModuleChain;
47 import org.apache.geronimo.security.jaas.LoginModuleSettings;
48 import org.apache.geronimo.security.jaas.JaasLoginModuleUse;
49 import org.apache.geronimo.security.jaas.NamedUPCredentialLoginModule;
50 import org.apache.geronimo.security.realm.providers.FileAuditLoginModule;
51 import org.apache.geronimo.security.realm.providers.GeronimoPasswordCredentialLoginModule;
52 import org.apache.geronimo.security.realm.providers.RepeatedFailureLockoutLoginModule;
53 import org.apache.geronimo.security.realm.SecurityRealm;
54 import org.apache.geronimo.xbeans.geronimo.loginconfig.GerControlFlagType;
55 import org.apache.geronimo.xbeans.geronimo.loginconfig.GerLoginConfigDocument;
56 import org.apache.geronimo.xbeans.geronimo.loginconfig.GerLoginConfigType;
57 import org.apache.geronimo.xbeans.geronimo.loginconfig.GerLoginModuleType;
58 import org.apache.geronimo.xbeans.geronimo.loginconfig.GerOptionType;
59 import org.apache.geronimo.gbean.AbstractName;
60 import org.apache.xmlbeans.XmlCursor;
61 import org.apache.xmlbeans.XmlObject;
62 import org.apache.xmlbeans.XmlOptions;
63
64 import javax.enterprise.deploy.spi.DeploymentManager JavaDoc;
65 import javax.enterprise.deploy.spi.Target JavaDoc;
66 import javax.enterprise.deploy.spi.TargetModuleID JavaDoc;
67 import javax.enterprise.deploy.spi.status.ProgressObject JavaDoc;
68 import javax.portlet.ActionRequest;
69 import javax.portlet.ActionResponse;
70 import javax.portlet.PortletConfig;
71 import javax.portlet.PortletException;
72 import javax.portlet.PortletRequest;
73 import javax.portlet.PortletRequestDispatcher;
74 import javax.portlet.PortletSession;
75 import javax.portlet.RenderRequest;
76 import javax.portlet.RenderResponse;
77 import javax.portlet.WindowState;
78 import javax.security.auth.Subject JavaDoc;
79 import javax.security.auth.spi.LoginModule JavaDoc;
80 import javax.management.ObjectName JavaDoc;
81 import javax.management.MalformedObjectNameException JavaDoc;
82 import javax.xml.namespace.QName JavaDoc;
83
84 import java.io.BufferedReader JavaDoc;
85 import java.io.File JavaDoc;
86 import java.io.FileWriter JavaDoc;
87 import java.io.IOException JavaDoc;
88 import java.io.PrintWriter JavaDoc;
89 import java.io.Serializable JavaDoc;
90 import java.io.StringReader JavaDoc;
91 import java.io.StringWriter JavaDoc;
92 import java.io.Writer JavaDoc;
93 import java.net.MalformedURLException JavaDoc;
94 import java.net.URL JavaDoc;
95 import java.net.URLClassLoader JavaDoc;
96 import java.net.URI JavaDoc;
97 import java.util.ArrayList JavaDoc;
98 import java.util.Arrays JavaDoc;
99 import java.util.Collections JavaDoc;
100 import java.util.HashMap JavaDoc;
101 import java.util.Iterator JavaDoc;
102 import java.util.LinkedHashMap JavaDoc;
103 import java.util.List JavaDoc;
104 import java.util.Map JavaDoc;
105 import java.util.Properties JavaDoc;
106 import java.util.Set JavaDoc;
107 import java.util.SortedSet JavaDoc;
108
109 /**
110  * A portlet that lists, creates, and edits security realms.
111  *
112  * @version $Rev: 486453 $ $Date: 2006-12-12 21:03:51 -0500 (Tue, 12 Dec 2006) $
113  */

114 public class SecurityRealmPortlet extends BasePortlet {
115     private final static Log log = LogFactory.getLog(SecurityRealmPortlet.class);
116     private final static String JavaDoc[] SKIP_ENTRIES_WITH = new String JavaDoc[]{"geronimo", "tomcat", "tranql", "commons", "directory", "activemq"};
117     private static final String JavaDoc LIST_VIEW = "/WEB-INF/view/realmwizard/list.jsp";
118     private static final String JavaDoc EDIT_VIEW = "/WEB-INF/view/realmwizard/edit.jsp";
119     private static final String JavaDoc SELECT_TYPE_VIEW = "/WEB-INF/view/realmwizard/selectType.jsp";
120     private static final String JavaDoc CONFIGURE_VIEW = "/WEB-INF/view/realmwizard/configure.jsp";
121     private static final String JavaDoc ADVANCED_VIEW = "/WEB-INF/view/realmwizard/advanced.jsp";
122     private static final String JavaDoc TEST_LOGIN_VIEW = "/WEB-INF/view/realmwizard/testLogin.jsp";
123     private static final String JavaDoc TEST_RESULTS_VIEW = "/WEB-INF/view/realmwizard/testResults.jsp";
124     private static final String JavaDoc SHOW_PLAN_VIEW = "/WEB-INF/view/realmwizard/showPlan.jsp";
125     private static final String JavaDoc USAGE_VIEW = "/WEB-INF/view/realmwizard/usage.jsp";
126     private static final String JavaDoc LIST_MODE = "list";
127     private static final String JavaDoc EDIT_MODE = "edit";
128     private static final String JavaDoc SELECT_TYPE_MODE = "type";
129     private static final String JavaDoc CONFIGURE_MODE = "configure";
130     private static final String JavaDoc ADVANCED_MODE = "advanced";
131     private static final String JavaDoc TEST_LOGIN_MODE = "test";
132     private static final String JavaDoc TEST_RESULTS_MODE = "results";
133     private static final String JavaDoc SHOW_PLAN_MODE = "plan";
134     private static final String JavaDoc EDIT_EXISTING_MODE = "editExisting";
135     private static final String JavaDoc USAGE_MODE = "usage";
136     private static final String JavaDoc SAVE_MODE = "save";
137     private static final String JavaDoc MODE_KEY = "mode";
138     private static final String JavaDoc CUSTOM_MODE = "custom";
139
140     private static Kernel kernel;
141
142     private PortletRequestDispatcher listView;
143     private PortletRequestDispatcher editView;
144     private PortletRequestDispatcher selectTypeView;
145     private PortletRequestDispatcher configureView;
146     private PortletRequestDispatcher advancedView;
147     private PortletRequestDispatcher testLoginView;
148     private PortletRequestDispatcher testResultsView;
149     private PortletRequestDispatcher planView;
150     private PortletRequestDispatcher usageView;
151     private static final QName JavaDoc GBEAN_QNAME = new QName JavaDoc(ServiceDocument.type.getDocumentElementName().getNamespaceURI(), "gbean");
152
153     public void init(PortletConfig portletConfig) throws PortletException {
154         super.init(portletConfig);
155         kernel = KernelRegistry.getSingleKernel();
156         listView = portletConfig.getPortletContext().getRequestDispatcher(LIST_VIEW);
157         editView = portletConfig.getPortletContext().getRequestDispatcher(EDIT_VIEW);
158         selectTypeView = portletConfig.getPortletContext().getRequestDispatcher(SELECT_TYPE_VIEW);
159         configureView = portletConfig.getPortletContext().getRequestDispatcher(CONFIGURE_VIEW);
160         advancedView = portletConfig.getPortletContext().getRequestDispatcher(ADVANCED_VIEW);
161         testLoginView = portletConfig.getPortletContext().getRequestDispatcher(TEST_LOGIN_VIEW);
162         testResultsView = portletConfig.getPortletContext().getRequestDispatcher(TEST_RESULTS_VIEW);
163         planView = portletConfig.getPortletContext().getRequestDispatcher(SHOW_PLAN_VIEW);
164         usageView = portletConfig.getPortletContext().getRequestDispatcher(USAGE_VIEW);
165     }
166
167     public void destroy() {
168         listView = null;
169         editView = null;
170         selectTypeView = null;
171         configureView = null;
172         advancedView = null;
173         testLoginView = null;
174         usageView = null;
175         planView = null;
176         super.destroy();
177     }
178
179     public void processAction(ActionRequest actionRequest,
180             ActionResponse actionResponse) throws PortletException, IOException JavaDoc {
181         String JavaDoc mode = actionRequest.getParameter(MODE_KEY);
182         RealmData data = new RealmData();
183         data.load(actionRequest);
184         if (mode.equals(SELECT_TYPE_MODE)) {
185             data.realmType = "Properties File Realm";
186             actionResponse.setRenderParameter(MODE_KEY, SELECT_TYPE_MODE);
187         } else if (mode.equals("process-" + SELECT_TYPE_MODE)) {
188             if (data.getName() != null && !data.getName().trim().equals("")) {
189                 // Config properties have to be set in render since they have values of null
190
if (data.getRealmType().equals("Other")) {
191                     actionResponse.setRenderParameter(MODE_KEY, CUSTOM_MODE);
192                 } else {
193                     actionResponse.setRenderParameter(MODE_KEY, CONFIGURE_MODE);
194                 }
195             } else {
196                 actionResponse.setRenderParameter(MODE_KEY, SELECT_TYPE_MODE);
197             }
198         } else if (mode.equals("process-" + CONFIGURE_MODE)) {
199             final String JavaDoc error = actionTestLoginModuleLoad(actionRequest, data);
200             if (error == null) {
201                 actionResponse.setRenderParameter(MODE_KEY, ADVANCED_MODE);
202             } else {
203                 actionResponse.setRenderParameter("LoginModuleError", error);
204                 actionResponse.setRenderParameter(MODE_KEY, CONFIGURE_MODE);
205             }
206         } else if (mode.equals("process-" + ADVANCED_MODE)) {
207             String JavaDoc test = actionRequest.getParameter("test");
208             if (test == null || test.equals("true")) {
209                 actionResponse.setRenderParameter(MODE_KEY, TEST_LOGIN_MODE);
210             } else {
211                 actionSaveRealm(actionRequest, data);
212                 actionResponse.setRenderParameter(MODE_KEY, LIST_MODE);
213             }
214         } else if (mode.equals("process-" + TEST_LOGIN_MODE)) {
215             actionAttemptLogin(data, actionRequest, actionRequest.getPortletSession(true), actionRequest.getParameter("username"), actionRequest.getParameter("password"));
216             actionResponse.setRenderParameter(MODE_KEY, TEST_RESULTS_MODE);
217         } else if (mode.equals(SHOW_PLAN_MODE)) {
218             XmlObject object = actionGeneratePlan(actionRequest, data);
219             savePlanToSession(actionRequest.getPortletSession(true), object);
220             actionResponse.setRenderParameter(MODE_KEY, SHOW_PLAN_MODE);
221         } else if (mode.equals(EDIT_EXISTING_MODE)) {
222             actionLoadExistingRealm(actionRequest, data);
223             actionResponse.setRenderParameter(MODE_KEY, EDIT_MODE);
224         } else if (mode.equals(CONFIGURE_MODE)) {
225             if (data.getAbstractName() != null) {
226                 actionResponse.setRenderParameter(MODE_KEY, EDIT_MODE);
227             } else if((data.getRealmType() != null && data.getRealmType().equals("Other"))) {
228                 actionResponse.setRenderParameter(MODE_KEY, CUSTOM_MODE);
229             } else {
230                 actionResponse.setRenderParameter(MODE_KEY, CONFIGURE_MODE);
231             }
232         } else if (mode.equals(SAVE_MODE)) {
233             actionSaveRealm(actionRequest, data);
234             actionResponse.setRenderParameter(MODE_KEY, LIST_MODE);
235         } else {
236             actionResponse.setRenderParameter(MODE_KEY, mode);
237         }
238         data.store(actionResponse);
239     }
240
241     protected void doView(RenderRequest renderRequest, RenderResponse renderResponse) throws IOException JavaDoc, PortletException {
242         if (WindowState.MINIMIZED.equals(renderRequest.getWindowState())) {
243             return;
244         }
245         try {
246             String JavaDoc mode = renderRequest.getParameter(MODE_KEY);
247             RealmData data = new RealmData();
248             data.load(renderRequest);
249             renderRequest.setAttribute("realm", data);
250             if (mode == null || mode.equals("")) {
251                 mode = LIST_MODE;
252             }
253             if (mode.equals(LIST_MODE)) {
254                 renderList(renderRequest, renderResponse);
255             } else if (mode.equals(EDIT_MODE) || mode.equals(CUSTOM_MODE)) {
256                 renderRequest.setAttribute("mode", mode);
257                 if(mode.equals(CUSTOM_MODE)) loadDriverJARList(renderRequest);
258                 renderEdit(renderRequest, renderResponse, data);
259             } else if (mode.equals(SELECT_TYPE_MODE)) {
260                 renderSelectType(renderRequest, renderResponse);
261             } else if (mode.equals(CONFIGURE_MODE)) {
262                 renderConfigure(renderRequest, renderResponse, data);
263             } else if (mode.equals(ADVANCED_MODE)) {
264                 renderAdvanced(renderRequest, renderResponse, data);
265             } else if (mode.equals(TEST_LOGIN_MODE)) {
266                 renderTestLoginForm(renderRequest, renderResponse);
267             } else if (mode.equals(TEST_RESULTS_MODE)) {
268                 renderTestResults(renderRequest, renderResponse);
269             } else if (mode.equals(SHOW_PLAN_MODE)) {
270                 renderPlan(renderRequest, renderResponse);
271             } else if (mode.equals(USAGE_MODE)) {
272                 renderUsage(renderRequest, renderResponse);
273             }
274         } catch (Throwable JavaDoc e) {
275             log.error("Unable to render portlet", e);
276         }
277     }
278
279     private String JavaDoc actionTestLoginModuleLoad(PortletRequest request, RealmData data) {
280         Map JavaDoc options = new HashMap JavaDoc();
281         try {
282             LoginModule module = loadModule(request, data, options);
283             log.warn("Testing with options " + options);
284             try {
285                 PortletManager.testLoginModule(request, module, options);
286                 return null;
287             } catch (Exception JavaDoc e) {
288                 log.warn("Unable to initialize LoginModule", e);
289                 return "Unable to initialize LoginModule: " + e.getMessage();
290             }
291         } catch (Exception JavaDoc e) {
292             log.warn("Unable to load LoginModule class", e);
293             return "Unable to load LoginModule class: " + e.getMessage();
294         }
295     }
296
297     private LoginModule loadModule(PortletRequest request, RealmData data, Map JavaDoc options) throws ClassNotFoundException JavaDoc, InstantiationException JavaDoc, IllegalAccessException JavaDoc {
298         ClassLoader JavaDoc loader = getClass().getClassLoader();
299         if (data.jar != null && !data.jar.equals("")) {
300             try {
301                 Artifact one = Artifact.create(data.getJar());
302                 ListableRepository[] repos = PortletManager.getCurrentServer(request).getRepositories();
303                 for (int i = 0; i < repos.length; i++) {
304                     ListableRepository repo = repos[i];
305                     File JavaDoc file = repo.getLocation(one);
306                     if (file != null) {
307                         loader = new URLClassLoader JavaDoc(new URL JavaDoc[]{file.toURL()}, loader);
308                         break;
309                     }
310                 }
311             } catch (MalformedURLException JavaDoc e) {
312                 log.warn("Repository unable to look up JAR file", e);
313             }
314         }
315         Class JavaDoc cls = loader.loadClass(getSelectedModule(data).getClassName());
316         LoginModule module = (LoginModule) cls.newInstance();
317         for (Iterator JavaDoc it = data.getOptions().keySet().iterator(); it.hasNext();) {
318             String JavaDoc key = (String JavaDoc) it.next();
319             final Object JavaDoc value = data.getOptions().get(key);
320             if (value != null && !value.equals("")) {
321                 options.put(key, value);
322             }
323         }
324         options.put(JaasLoginModuleUse.CLASSLOADER_LM_OPTION, loader);
325         return module;
326     }
327
328     private void actionAttemptLogin(RealmData data, PortletRequest request, PortletSession session, String JavaDoc username, String JavaDoc password) {
329         session.removeAttribute("TestLoginPrincipals");
330         session.removeAttribute("TestLoginError");
331         Map JavaDoc options = new HashMap JavaDoc();
332         try {
333             LoginModule module = loadModule(request, data, options);
334             Subject JavaDoc sub = PortletManager.testLoginModule(request, module, options, username, password);
335             session.setAttribute("TestLoginPrincipals", sub.getPrincipals());
336         } catch (Exception JavaDoc e) {
337             log.warn("Test login failed", e);
338             session.setAttribute("TestLoginError", "Login Failed: " + (e.getMessage() == null ? "no message" : e.getMessage()));
339         }
340     }
341
342     private XmlObject actionGeneratePlan(PortletRequest request, RealmData data) {
343         normalize(data);
344         ModuleDocument doc = ModuleDocument.Factory.newInstance();
345         ModuleType root = doc.addNewModule();
346         EnvironmentType environment = root.addNewEnvironment();
347         ArtifactType configId = environment.addNewModuleId();
348         configId.setGroupId("console.realm");
349         String JavaDoc artifactId = data.getName();
350         if(artifactId.indexOf('/') != -1) {
351             // slash in artifact-id results in invalid configuration-id and leads to deployment errors.
352
// Note: 0x002F = '/'
353
artifactId = artifactId.replaceAll("/", "%2F");
354         }
355         configId.setArtifactId(artifactId);
356         configId.setVersion("1.0");
357         configId.setType("car");
358
359         // Parent
360

361         DependenciesType dependenciesType = environment.addNewDependencies();
362         ArtifactType parent = dependenciesType.addNewDependency();
363         parent.setGroupId("org.apache.geronimo.configs");
364         parent.setArtifactId("j2ee-security");
365         parent.setType("car");
366         // Dependencies
367
if (data.getJar() != null) {
368             ArtifactType artifactType = dependenciesType.addNewDependency();
369             Artifact artifact = Artifact.create(data.getJar());
370             artifactType.setGroupId(artifact.getGroupId());
371             artifactType.setArtifactId(artifact.getArtifactId());
372             artifactType.setVersion(artifact.getVersion().toString());
373             artifactType.setType(artifact.getType());
374         }
375         // Build the realm GBean
376
GbeanType realm = GbeanType.Factory.newInstance();
377         realm.setName(data.getName());
378         realm.setClass1("org.apache.geronimo.security.realm.GenericSecurityRealm");
379         AttributeType realmName = realm.addNewAttribute();
380         realmName.setName("realmName");
381         realmName.setStringValue(data.getName());
382         ReferenceType serverInfo = realm.addNewReference();
383         serverInfo.setName2("ServerInfo");
384         serverInfo.setName((String JavaDoc) PortletManager.getNameFor(request, PortletManager.getCurrentServer(request).getServerInfo()).getName().get("name"));
385         ReferenceType loginService = realm.addNewReference();
386         loginService.setName2("LoginService");
387         loginService.setName((String JavaDoc) PortletManager.getNameFor(request, PortletManager.getCurrentServer(request).getLoginService()).getName().get("name"));
388         XmlAttributeType config = realm.addNewXmlReference();
389         // Construct the content to put in the XmlAttributeType
390
GerLoginConfigDocument lcDoc = GerLoginConfigDocument.Factory.newInstance();
391         GerLoginConfigType login = lcDoc.addNewLoginConfig();
392         for (int i = 0; i < data.getModules().length; i++) {
393             LoginModuleDetails details = data.getModules()[i];
394             if (details.getLoginDomainName() == null || details.getLoginDomainName().equals("")) {
395                 continue;
396             }
397             GerLoginModuleType module = login.addNewLoginModule();
398             module.setControlFlag(details.getControlFlag().equals("OPTIONAL") ? GerControlFlagType.OPTIONAL :
399                     details.getControlFlag().equals("REQUIRED") ? GerControlFlagType.REQUIRED :
400                             details.getControlFlag().equals("REQUISITE") ? GerControlFlagType.REQUISITE :
401                                     details.getControlFlag().equals("SUFFICIENT") ? GerControlFlagType.SUFFICIENT :
402                                             GerControlFlagType.OPTIONAL);
403             module.setServerSide(details.isServerSide());
404             module.setLoginDomainName(details.getLoginDomainName());
405             module.setLoginModuleClass(details.getClassName());
406             module.setWrapPrincipals(details.isWrapPrincipals());
407             for (Iterator JavaDoc it = details.getOptions().entrySet().iterator(); it.hasNext();) {
408                 Map.Entry JavaDoc entry = (Map.Entry JavaDoc) it.next();
409                 GerOptionType option = module.addNewOption();
410                 option.setName((String JavaDoc) entry.getKey());
411                 option.setStringValue((String JavaDoc) entry.getValue());
412             }
413
414             // bit of a hack -- to put the DataSource module in as a parent for SQL modules
415
if (details.getClassName().indexOf("SQL") > -1) {
416                 String JavaDoc poolName = (String JavaDoc) details.getOptions().get("dataSourceName");
417                 String JavaDoc appName = (String JavaDoc) details.getOptions().get("dataSourceApplication");
418                 if (poolName != null) {
419                     if (appName == null) appName = "null";
420                     JCAManagedConnectionFactory[] factories = PortletManager.getOutboundFactoriesOfType(request, "javax.sql.DataSource");
421                     for (int j = 0; j < factories.length; j++) {
422                         JCAManagedConnectionFactory factory = factories[j];
423                         try {
424                             ObjectName JavaDoc objectName = ObjectName.getInstance(factory.getObjectName());
425                             final String JavaDoc testName = objectName.getKeyProperty(NameFactory.J2EE_NAME);
426                             final String JavaDoc testApp = objectName.getKeyProperty(NameFactory.J2EE_APPLICATION);
427                             if (testName.equals(poolName) && testApp.equals(appName)) {
428                                 String JavaDoc moduleName = objectName.getKeyProperty(NameFactory.JCA_RESOURCE);
429
430                                 ArtifactType artifactType = dependenciesType.addNewDependency();
431                                 Artifact artifact = Artifact.create(moduleName);
432                                 artifactType.setGroupId(artifact.getGroupId());
433                                 artifactType.setArtifactId(artifact.getArtifactId());
434                                 artifactType.setVersion(artifact.getVersion().toString());
435                                 artifactType.setType(artifact.getType());
436                                 break;
437                             }
438                         } catch (MalformedObjectNameException JavaDoc e) {
439                             log.error("Unable to parse ObjectName", e);
440                         }
441                     }
442                 }
443             }
444         }
445         // Copy the content into the XmlAttributeType
446
XmlCursor loginCursor = lcDoc.newCursor();
447         loginCursor.toFirstContentToken();
448         XmlCursor destination = config.newCursor();
449         destination.toNextToken();
450         loginCursor.moveXml(destination);
451         loginCursor.dispose();
452         destination.dispose();
453         config.setName("LoginModuleConfiguration");
454         root.setServiceArray(new AbstractServiceType[]{realm});
455
456
457         //Above code inserts gbean using xsi:type=dep:GBeanType. We also need to account for the substitution group
458
//by changing the qname:
459
XmlCursor gbeanCursor = root.newCursor();
460         try {
461             if (!gbeanCursor.toChild(ServiceDocument.type.getDocumentElementName())) {
462                 throw new RuntimeException JavaDoc("Could not find service element");
463             }
464             gbeanCursor.setName(GBEAN_QNAME);
465         } finally {
466             gbeanCursor.dispose();
467         }
468
469         return doc;
470     }
471
472     private void actionLoadExistingRealm(PortletRequest request, RealmData data) {
473         SecurityRealm realm = (SecurityRealm) PortletManager.getManagedBean(request, new AbstractName(URI.create(data.getAbstractName())));
474         data.name = realm.getRealmName();
475         List JavaDoc list = new ArrayList JavaDoc();
476         JaasLoginModuleChain node = realm.getLoginModuleChain();
477         while (node != null) {
478             LoginModuleDetails details = new LoginModuleDetails();
479             details.setControlFlag(node.getControlFlag());
480             LoginModuleSettings module = node.getLoginModule();
481             details.setLoginDomainName(module.getLoginDomainName());
482             details.setClassName(module.getLoginModuleClass());
483             details.setServerSide(module.isServerSide());
484             details.setWrapPrincipals(module.isWrapPrincipals());
485             details.setOptions(module.getOptions());
486             list.add(details);
487             node = node.getNext();
488             if (node == null) {
489                 break;
490             }
491         }
492         data.modules = (LoginModuleDetails[]) list.toArray(new LoginModuleDetails[list.size()]);
493     }
494
495     private void actionSaveRealm(PortletRequest request, RealmData data) {
496         normalize(data);
497         if (data.getAbstractName() == null || data.getAbstractName().equals("")) { // we're creating a new realm
498
try {
499                 XmlObject plan = actionGeneratePlan(request, data);
500                 data.name = data.name.replaceAll("\\s", "");
501                 DeploymentManager JavaDoc mgr = PortletManager.getDeploymentManager(request);
502                 File JavaDoc tempFile = File.createTempFile("console-deployment", ".xml");
503                 tempFile.deleteOnExit();
504                 log.debug("Writing security realm deployment plan to " + tempFile.getAbsolutePath());
505                 PrintWriter JavaDoc out = new PrintWriter JavaDoc(new FileWriter JavaDoc(tempFile));
506                 savePlanToStream(plan, out);
507                 out.flush();
508                 out.close();
509                 Target JavaDoc[] targets = mgr.getTargets();
510                 ProgressObject JavaDoc po = mgr.distribute(targets, null, tempFile);
511                 waitForProgress(po);
512                 if (po.getDeploymentStatus().isCompleted()) {
513                     TargetModuleID JavaDoc[] ids = po.getResultTargetModuleIDs();
514                     po = mgr.start(ids);
515                     waitForProgress(po);
516                     if (po.getDeploymentStatus().isCompleted()) {
517                         log.info("Deployment completed successfully!");
518                     }
519                 }
520             } catch (IOException JavaDoc e) {
521                 log.error("Unable to save security realm", e);
522             }
523         } else {
524             SecurityRealm realm = (SecurityRealm) PortletManager.getManagedBean(request, new AbstractName(URI.create(data.getAbstractName())));
525             // index existing modules
526
Map JavaDoc nodes = new HashMap JavaDoc();
527             JaasLoginModuleChain node = realm.getLoginModuleChain();
528             while (node != null) {
529                 LoginModuleSettings module = node.getLoginModule();
530                 nodes.put(module.getLoginDomainName(), node);
531                 node = node.getNext();
532                 if (node == null) {
533                     break;
534                 }
535             }
536             // apply settings
537
for (int i = 0; i < data.getModules().length; i++) {
538                 LoginModuleDetails details = data.getModules()[i];
539                 node = (JaasLoginModuleChain) nodes.get(details.getLoginDomainName());
540                 node.setControlFlag(details.getControlFlag());
541                 LoginModuleSettings module = node.getLoginModule();
542                 module.setOptions(details.getOptions());
543                 module.setServerSide(details.isServerSide());
544                 module.setWrapPrincipals(details.isWrapPrincipals());
545                 module.setLoginModuleClass(details.getClassName());
546             }
547         }
548     }
549
550     private void renderList(RenderRequest request, RenderResponse response) throws IOException JavaDoc, PortletException {
551         // Unfortunately there are two classes named SecurityRealm; one extends the other
552
// The array type is management.geronimo.SecurityRealm (the superclass)
553
// The array entry types are security.realm.SecurityRealm (the subclass)
554
org.apache.geronimo.management.geronimo.SecurityRealm[] realms = PortletManager.getCurrentServer(request).getSecurityRealms();
555         ExistingRealm[] results = new ExistingRealm[realms.length];
556
557         // ConfigurationManager is used to determine if the SecurityRealm is deployed as a "SERVICE", i.e., "Server-wide"
558
ConfigurationManager configMgr = null;
559         if(results.length > 0) {
560             // Needed only when there are any SecurityRealms
561
configMgr = ConfigurationUtil.getConfigurationManager(kernel);
562         }
563         for (int i = 0; i < results.length; i++) {
564             final GeronimoManagedBean managedBean = (GeronimoManagedBean) realms[i];
565             AbstractName abstractName = PortletManager.getNameFor(request, realms[i]);
566             String JavaDoc parent;
567             Configuration parentConfig = configMgr.getConfiguration(abstractName.getArtifact());
568             ConfigurationModuleType parentType = parentConfig.getModuleType();
569             if(ConfigurationModuleType.SERVICE.equals(parentType)) {
570                 parent = null; // Server-wide
571
} else {
572                 parent = abstractName.getArtifact().toString();
573             }
574             results[i] = new ExistingRealm(realms[i].getRealmName(), abstractName, managedBean.getState(), parent);
575         }
576         // Once done, release the ConfigurationManager
577
if(configMgr != null) {
578             ConfigurationUtil.releaseConfigurationManager(kernel, configMgr);
579         }
580         request.setAttribute("realms", results);
581         listView.include(request, response);
582     }
583
584     private void renderEdit(RenderRequest request, RenderResponse response, RealmData data) throws IOException JavaDoc, PortletException {
585         normalize(data);
586         editView.include(request, response);
587     }
588
589     private void renderSelectType(RenderRequest request, RenderResponse response) throws IOException JavaDoc, PortletException {
590         request.setAttribute("moduleTypes", MasterLoginModuleInfo.getAllModules());
591         selectTypeView.include(request, response);
592     }
593
594     private void renderConfigure(RenderRequest request, RenderResponse response, RealmData data) throws IOException JavaDoc, PortletException {
595         // Pass errors through
596
if (request.getParameter("LoginModuleError") != null) {
597             request.setAttribute("LoginModuleError", request.getParameter("LoginModuleError"));
598         }
599         // Clear out any cached modules
600
data.modules = null;
601         // Configure option list
602
MasterLoginModuleInfo info = getSelectedModule(data);
603         for (int i = 0; i < info.getOptions().length; i++) {
604             MasterLoginModuleInfo.OptionInfo option = info.getOptions()[i];
605             if (!data.getOptions().containsKey(option.getName())) {
606                 data.getOptions().put(option.getName(), null);
607             }
608         }
609         data.reorderOptions(info.getOptions());
610         request.setAttribute("optionMap", info.getOptionMap());
611         if (info.getName().indexOf("SQL") > -1) {
612             loadDriverJARList(request);
613             loadDatabasePoolList(request);
614         }
615         configureView.include(request, response);
616     }
617
618     private void renderAdvanced(RenderRequest request, RenderResponse response, RealmData data) throws IOException JavaDoc, PortletException {
619         // Clear out any cached modules
620
data.modules = null;
621         // Show the page
622
advancedView.include(request, response);
623     }
624
625     private void renderTestLoginForm(RenderRequest request, RenderResponse response) throws IOException JavaDoc, PortletException {
626         testLoginView.include(request, response);
627     }
628
629     private void renderTestResults(RenderRequest request, RenderResponse response) throws IOException JavaDoc, PortletException {
630         PortletSession session = request.getPortletSession();
631         String JavaDoc status = (String JavaDoc) session.getAttribute("TestLoginError");
632         if (status == null) {
633             Set JavaDoc principals = (Set JavaDoc) session.getAttribute("TestLoginPrincipals");
634             status = "Login succeeded with " + (principals == null ? 0 : principals.size()) + " principals";
635             request.setAttribute("principals", principals);
636         }
637         request.setAttribute("LoginResults", status);
638         testResultsView.include(request, response);
639     }
640
641     private void renderPlan(RenderRequest request, RenderResponse response) throws IOException JavaDoc, PortletException {
642         String JavaDoc plan = (String JavaDoc) request.getPortletSession().getAttribute("SecurityRealmPlan");
643         request.setAttribute("deploymentPlan", plan);
644         planView.include(request, response);
645     }
646
647     private void renderUsage(RenderRequest request, RenderResponse response) throws IOException JavaDoc, PortletException {
648         usageView.include(request, response);
649     }
650
651     private static MasterLoginModuleInfo getSelectedModule(RealmData data) {
652         MasterLoginModuleInfo[] all = MasterLoginModuleInfo.getAllModules();
653         for (int i = 0; i < all.length; i++) {
654             MasterLoginModuleInfo info = all[i];
655             if (info.getName().equals(data.getRealmType())) {
656                 return info;
657             }
658         }
659         return null;
660     }
661
662     private void loadDatabasePoolList(RenderRequest renderRequest) {
663         JCAManagedConnectionFactory[] factories = PortletManager.getOutboundFactoriesOfType(renderRequest, "javax.sql.DataSource");
664         List JavaDoc pools = new ArrayList JavaDoc();
665         try {
666             for (int i = 0; i < factories.length; i++) {
667                 JCAManagedConnectionFactory factory = factories[i];
668                 ObjectName JavaDoc objectName = ObjectName.getInstance(factory.getObjectName());
669                 final String JavaDoc name = objectName.getKeyProperty(NameFactory.J2EE_NAME);
670                 String JavaDoc display = name;
671                 final String JavaDoc appName = objectName.getKeyProperty(NameFactory.J2EE_APPLICATION);
672                 if (appName != null && !appName.equals("null")) {
673                     display = display + " (" + appName + ")";
674                 }
675                 pools.add(new DatabasePool(name, display, appName, PortletManager.getNameFor(renderRequest, factory)));
676             }
677             renderRequest.setAttribute("pools", pools);
678         } catch (MalformedObjectNameException JavaDoc e) {
679             log.error("Unable to parse ObjectName", e);
680         }
681     }
682
683     private void loadDriverJARList(RenderRequest renderRequest) {
684         // List the available JARs
685
List JavaDoc list = new ArrayList JavaDoc();
686         ListableRepository[] repos = PortletManager.getCurrentServer(renderRequest).getRepositories();
687         for (int i = 0; i < repos.length; i++) {
688             ListableRepository repo = repos[i];
689
690             SortedSet JavaDoc artifacts = repo.list();
691             outer:
692             for (Iterator JavaDoc iterator = artifacts.iterator(); iterator.hasNext();) {
693                 Artifact artifact = (Artifact) iterator.next();
694                 String JavaDoc test = artifact.toString();
695                 // todo should only test groupId and should check for long (org.apache.geronimo) and short form
696
for (int k = 0; k < SKIP_ENTRIES_WITH.length; k++) {
697                     String JavaDoc skip = SKIP_ENTRIES_WITH[k];
698                     if (test.indexOf(skip) > -1) {
699                         continue outer;
700                     }
701                 }
702                 list.add(test);
703             }
704         }
705         Collections.sort(list);
706         renderRequest.setAttribute("jars", list);
707     }
708
709     private void savePlanToSession(PortletSession session, XmlObject object) {
710         StringWriter JavaDoc out = new StringWriter JavaDoc();
711         try {
712             savePlanToStream(object, out);
713             session.setAttribute("SecurityRealmPlan", out.getBuffer().toString());
714         } catch (IOException JavaDoc e) {
715             log.error("Unable to write deployment plan", e);
716         }
717     }
718
719     private void savePlanToStream(XmlObject object, Writer JavaDoc out) throws IOException JavaDoc {
720         XmlOptions options = new XmlOptions();
721         options.setSavePrettyPrint();
722         options.setSavePrettyPrintIndent(4);
723         options.setUseDefaultNamespace();
724         object.save(out, options);
725         out.close();
726     }
727
728     private static void waitForProgress(ProgressObject JavaDoc po) {
729         while (po.getDeploymentStatus().isRunning()) {
730             try {
731                 Thread.sleep(100);
732             } catch (InterruptedException JavaDoc e) {
733                 log.error(e.getMessage(), e);
734             }
735         }
736     }
737
738     public static void normalize(RealmData data) {
739         List JavaDoc list = new ArrayList JavaDoc();
740         if (data.modules == null) {
741             LoginModuleDetails module = new LoginModuleDetails();
742             module.setClassName(getSelectedModule(data).getClassName());
743             module.setControlFlag("REQUIRED");
744             module.setLoginDomainName(data.getName());
745             module.setServerSide(data.getRealmType().indexOf("erberos") < 0);
746             Properties JavaDoc props = module.getOptions();
747             for (Iterator JavaDoc it = data.getOptions().entrySet().iterator(); it.hasNext();) {
748                 Map.Entry JavaDoc entry = (Map.Entry JavaDoc) it.next();
749                 props.setProperty((String JavaDoc) entry.getKey(), (String JavaDoc) entry.getValue());
750             }
751             list.add(module);
752             if (data.isStorePassword()) {
753                 module = new LoginModuleDetails();
754                 module.setClassName(GeronimoPasswordCredentialLoginModule.class.getName());
755                 module.setControlFlag("OPTIONAL");
756                 module.setLoginDomainName(data.getName() + "-Password");
757                 module.setServerSide(true);
758                 list.add(module);
759             }
760             if (data.getAuditPath() != null) {
761                 module = new LoginModuleDetails();
762                 module.setClassName(FileAuditLoginModule.class.getName());
763                 module.setControlFlag("OPTIONAL");
764                 module.setLoginDomainName(data.getName() + "-Audit");
765                 module.setServerSide(true);
766                 props = module.getOptions();
767                 props.setProperty("file", data.getAuditPath());
768                 list.add(module);
769             }
770             if (data.isLockoutEnabled()) {
771                 module = new LoginModuleDetails();
772                 module.setClassName(RepeatedFailureLockoutLoginModule.class.getName());
773                 module.setControlFlag("REQUISITE");
774                 module.setLoginDomainName(data.getName() + "-Lockout");
775                 module.setServerSide(true);
776                 props = module.getOptions();
777                 props.setProperty("failureCount", data.getLockoutCount());
778                 props.setProperty("failurePeriodSecs", data.getLockoutWindow());
779                 props.setProperty("lockoutDurationSecs", data.getLockoutDuration());
780                 list.add(module);
781             }
782             if (data.getCredentialName() != null) {
783                 module = new LoginModuleDetails();
784                 module.setClassName(NamedUPCredentialLoginModule.class.getName());
785                 module.setControlFlag("OPTIONAL");
786                 module.setLoginDomainName(data.getName() + "-NamedUPC");
787                 module.setServerSide(true);
788                 props = module.getOptions();
789                 props.setProperty(NamedUPCredentialLoginModule.CREDENTIAL_NAME, data.getCredentialName());
790                 list.add(module);
791             }
792         } else {
793             list.addAll(Arrays.asList(data.modules));
794         }
795         if (data.getAbstractName() == null) {
796             for (int i = list.size(); i < 5; i++) {
797                 LoginModuleDetails module = new LoginModuleDetails();
798                 list.add(module);
799             }
800         }
801         data.modules = (LoginModuleDetails[]) list.toArray(new LoginModuleDetails[list.size()]);
802     }
803
804     public static class RealmData implements Serializable JavaDoc {
805         private String JavaDoc name;
806         private String JavaDoc realmType;
807         private String JavaDoc jar;
808         private Map JavaDoc options = new LinkedHashMap JavaDoc();
809         private String JavaDoc auditPath;
810         private String JavaDoc lockoutCount;
811         private String JavaDoc lockoutWindow;
812         private String JavaDoc lockoutDuration;
813         private boolean storePassword;
814         private String JavaDoc abstractName; // used when editing existing realms
815
private LoginModuleDetails[] modules;
816         private String JavaDoc credentialName;
817
818         public void load(PortletRequest request) {
819             name = request.getParameter("name");
820             if (name != null && name.equals("")) name = null;
821             realmType = request.getParameter("realmType");
822             if (realmType != null && realmType.equals("")) realmType = null;
823             jar = request.getParameter("jar");
824             if (jar != null && jar.equals("")) jar = null;
825             auditPath = request.getParameter("auditPath");
826             if (auditPath != null && auditPath.equals("")) auditPath = null;
827             lockoutCount = request.getParameter("lockoutCount");
828             if (lockoutCount != null && lockoutCount.equals("")) lockoutCount = null;
829             lockoutWindow = request.getParameter("lockoutWindow");
830             if (lockoutWindow != null && lockoutWindow.equals("")) lockoutWindow = null;
831             lockoutDuration = request.getParameter("lockoutDuration");
832             if (lockoutDuration != null && lockoutDuration.equals("")) lockoutDuration = null;
833             abstractName = request.getParameter("abstractName");
834             if (abstractName != null && abstractName.equals("")) abstractName = null;
835             String JavaDoc test = request.getParameter("storePassword");
836             storePassword = test != null && !test.equals("") && !test.equals("false");
837             credentialName = request.getParameter("credentialName");
838             if (credentialName != null && credentialName.equals("")) credentialName = null;
839             Map JavaDoc map = request.getParameterMap();
840             for (Iterator JavaDoc it = map.keySet().iterator(); it.hasNext();) {
841                 String JavaDoc key = (String JavaDoc) it.next();
842                 if (key.startsWith("option-")) {
843                     if (key.equals("option-databasePoolAbstractName"))
844                     { // special handling for a data source, where there's one select corresponding to two properties
845
String JavaDoc nameString = request.getParameter(key);
846                         if (nameString != null && !nameString.equals("")) {
847                             AbstractName an = new AbstractName(URI.create(nameString));
848                             options.put("dataSourceName", an.getNameProperty(NameFactory.J2EE_NAME));
849                             options.put("dataSourceApplication", an.getNameProperty(NameFactory.J2EE_APPLICATION));
850                         }
851                     } else {
852                         final String JavaDoc optionName = key.substring(7);
853                         final String JavaDoc value = request.getParameter(key);
854                         if (value != null && !value.equals("")) {
855                             options.put(optionName, value);
856                         }
857                     }
858                 }
859             }
860             int count = 0;
861             List JavaDoc list = new ArrayList JavaDoc();
862             while (true) {
863                 int index = count;
864                 ++count;
865                 String JavaDoc name = request.getParameter("module-domain-" + index);
866                 if (name == null || name.equals("")) break;
867                 LoginModuleDetails details = new LoginModuleDetails();
868                 details.setLoginDomainName(name);
869                 String JavaDoc cls = request.getParameter("module-class-" + index);
870                 if (cls == null || cls.equals("")) continue;
871                 details.setClassName(cls);
872                 String JavaDoc flag = request.getParameter("module-control-" + index);
873                 if (flag == null || flag.equals("")) continue;
874                 details.setControlFlag(flag);
875                 String JavaDoc wrap = request.getParameter("module-wrap-" + index);
876                 if (wrap == null || wrap.equals("")) continue;
877                 details.setWrapPrincipals(Boolean.valueOf(wrap).booleanValue());
878                 String JavaDoc server = request.getParameter("module-server-" + index);
879                 if (server == null || server.equals("")) continue;
880                 details.setServerSide(Boolean.valueOf(server).booleanValue());
881                 String JavaDoc options = request.getParameter("module-options-" + index);
882                 if (options != null && !options.equals("")) {
883                     BufferedReader JavaDoc in = new BufferedReader JavaDoc(new StringReader JavaDoc(options));
884                     String JavaDoc line;
885                     try {
886                         while ((line = in.readLine()) != null) {
887                             if (line.startsWith("#") || line.equals("")) {
888                                 continue;
889                             }
890                             int pos = line.indexOf('=');
891                             if (pos > -1) {
892                                 details.getOptions().setProperty(line.substring(0, pos), line.substring(pos + 1));
893                             }
894                         }
895                     } catch (IOException JavaDoc e) {
896                         log.error("Unable to read properties '" + options + "'", e);
897                     }
898                 }
899                 list.add(details);
900             }
901             if (list.size() > 0) {
902                 modules = (LoginModuleDetails[]) list.toArray(new LoginModuleDetails[list.size()]);
903             }
904         }
905
906         public void reorderOptions(MasterLoginModuleInfo.OptionInfo[] info) {
907             if (info == null || info.length == 0) {
908                 return; // Probably SQL or something that handles this manually
909
}
910             Map JavaDoc map = new LinkedHashMap JavaDoc();
911             for (int i = 0; i < info.length; i++) {
912                 if (options.containsKey(info[i].getName())) {
913                     map.put(info[i].getName(), options.get(info[i].getName()));
914                 }
915             }
916             options = map;
917         }
918
919         public void store(ActionResponse response) {
920             if (name != null) response.setRenderParameter("name", name);
921             if (realmType != null) response.setRenderParameter("realmType", realmType);
922             if (jar != null) response.setRenderParameter("jar", jar);
923             if (auditPath != null) response.setRenderParameter("auditPath", auditPath);
924             if (lockoutCount != null) response.setRenderParameter("lockoutCount", lockoutCount);
925             if (lockoutWindow != null) response.setRenderParameter("lockoutWindow", lockoutWindow);
926             if (lockoutDuration != null) response.setRenderParameter("lockoutDuration", lockoutDuration);
927             if (abstractName != null) response.setRenderParameter("abstractName", abstractName);
928             if (storePassword) response.setRenderParameter("storePassword", "true");
929             if (credentialName != null) response.setRenderParameter("credentialName", credentialName);
930             for (Iterator JavaDoc it = options.keySet().iterator(); it.hasNext();) {
931                 String JavaDoc name = (String JavaDoc) it.next();
932                 String JavaDoc value = (String JavaDoc) options.get(name);
933                 if (value != null) {
934                     response.setRenderParameter("option-" + name, value);
935                 }
936             }
937             if (modules != null) {
938                 for (int i = 0; i < modules.length; i++) {
939                     LoginModuleDetails module = modules[i];
940                     if (module.getLoginDomainName() != null)
941                         response.setRenderParameter("module-domain-" + i, module.getLoginDomainName());
942                     if (module.getClassName() != null)
943                         response.setRenderParameter("module-class-" + i, module.getClassName());
944                     if (module.getControlFlag() != null)
945                         response.setRenderParameter("module-control-" + i, module.getControlFlag());
946                     response.setRenderParameter("module-wrap-" + i, Boolean.toString(module.isWrapPrincipals()));
947                     response.setRenderParameter("module-server-" + i, Boolean.toString(module.isServerSide()));
948                     if (module.getOptions().size() > 0)
949                         response.setRenderParameter("module-options-" + i, module.getOptionString());
950                 }
951             }
952         }
953
954         public String JavaDoc getName() {
955             return name;
956         }
957
958         public String JavaDoc getRealmType() {
959             return realmType;
960         }
961
962         public Map JavaDoc getOptions() {
963             return options;
964         }
965
966         public Set JavaDoc getOptionNames() {
967             return options.keySet();
968         }
969
970         public String JavaDoc getJar() {
971             return jar;
972         }
973
974         public String JavaDoc getAuditPath() {
975             return auditPath;
976         }
977
978         public String JavaDoc getLockoutCount() {
979             return lockoutCount;
980         }
981
982         public String JavaDoc getLockoutWindow() {
983             return lockoutWindow;
984         }
985
986         public String JavaDoc getLockoutDuration() {
987             return lockoutDuration;
988         }
989
990         public boolean isStorePassword() {
991             return storePassword;
992         }
993
994         public boolean isLockoutEnabled() {
995             return lockoutCount != null || lockoutWindow != null || lockoutDuration != null;
996         }
997
998         public String JavaDoc getCredentialName() {
999             return credentialName;
1000        }
1001
1002        public String JavaDoc getAbstractName() {
1003            return abstractName;
1004        }
1005
1006        public boolean isTestable() {
1007            return getSelectedModule(this).isTestable();
1008        }
1009
1010        public LoginModuleDetails[] getModules() {
1011            return modules;
1012        }
1013    }
1014
1015    public static class LoginModuleDetails implements Serializable JavaDoc {
1016        private String JavaDoc loginDomainName;
1017        private String JavaDoc className;
1018        private String JavaDoc controlFlag;
1019        private boolean serverSide = true;
1020        private boolean wrapPrincipals = false;
1021        private Properties JavaDoc options = new Properties JavaDoc();
1022
1023        public String JavaDoc getLoginDomainName() {
1024            return loginDomainName;
1025        }
1026
1027        public void setLoginDomainName(String JavaDoc loginDomainName) {
1028            this.loginDomainName = loginDomainName;
1029        }
1030
1031        public String JavaDoc getClassName() {
1032            return className;
1033        }
1034
1035        public void setClassName(String JavaDoc className) {
1036            this.className = className;
1037        }
1038
1039        public String JavaDoc getControlFlag() {
1040            return controlFlag;
1041        }
1042
1043        public void setControlFlag(String JavaDoc controlFlag) {
1044            this.controlFlag = controlFlag;
1045        }
1046
1047        public boolean isServerSide() {
1048            return serverSide;
1049        }
1050
1051        public void setServerSide(boolean serverSide) {
1052            this.serverSide = serverSide;
1053        }
1054
1055        public Properties JavaDoc getOptions() {
1056            return options;
1057        }
1058
1059        public void setOptions(Properties JavaDoc options) {
1060            this.options = options;
1061        }
1062
1063        public boolean isWrapPrincipals() {
1064            return wrapPrincipals;
1065        }
1066
1067        public void setWrapPrincipals(boolean wrapPrincipals) {
1068            this.wrapPrincipals = wrapPrincipals;
1069        }
1070
1071        public String JavaDoc getOptionString() {
1072            StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
1073            for (Iterator JavaDoc it = options.keySet().iterator(); it.hasNext();) {
1074                String JavaDoc key = (String JavaDoc) it.next();
1075                buf.append(key).append("=").append(options.getProperty(key)).append("\n");
1076            }
1077            return buf.toString();
1078        }
1079    }
1080
1081    public static class ExistingRealm implements Serializable JavaDoc {
1082        private final String JavaDoc name;
1083        private final String JavaDoc abstractName;
1084        private final String JavaDoc parentName;
1085        private final int state;
1086
1087        public ExistingRealm(String JavaDoc name, AbstractName abstractName, int state, String JavaDoc parent) {
1088            this.name = name;
1089            this.abstractName = abstractName.toString();
1090            parentName = parent;
1091            this.state = state;
1092
1093        }
1094
1095        public String JavaDoc getName() {
1096            return name;
1097        }
1098
1099        public String JavaDoc getAbstractName() {
1100            return abstractName;
1101        }
1102
1103        public String JavaDoc getParentName() {
1104            return parentName;
1105        }
1106
1107        public int getState() {
1108            return state;
1109        }
1110
1111        public String JavaDoc getStateName() {
1112            return State.toString(state);
1113        }
1114    }
1115
1116    public static class DatabasePool implements Serializable JavaDoc, Comparable JavaDoc {
1117        private final String JavaDoc name;
1118        private final String JavaDoc displayName;
1119        private final String JavaDoc applicationName;
1120        private final String JavaDoc abstractName;
1121
1122        public DatabasePool(String JavaDoc name, String JavaDoc displayName, String JavaDoc applicationName, AbstractName abstractName) {
1123            this.name = name;
1124            this.displayName = displayName;
1125            this.applicationName = applicationName;
1126            this.abstractName = abstractName.toString();
1127        }
1128
1129        public String JavaDoc getName() {
1130            return name;
1131        }
1132
1133        public String JavaDoc getApplicationName() {
1134            return applicationName;
1135        }
1136
1137        public String JavaDoc getAbstractName() {
1138            return abstractName;
1139        }
1140
1141        public String JavaDoc getDisplayName() {
1142            return displayName;
1143        }
1144
1145        public int compareTo(Object JavaDoc o) {
1146            final DatabasePool pool = (DatabasePool) o;
1147            int names = name.compareTo(pool.name);
1148            if (applicationName == null) {
1149                if (pool.applicationName == null) {
1150                    return names;
1151                } else {
1152                    return -1;
1153                }
1154            } else {
1155                if (pool.applicationName == null) {
1156                    return 1;
1157                } else {
1158                    int test = applicationName.compareTo(pool.applicationName);
1159                    if (test != 0) {
1160                        return test;
1161                    } else {
1162                        return names;
1163                    }
1164                }
1165            }
1166        }
1167    }
1168}
Popular Tags