1 17 18 package org.apache.geronimo.connector.outbound.security; 19 20 import javax.resource.spi.ManagedConnectionFactory ; 21 import java.util.HashMap ; 22 import java.util.Map ; 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 38 public class PasswordCredentialRealm implements SecurityRealm, ConfigurationEntryFactory, ManagedConnectionFactoryListener { 39 40 private static final GBeanInfo GBEAN_INFO; 41 42 ManagedConnectionFactory managedConnectionFactory; 43 private final Kernel kernel; 44 private final String realmName; 45 46 static final String REALM_INSTANCE = "org.apache.connector.outbound.security.PasswordCredentialRealm"; 47 48 public PasswordCredentialRealm(Kernel kernel, String realmName) { 49 this.kernel = kernel; 50 this.realmName = realmName; 51 } 52 53 public String getRealmName() { 54 return realmName; 55 } 56 57 public boolean isRestrictPrincipalsToServer() { 58 return true; 59 } 60 61 public String [] getLoginDomains() { 62 return new String []{realmName}; 63 } 64 65 public JaasLoginModuleConfiguration[] getAppConfigurationEntries() { 66 Map options = new HashMap (); 67 68 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 managedConnectionFactory) { 77 this.managedConnectionFactory = managedConnectionFactory; 78 } 79 80 ManagedConnectionFactory getManagedConnectionFactory() { 81 return managedConnectionFactory; 82 } 83 84 public String getConfigurationName() { 85 return realmName; 86 } 87 88 public JaasLoginModuleConfiguration generateConfiguration() { 89 Map options = new HashMap (); 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 .class, true); 103 104 infoFactory.setConstructor(new String []{"kernel", "realmName"}); 105 106 GBEAN_INFO = infoFactory.getBeanInfo(); 107 } 108 109 public static GBeanInfo getGBeanInfo() { 110 return GBEAN_INFO; 111 } 112 } 113 | Popular Tags |