diff -r 0419f45c7761 -r 44dfee24cb71 jdk/src/share/classes/java/security/AccessController.java --- a/jdk/src/share/classes/java/security/AccessController.java Wed Apr 17 10:15:33 2013 +0800 +++ b/jdk/src/share/classes/java/security/AccessController.java Tue Apr 16 21:39:52 2013 -0700 @@ -26,6 +26,8 @@ package java.security; import sun.security.util.Debug; +import sun.reflect.CallerSensitive; +import sun.reflect.Reflection; /** *

The AccessController class is used for access control operations @@ -264,6 +266,7 @@ * @see java.security.DomainCombiner */ + @CallerSensitive public static native T doPrivileged(PrivilegedAction action); /** @@ -288,14 +291,15 @@ * * @since 1.6 */ + @CallerSensitive public static T doPrivilegedWithCombiner(PrivilegedAction action) { - AccessControlContext acc = getStackAccessControlContext(); if (acc == null) { return AccessController.doPrivileged(action); } DomainCombiner dc = acc.getAssignedCombiner(); - return AccessController.doPrivileged(action, preserveCombiner(dc)); + return AccessController.doPrivileged(action, + preserveCombiner(dc, Reflection.getCallerClass())); } @@ -326,6 +330,7 @@ * @see #doPrivileged(PrivilegedAction) * @see #doPrivileged(PrivilegedExceptionAction,AccessControlContext) */ + @CallerSensitive public static native T doPrivileged(PrivilegedAction action, AccessControlContext context); @@ -353,6 +358,7 @@ * @see #doPrivilegedWithCombiner(PrivilegedExceptionAction) * @see java.security.DomainCombiner */ + @CallerSensitive public static native T doPrivileged(PrivilegedExceptionAction action) throws PrivilegedActionException; @@ -383,34 +389,29 @@ * * @since 1.6 */ - public static T doPrivilegedWithCombiner - (PrivilegedExceptionAction action) throws PrivilegedActionException { - + @CallerSensitive + public static T doPrivilegedWithCombiner(PrivilegedExceptionAction action) + throws PrivilegedActionException + { AccessControlContext acc = getStackAccessControlContext(); if (acc == null) { return AccessController.doPrivileged(action); } DomainCombiner dc = acc.getAssignedCombiner(); - return AccessController.doPrivileged(action, preserveCombiner(dc)); + return AccessController.doPrivileged(action, + preserveCombiner(dc, Reflection.getCallerClass())); } /** * preserve the combiner across the doPrivileged call */ - private static AccessControlContext preserveCombiner - (DomainCombiner combiner) { - - /** - * callerClass[0] = Reflection.getCallerClass - * callerClass[1] = AccessController.preserveCombiner - * callerClass[2] = AccessController.doPrivileged - * callerClass[3] = caller - */ - final Class callerClass = sun.reflect.Reflection.getCallerClass(3); + private static AccessControlContext preserveCombiner(DomainCombiner combiner, + Class caller) + { ProtectionDomain callerPd = doPrivileged (new PrivilegedAction() { public ProtectionDomain run() { - return callerClass.getProtectionDomain(); + return caller.getProtectionDomain(); } }); @@ -455,6 +456,7 @@ * @see #doPrivileged(PrivilegedAction) * @see #doPrivileged(PrivilegedExceptionAction,AccessControlContext) */ + @CallerSensitive public static native T doPrivileged(PrivilegedExceptionAction action, AccessControlContext context)