292
293 private static synchronized
294 void setSecurityManager0(final SecurityManager s) {
295 SecurityManager sm = getSecurityManager();
296 if (sm != null) {
297 // ask the currently installed security manager if we
298 // can replace it.
299 sm.checkPermission(new RuntimePermission
300 ("setSecurityManager"));
301 }
302
303 if ((s != null) && (s.getClass().getClassLoader() != null)) {
304 // New security manager class is not on bootstrap classpath.
305 // Cause policy to get initialized before we install the new
306 // security manager, in order to prevent infinite loops when
307 // trying to initialize the policy (which usually involves
308 // accessing some security and/or system properties, which in turn
309 // calls the installed security manager's checkPermission method
310 // which will loop infinitely if there is a non-system class
311 // (in this case: the new security manager class) on the stack).
312 AccessController.doPrivileged(new PrivilegedAction<Object>() {
313 public Object run() {
314 s.getClass().getProtectionDomain().implies
315 (SecurityConstants.ALL_PERMISSION);
316 return null;
317 }
318 });
319 }
320
321 security = s;
322 }
323
324 /**
325 * Gets the system security interface.
326 *
327 * @return if a security manager has already been established for the
328 * current application, then that security manager is returned;
329 * otherwise, <code>null</code> is returned.
330 * @see #setSecurityManager
331 */
332 public static SecurityManager getSecurityManager() {
|
292
293 private static synchronized
294 void setSecurityManager0(final SecurityManager s) {
295 SecurityManager sm = getSecurityManager();
296 if (sm != null) {
297 // ask the currently installed security manager if we
298 // can replace it.
299 sm.checkPermission(new RuntimePermission
300 ("setSecurityManager"));
301 }
302
303 if ((s != null) && (s.getClass().getClassLoader() != null)) {
304 // New security manager class is not on bootstrap classpath.
305 // Cause policy to get initialized before we install the new
306 // security manager, in order to prevent infinite loops when
307 // trying to initialize the policy (which usually involves
308 // accessing some security and/or system properties, which in turn
309 // calls the installed security manager's checkPermission method
310 // which will loop infinitely if there is a non-system class
311 // (in this case: the new security manager class) on the stack).
312 AccessController.doPrivileged(new PrivilegedAction<>() {
313 public Object run() {
314 s.getClass().getProtectionDomain().implies
315 (SecurityConstants.ALL_PERMISSION);
316 return null;
317 }
318 });
319 }
320
321 security = s;
322 }
323
324 /**
325 * Gets the system security interface.
326 *
327 * @return if a security manager has already been established for the
328 * current application, then that security manager is returned;
329 * otherwise, <code>null</code> is returned.
330 * @see #setSecurityManager
331 */
332 public static SecurityManager getSecurityManager() {
|