1 7 8 package javax.security.auth.login; 9 10 import javax.security.auth.AuthPermission ; 11 12 import java.io.*; 13 import java.util.*; 14 import java.net.URL ; 15 import java.security.PrivilegedActionException ; 16 17 152 public abstract class Configuration { 153 154 private static Configuration configuration; 155 private static ClassLoader contextClassLoader; 156 157 static { 158 contextClassLoader = 159 (ClassLoader )java.security.AccessController.doPrivileged 160 (new java.security.PrivilegedAction () { 161 public Object run() { 162 return Thread.currentThread().getContextClassLoader(); 163 } 164 }); 165 }; 166 167 171 protected Configuration() { } 172 173 188 public static synchronized Configuration getConfiguration() { 189 190 SecurityManager sm = System.getSecurityManager(); 191 if (sm != null) 192 sm.checkPermission(new AuthPermission ("getLoginConfiguration")); 193 194 if (configuration == null) { 195 String config_class = null; 196 config_class = (String ) 197 java.security.AccessController.doPrivileged 198 (new java.security.PrivilegedAction () { 199 public Object run() { 200 return java.security.Security.getProperty 201 ("login.configuration.provider"); 202 } 203 }); 204 if (config_class == null) { 205 config_class = "com.sun.security.auth.login.ConfigFile"; 206 } 207 208 try { 209 final String finalClass = config_class; 210 configuration = (Configuration ) 211 java.security.AccessController.doPrivileged 212 (new java.security.PrivilegedExceptionAction () { 213 public Object run() throws ClassNotFoundException , 214 InstantiationException , 215 IllegalAccessException { 216 return Class.forName 217 (finalClass, 218 true, 219 contextClassLoader).newInstance(); 220 } 221 }); 222 } catch (PrivilegedActionException e) { 223 Exception ee = e.getException(); 224 if (ee instanceof InstantiationException ) { 225 throw (SecurityException ) new 226 SecurityException 227 ("Configuration error:" + 228 ee.getCause().getMessage() + 229 "\n").initCause(ee.getCause()); 230 } else { 231 throw (SecurityException ) new 232 SecurityException 233 ("Configuration error: " + 234 ee.toString() + 235 "\n").initCause(ee); 236 } 237 } 238 } 239 return configuration; 240 } 241 242 254 public static void setConfiguration(Configuration configuration) { 255 SecurityManager sm = System.getSecurityManager(); 256 if (sm != null) 257 sm.checkPermission(new AuthPermission ("setLoginConfiguration")); 258 Configuration.configuration = configuration; 259 } 260 261 273 public abstract AppConfigurationEntry [] getAppConfigurationEntry 274 (String name); 275 276 289 public abstract void refresh(); 290 } 291 | Popular Tags |