# HG changeset patch # User jbachorik # Date 1387805367 -3600 # Node ID 694814411ba93589d63fc31b8f66ca54164f9ea6 # Parent be16fac29d7fe859ebd676402c0e8133cd229811 8029286: Enhance subject delegation Reviewed-by: dfuchs, ahgross diff -r be16fac29d7f -r 694814411ba9 jdk/src/share/classes/com/sun/jmx/remote/security/SubjectDelegator.java --- a/jdk/src/share/classes/com/sun/jmx/remote/security/SubjectDelegator.java Tue Jan 14 11:55:26 2014 +0000 +++ b/jdk/src/share/classes/com/sun/jmx/remote/security/SubjectDelegator.java Mon Dec 23 14:29:27 2013 +0100 @@ -35,6 +35,8 @@ import javax.management.remote.SubjectDelegationPermission; import com.sun.jmx.remote.util.CacheMap; +import java.util.ArrayList; +import java.util.Collection; public class SubjectDelegator { private static final int PRINCIPALS_CACHE_SIZE = 10; @@ -53,11 +55,14 @@ boolean removeCallerContext) throws SecurityException { + if (System.getSecurityManager() != null && authenticatedACC == null) { + throw new SecurityException("Illegal AccessControlContext: null"); + } if (principalsCache == null || accCache == null) { principalsCache = - new CacheMap(PRINCIPALS_CACHE_SIZE); + new CacheMap<>(PRINCIPALS_CACHE_SIZE); accCache = - new CacheMap(ACC_CACHE_SIZE); + new CacheMap<>(ACC_CACHE_SIZE); } // Retrieve the principals for the given @@ -101,14 +106,15 @@ // principal in the delegated subject // final Principal[] dp = delegatedPrincipals; + final Collection permissions = new ArrayList<>(dp.length); + for(Principal p : dp) { + final String pname = p.getClass().getName() + "." + p.getName(); + permissions.add(new SubjectDelegationPermission(pname)); + } PrivilegedAction action = new PrivilegedAction() { public Void run() { - for (int i = 0 ; i < dp.length ; i++) { - final String pname = - dp[i].getClass().getName() + "." + dp[i].getName(); - Permission sdp = - new SubjectDelegationPermission(pname); + for (Permission sdp : permissions) { AccessController.checkPermission(sdp); } return null;