1 7 8 package java.security; 9 10 import sun.security.util.Debug; 11 12 229 230 public final class AccessController { 231 232 235 private AccessController() { } 236 237 254 255 public static native <T> T doPrivileged(PrivilegedAction <T> action); 256 257 258 285 public static native <T> T doPrivileged(PrivilegedAction <T> action, 286 AccessControlContext context); 287 288 307 public static native <T> T 308 doPrivileged(PrivilegedExceptionAction <T> action) 309 throws PrivilegedActionException ; 310 311 312 341 public static native <T> T 342 doPrivileged(PrivilegedExceptionAction <T> action, 343 AccessControlContext context) 344 throws PrivilegedActionException ; 345 346 355 356 private static native AccessControlContext getStackAccessControlContext(); 357 358 363 364 static native AccessControlContext getInheritedAccessControlContext(); 365 366 376 377 public static AccessControlContext getContext() 378 { 379 AccessControlContext acc = getStackAccessControlContext(); 380 if (acc == null) { 381 return new AccessControlContext (null, true); 384 } else { 385 return acc.optimize(); 386 } 387 } 388 389 404 405 public static void checkPermission(Permission perm) 406 throws AccessControlException 407 { 408 411 AccessControlContext stack = getStackAccessControlContext(); 412 if (stack == null) { 414 Debug debug = AccessControlContext.getDebug(); 415 if (debug != null) { 416 if (Debug.isOn("stack")) 417 Thread.currentThread().dumpStack(); 418 if (Debug.isOn("domain")) { 419 debug.println("domain (context is null)"); 420 } 421 debug.println("access allowed "+perm); 422 } 423 return; 424 } 425 426 AccessControlContext acc = stack.optimize(); 427 acc.checkPermission(perm); 428 429 } 430 } 431 | Popular Tags |