1 17 package org.apache.geronimo.security.jaas; 18 19 import java.util.Properties ; 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 38 public class ServerRealmConfigurationEntry implements ConfigurationEntryFactory { 39 private final String applicationConfigName; 40 private final String 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 applicationConfigName, String realmName, Kernel kernel, JaasLoginServiceMBean loginService) { 53 this.applicationConfigName = applicationConfigName; 54 this.realmName = realmName; 55 if (applicationConfigName == null || realmName == null) { 56 throw new IllegalArgumentException ("applicationConfigName and realmName are required"); 57 } 58 if (applicationConfigName.equals(realmName)) { 59 throw new IllegalArgumentException ("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 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 options = new Properties (); 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 .class, true); 97 infoFactory.addAttribute("realmName", String .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 []{"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 |