1 7 package org.jboss.security.auth.login; 8 9 import java.net.URL ; 10 import javax.management.MBeanServer ; 11 import javax.management.ObjectName ; 12 13 import org.jboss.system.ServiceMBeanSupport; 14 import org.jboss.deployment.DeploymentException; 15 16 45 public class DynamicLoginConfig extends ServiceMBeanSupport 46 implements DynamicLoginConfigMBean 47 { 48 49 private String authConf = "login-config.xml"; 50 51 private ObjectName loginConfigService; 52 53 private ObjectName securityMgrService; 54 55 private String [] configNames; 56 57 public DynamicLoginConfig() 58 { 59 } 60 61 public String getName() 62 { 63 return "Dynamic JAAS Login Config"; 64 } 65 66 public ObjectName getLoginConfigService() 67 { 68 return loginConfigService; 69 } 70 75 public void setLoginConfigService(ObjectName serviceName) 76 { 77 this.loginConfigService = serviceName; 78 } 79 80 public ObjectName getSecurityManagerService() 81 { 82 return securityMgrService; 83 } 84 91 public void setSecurityManagerService(ObjectName serviceName) 92 { 93 this.securityMgrService = serviceName; 94 } 95 96 98 public String getAuthConfig() 99 { 100 return authConf; 101 } 102 103 106 public void setAuthConfig(String authConf) 107 { 108 this.authConf = authConf; 109 } 110 111 116 public void flushAuthenticationCaches() throws Exception 117 { 118 if( this.securityMgrService != null && server.isRegistered(securityMgrService)) 119 { 120 int count = configNames == null ? 0 : configNames.length; 121 String [] sig = {String .class.getName()}; 122 for(int n = 0; n < count; n ++) 123 { 124 Object [] args = {configNames[n]}; 125 server.invoke(securityMgrService, "flushAuthenticationCache", args, sig); 126 log.debug("Flushed domain: "+configNames[n]); 127 } 128 } 129 } 130 131 134 protected void startService() throws Exception 135 { 136 ClassLoader loader = Thread.currentThread().getContextClassLoader(); 138 URL loginConfig = loader.getResource(authConf); 139 if( loginConfig != null ) 140 { 141 log.debug("Using JAAS AuthConfig: "+loginConfig.toExternalForm()); 142 MBeanServer server = super.getServer(); 143 Object [] args = {loginConfig}; 144 String [] sig = {URL .class.getName()}; 145 configNames = (String []) server.invoke(loginConfigService, 146 "loadConfig", args, sig); 147 int count = configNames == null ? 0 : configNames.length; 148 for(int n = 0; n < count; n ++) 149 { 150 log.debug("Loaded config: "+configNames[n]); 151 } 152 } 153 else 154 { 155 throw new DeploymentException("Failed to find authConf as resource: "+authConf); 156 } 157 } 158 159 162 protected void stopService() throws Exception 163 { 164 MBeanServer server = super.getServer(); 165 flushAuthenticationCaches(); 166 if( configNames != null && configNames.length > 0 ) 167 { 168 Object [] args = {configNames}; 169 String [] sig = {configNames.getClass().getName()}; 170 server.invoke(loginConfigService, "removeConfigs", args, sig); 171 } 172 } 173 } 174 | Popular Tags |