1 7 package org.jboss.security.plugins; 8 9 import java.io.InputStream ; 10 import java.io.IOException ; 11 import java.io.PrintWriter ; 12 import java.io.StringWriter ; 13 import java.net.URL ; 14 import java.util.Stack ; 15 import javax.management.JMException ; 16 import javax.management.MalformedObjectNameException ; 17 import javax.management.MBeanServer ; 18 import javax.management.ObjectName ; 19 import javax.security.auth.login.Configuration ; 20 21 import org.jboss.system.ServiceMBeanSupport; 22 23 31 public class SecurityConfig extends ServiceMBeanSupport 32 implements SecurityConfigMBean 33 { 34 36 38 private String loginConfigName; 39 40 private Stack loginConfigStack = new Stack (); 41 42 static class ConfigInfo 43 { 44 ObjectName name; 45 Configuration config; 46 ConfigInfo(ObjectName name, Configuration config) 47 { 48 this.name = name; 49 this.config = config; 50 } 51 } 52 53 public SecurityConfig() 54 { 55 } 56 57 public String getName() 58 { 59 return "SecurityIntialization"; 60 } 61 62 64 public String getLoginConfig() 65 { 66 return loginConfigName; 67 } 68 69 71 public void setLoginConfig(String name) throws MalformedObjectNameException 72 { 73 this.loginConfigName = name; 74 } 75 76 79 public void startService() throws Exception 80 { 81 pushLoginConfig(loginConfigName); 82 } 83 84 87 public void stopService() throws Exception 88 { 89 if( loginConfigStack.empty() == false ) 90 popLoginConfig(); 91 } 92 93 97 public synchronized void pushLoginConfig(String objectName) 98 throws JMException , MalformedObjectNameException 99 { 100 ObjectName name = new ObjectName (objectName); 101 Configuration prevConfig = null; 102 if( loginConfigStack.empty() == false ) 103 { 104 ConfigInfo prevInfo = (ConfigInfo) loginConfigStack.peek(); 105 prevConfig = prevInfo.config; 106 } 107 108 ConfigInfo info = installConfig(name, prevConfig); 109 loginConfigStack.push(info); 110 } 111 115 public synchronized void popLoginConfig() 116 throws JMException 117 { 118 ConfigInfo info = (ConfigInfo) loginConfigStack.pop(); 119 Configuration prevConfig = null; 120 if( loginConfigStack.empty() == false ) 121 { 122 ConfigInfo prevInfo = (ConfigInfo) loginConfigStack.peek(); 123 prevConfig = prevInfo.config; 124 } 125 126 installConfig(info.name, prevConfig); 127 } 128 129 134 private ConfigInfo installConfig(ObjectName name, Configuration prevConfig) 135 throws JMException 136 { 137 MBeanServer server = super.getServer(); 138 Object [] args = {prevConfig}; 139 String [] signature = {"javax.security.auth.login.Configuration"}; 140 Configuration config = (Configuration ) server.invoke(name, 141 "getConfiguration", args, signature); 142 Configuration.setConfiguration(config); 143 ConfigInfo info = new ConfigInfo(name, config); 144 log.debug("Installed JAAS Configuration service="+name+", config="+config); 145 return info; 146 } 147 } 148 | Popular Tags |