KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > connector > outbound > security > PasswordCredentialRealm


1 /**
2  *
3  * Copyright 2003-2004 The Apache Software Foundation
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * 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
18 package org.apache.geronimo.connector.outbound.security;
19
20 import javax.resource.spi.ManagedConnectionFactory JavaDoc;
21 import java.util.HashMap JavaDoc;
22 import java.util.Map JavaDoc;
23
24 import org.apache.geronimo.gbean.GBeanInfo;
25 import org.apache.geronimo.gbean.GBeanInfoBuilder;
26 import org.apache.geronimo.kernel.Kernel;
27 import org.apache.geronimo.security.jaas.ConfigurationEntryFactory;
28 import org.apache.geronimo.security.jaas.JaasLoginCoordinator;
29 import org.apache.geronimo.security.jaas.JaasLoginModuleConfiguration;
30 import org.apache.geronimo.security.jaas.LoginModuleControlFlag;
31 import org.apache.geronimo.security.realm.SecurityRealm;
32 import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
33
34
35 /**
36  * @version $Rev: 126313 $ $Date: 2005-01-24 13:03:52 -0800 (Mon, 24 Jan 2005) $
37  */

38 public class PasswordCredentialRealm implements SecurityRealm, ConfigurationEntryFactory, ManagedConnectionFactoryListener {
39
40     private static final GBeanInfo GBEAN_INFO;
41
42     ManagedConnectionFactory JavaDoc managedConnectionFactory;
43     private final Kernel kernel;
44     private final String JavaDoc realmName;
45
46     static final String JavaDoc REALM_INSTANCE = "org.apache.connector.outbound.security.PasswordCredentialRealm";
47
48     public PasswordCredentialRealm(Kernel kernel, String JavaDoc realmName) {
49         this.kernel = kernel;
50         this.realmName = realmName;
51     }
52
53     public String JavaDoc getRealmName() {
54         return realmName;
55     }
56
57     public boolean isRestrictPrincipalsToServer() {
58         return true;
59     }
60
61     public String JavaDoc[] getLoginDomains() {
62         return new String JavaDoc[]{realmName};
63     }
64
65     public JaasLoginModuleConfiguration[] getAppConfigurationEntries() {
66         Map JavaDoc options = new HashMap JavaDoc();
67
68         // TODO: This can be a bad thing, passing a reference to a realm to the login module
69
// since the SerializableACE can be sent remotely
70
options.put(REALM_INSTANCE, this);
71         JaasLoginModuleConfiguration config = new JaasLoginModuleConfiguration(PasswordCredentialLoginModule.class.getName(),
72                                                                                LoginModuleControlFlag.REQUISITE, options, true, getRealmName());
73         return new JaasLoginModuleConfiguration[]{config};
74     }
75
76     public void setManagedConnectionFactory(ManagedConnectionFactory JavaDoc managedConnectionFactory) {
77         this.managedConnectionFactory = managedConnectionFactory;
78     }
79
80     ManagedConnectionFactory JavaDoc getManagedConnectionFactory() {
81         return managedConnectionFactory;
82     }
83
84     public String JavaDoc getConfigurationName() {
85         return realmName;
86     }
87
88     public JaasLoginModuleConfiguration generateConfiguration() {
89         Map JavaDoc options = new HashMap JavaDoc();
90         options.put("realm", realmName);
91         options.put("kernel", kernel.getKernelName());
92
93         return new JaasLoginModuleConfiguration(JaasLoginCoordinator.class.getName(), LoginModuleControlFlag.REQUIRED, options, true, realmName);
94     }
95
96     static {
97         GBeanInfoBuilder infoFactory = new GBeanInfoBuilder(PasswordCredentialRealm.class, NameFactory.SECURITY_REALM);
98
99         infoFactory.addInterface(ManagedConnectionFactoryListener.class);
100         infoFactory.addInterface(ConfigurationEntryFactory.class);
101         infoFactory.addAttribute("kernel", Kernel.class, false);
102         infoFactory.addAttribute("realmName", String JavaDoc.class, true);
103
104         infoFactory.setConstructor(new String JavaDoc[]{"kernel", "realmName"});
105
106         GBEAN_INFO = infoFactory.getBeanInfo();
107     }
108
109     public static GBeanInfo getGBeanInfo() {
110         return GBEAN_INFO;
111     }
112 }
113
Popular Tags