KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > security > jaas > ServerRealmConfigurationEntry


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.security.jaas;
18
19 import java.util.Properties JavaDoc;
20
21 import org.apache.geronimo.gbean.GBeanInfo;
22 import org.apache.geronimo.gbean.GBeanInfoBuilder;
23 import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
24 import org.apache.geronimo.kernel.Kernel;
25 import org.apache.geronimo.security.jaas.server.JaasLoginServiceMBean;
26 import org.apache.geronimo.security.jaas.server.JaasLoginModuleConfiguration;
27 import org.apache.geronimo.security.jaas.client.JaasLoginCoordinator;
28
29
30 /**
31  * Creates a LoginModule configuration that will connect a server-side
32  * component to a security realm. The same thing could be done with a
33  * LoginModuleGBean and a DirectConfigurationEntry, but this method saves some
34  * configuration effort.
35  *
36  * @version $Rev: 476049 $ $Date: 2006-11-16 23:35:17 -0500 (Thu, 16 Nov 2006) $
37  */

38 public class ServerRealmConfigurationEntry implements ConfigurationEntryFactory {
39     private final String JavaDoc applicationConfigName;
40     private final String JavaDoc realmName;
41     private final Kernel kernel;
42     private final JaasLoginServiceMBean loginService;
43     private boolean wrapPrincipals;
44
45     public ServerRealmConfigurationEntry() {
46         this.applicationConfigName = null;
47         this.realmName = null;
48         this.kernel = null;
49         this.loginService = null;
50     }
51
52     public ServerRealmConfigurationEntry(String JavaDoc applicationConfigName, String JavaDoc realmName, Kernel kernel, JaasLoginServiceMBean loginService) {
53         this.applicationConfigName = applicationConfigName;
54         this.realmName = realmName;
55         if (applicationConfigName == null || realmName == null) {
56             throw new IllegalArgumentException JavaDoc("applicationConfigName and realmName are required");
57         }
58         if (applicationConfigName.equals(realmName)) {
59             throw new IllegalArgumentException JavaDoc("applicationConfigName must be different than realmName (there's an automatic entry using the same name as the realm name, so you don't need a ServerRealmConfigurationEntry if you're just going to use that!)");
60         }
61         this.kernel = kernel;
62         this.loginService = loginService;
63     }
64
65     public String JavaDoc getConfigurationName() {
66         return applicationConfigName;
67     }
68
69     public boolean isWrapPrincipals() {
70         return wrapPrincipals;
71     }
72
73     public void setWrapPrincipals(boolean wrapPrincipals) {
74         this.wrapPrincipals = wrapPrincipals;
75     }
76
77     public JaasLoginModuleConfiguration generateConfiguration() {
78         Properties JavaDoc options = new Properties JavaDoc();
79         options.put(JaasLoginCoordinator.OPTION_REALM, realmName);
80         options.put(JaasLoginCoordinator.OPTION_KERNEL, kernel.getKernelName());
81         if (loginService != null) {
82             options.put(JaasLoginCoordinator.OPTION_SERVICENAME, loginService.getObjectName());
83         }
84
85         options.put("realm", realmName);
86         options.put("kernel", kernel.getKernelName());
87
88         return new JaasLoginModuleConfiguration(JaasLoginCoordinator.class.getName(), LoginModuleControlFlag.REQUIRED, options, true, applicationConfigName, wrapPrincipals, JaasLoginCoordinator.class.getClassLoader());
89     }
90
91     public static final GBeanInfo GBEAN_INFO;
92
93     static {
94         GBeanInfoBuilder infoFactory = GBeanInfoBuilder.createStatic(ServerRealmConfigurationEntry.class, NameFactory.CONFIGURATION_ENTRY);
95         infoFactory.addInterface(ConfigurationEntryFactory.class);
96         infoFactory.addAttribute("applicationConfigName", String JavaDoc.class, true);
97         infoFactory.addAttribute("realmName", String JavaDoc.class, true);
98         infoFactory.addAttribute("kernel", Kernel.class, false);
99         infoFactory.addReference("LoginService", JaasLoginServiceMBean.class, "JaasLoginService");
100         infoFactory.addAttribute("wrapPrincipals", Boolean.TYPE, true);
101
102         infoFactory.setConstructor(new String JavaDoc[]{"applicationConfigName", "realmName", "kernel", "LoginService"});
103         GBEAN_INFO = infoFactory.getBeanInfo();
104     }
105
106     public static GBeanInfo getGBeanInfo() {
107         return GBEAN_INFO;
108     }
109
110 }
111
Popular Tags