1 22 package org.jboss.test.security.service; 23 24 import java.net.MalformedURLException ; 25 import java.net.URL ; 26 import java.util.Hashtable ; 27 import javax.management.MBeanServer ; 28 import javax.management.ObjectName ; 29 import javax.security.auth.login.Configuration ; 30 31 import org.jboss.security.auth.login.XMLLoginConfig; 32 import org.jboss.system.ServiceMBeanSupport; 33 34 41 public class SecurityConfig extends ServiceMBeanSupport 42 implements SecurityConfigMBean 43 { 44 46 private String authConf = "login-config.xml"; 48 private XMLLoginConfig config = null; 49 private ObjectName mainSecurityConfig; 50 51 53 public SecurityConfig() 55 { 56 setSecurityConfigName("jboss.security:name=SecurityConfig"); 57 } 58 59 public String getName() 60 { 61 return "JAAS Login Config"; 62 } 63 public String getSecurityConfigName() 64 { 65 return mainSecurityConfig.toString(); 66 } 67 public void setSecurityConfigName(String objectName) 68 { 69 try 70 { 71 mainSecurityConfig = new ObjectName (objectName); 72 } 73 catch(Exception e) 74 { 75 log.error("Failed to create ObjectName", e); 76 } 77 } 78 79 81 public String getAuthConfig() 82 { 83 return authConf; 84 } 85 86 89 public void setAuthConfig(String authConf) 90 { 91 this.authConf = authConf; 92 } 93 94 97 protected void startService() throws Exception 98 { 99 ClassLoader loader = Thread.currentThread().getContextClassLoader(); 101 URL loginConfig = loader.getResource(authConf); 102 if( loginConfig != null ) 103 { 104 log.info("Using JAAS AuthConfig: "+loginConfig.toExternalForm()); 105 config = new XMLLoginConfig(); 106 config.setConfigURL(loginConfig); 107 config.start(); 108 MBeanServer server = super.getServer(); 109 ObjectName name = super.getServiceName(); 110 Hashtable props = name.getKeyPropertyList(); 111 props.put("testConfig", "XMLLoginConfig"); 112 name = new ObjectName (name.getDomain(), props); 113 server.registerMBean(config, name); 114 Object [] args = {name.toString()}; 115 String [] sig = {String .class.getName()}; 116 server.invoke(mainSecurityConfig, "pushLoginConfig", args, sig); 117 } 118 else 119 { 120 log.warn("No AuthConfig resource found"); 121 } 122 } 123 124 protected void stopService() throws Exception 125 { 126 MBeanServer server = super.getServer(); 127 ObjectName name = super.getServiceName(); 128 Hashtable props = name.getKeyPropertyList(); 129 props.put("testConfig", "XMLLoginConfig"); 130 name = new ObjectName (name.getDomain(), props); 131 Object [] args = {}; 132 String [] sig = {}; 133 server.invoke(mainSecurityConfig, "popLoginConfig", args, sig); 134 server.unregisterMBean(name); 135 } 136 } 137 | Popular Tags |