1 17 package org.apache.geronimo.security.realm; 18 19 import java.util.ArrayList ; 20 import java.util.HashMap ; 21 import java.util.HashSet ; 22 import java.util.List ; 23 import java.util.Map ; 24 import java.util.Properties ; 25 import java.util.Set ; 26 27 import org.apache.geronimo.gbean.GBeanInfo; 28 import org.apache.geronimo.gbean.GBeanInfoBuilder; 29 import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory; 30 import org.apache.geronimo.kernel.Kernel; 31 import org.apache.geronimo.security.deploy.PrincipalInfo; 32 import org.apache.geronimo.security.jaas.ConfigurationEntryFactory; 33 import org.apache.geronimo.security.jaas.client.JaasLoginCoordinator; 34 import org.apache.geronimo.security.jaas.server.JaasLoginModuleConfiguration; 35 import org.apache.geronimo.security.jaas.JaasLoginModuleUse; 36 import org.apache.geronimo.security.jaas.LoginModuleControlFlag; 37 import org.apache.geronimo.security.jaas.JaasLoginModuleChain; 38 import org.apache.geronimo.security.jaas.server.JaasLoginServiceMBean; 39 import org.apache.geronimo.system.serverinfo.ServerInfo; 40 41 42 62 public class GenericSecurityRealm implements SecurityRealm, ConfigurationEntryFactory { 63 64 private final JaasLoginServiceMBean loginService; 65 private final String realmName; 66 private JaasLoginModuleConfiguration[] config; 67 private final Kernel kernel; 68 69 private final PrincipalInfo defaultPrincipalInfo; 70 71 private String [] domains; 72 private final boolean restrictPrincipalsToServer; 73 private final boolean wrapPrincipals; 74 private final JaasLoginModuleUse loginModuleUse; 75 76 public GenericSecurityRealm(String realmName, 77 JaasLoginModuleUse loginModuleUse, 78 boolean restrictPrincipalsToServer, 79 boolean wrapPrincipals, 80 PrincipalInfo defaultPrincipalInfo, 81 ServerInfo serverInfo, 82 ClassLoader classLoader, 83 Kernel kernel, 84 JaasLoginServiceMBean loginService) { 85 this.realmName = realmName; 86 this.kernel = kernel; 87 this.restrictPrincipalsToServer = restrictPrincipalsToServer; 88 this.wrapPrincipals = wrapPrincipals; 89 this.defaultPrincipalInfo = defaultPrincipalInfo; 90 this.loginService = loginService; 91 this.loginModuleUse = loginModuleUse; 92 93 Set domainNames = new HashSet (); 94 List loginModuleConfigurations = new ArrayList (); 95 96 if (loginModuleUse != null) { 97 loginModuleUse.configure(domainNames, loginModuleConfigurations, kernel, serverInfo, classLoader); 98 } 99 100 domains = (String []) domainNames.toArray(new String [domainNames.size()]); 101 config = (JaasLoginModuleConfiguration[]) loginModuleConfigurations.toArray(new JaasLoginModuleConfiguration[loginModuleConfigurations.size()]); 102 103 } 104 105 public String getRealmName() { 106 return realmName; 107 } 108 109 public JaasLoginModuleConfiguration[] getAppConfigurationEntries() { 110 return config; 111 } 112 113 public JaasLoginModuleChain getLoginModuleChain() { 114 return loginModuleUse; 115 } 116 117 123 public String [] getLoginDomains() { 124 return domains; 125 } 126 127 128 134 public PrincipalInfo getDefaultPrincipal() { 135 return defaultPrincipalInfo; 136 } 137 138 144 public boolean isRestrictPrincipalsToServer() { 145 return restrictPrincipalsToServer; 146 } 147 148 152 public boolean isWrapPrincipals() { 153 return wrapPrincipals; 154 } 155 156 public String getConfigurationName() { 157 return realmName; 158 } 159 160 public JaasLoginModuleConfiguration generateConfiguration() { 161 Map options = new HashMap (); 162 options.put(JaasLoginCoordinator.OPTION_REALM, realmName); 163 if (kernel != null) { 164 options.put(JaasLoginCoordinator.OPTION_KERNEL, kernel.getKernelName()); 165 if (loginService != null) { 166 options.put(JaasLoginCoordinator.OPTION_SERVICENAME, loginService.getObjectName()); 167 } 168 } else { 169 if (loginService != null) { 170 options.put(JaasLoginCoordinator.OPTION_SERVICE_INSTANCE, loginService); 172 } 173 } 174 175 return new JaasLoginModuleConfiguration(JaasLoginCoordinator.class.getName(), LoginModuleControlFlag.REQUIRED, options, true, realmName, wrapPrincipals, JaasLoginCoordinator.class.getClassLoader()); 176 } 177 178 public static final GBeanInfo GBEAN_INFO; 179 180 static { 181 GBeanInfoBuilder infoFactory = GBeanInfoBuilder.createStatic(GenericSecurityRealm.class, NameFactory.SECURITY_REALM); 182 183 infoFactory.addInterface(SecurityRealm.class); 184 infoFactory.addInterface(ConfigurationEntryFactory.class); 185 infoFactory.addAttribute("realmName", String .class, true); 186 infoFactory.addAttribute("kernel", Kernel.class, false); 187 infoFactory.addAttribute("classLoader", ClassLoader .class, false); 188 infoFactory.addAttribute("defaultPrincipal", PrincipalInfo.class, true); 189 infoFactory.addAttribute("deploymentSupport", Properties .class, true); 190 infoFactory.addAttribute("restrictPrincipalsToServer", boolean.class, true); 191 infoFactory.addAttribute("wrapPrincipals", boolean.class, true); 192 193 infoFactory.addReference("LoginModuleConfiguration", JaasLoginModuleUse.class, "LoginModuleUse"); 194 infoFactory.addReference("ServerInfo", ServerInfo.class, NameFactory.GERONIMO_SERVICE); 195 infoFactory.addReference("LoginService", JaasLoginServiceMBean.class, "JaasLoginService"); 196 197 infoFactory.addOperation("getAppConfigurationEntries", new Class [0]); 198 199 infoFactory.setConstructor(new String []{"realmName", 200 "LoginModuleConfiguration", 201 "restrictPrincipalsToServer", 202 "wrapPrincipals", 203 "defaultPrincipal", 204 "ServerInfo", 205 "classLoader", 206 "kernel", 207 "LoginService"}); 208 209 GBEAN_INFO = infoFactory.getBeanInfo(); 210 } 211 212 public static GBeanInfo getGBeanInfo() { 213 return GBEAN_INFO; 214 } 215 216 } 217 | Popular Tags |