--- a/jdk/src/share/classes/java/security/ProtectionDomain.java Mon Dec 07 21:16:41 2009 -0800
+++ b/jdk/src/share/classes/java/security/ProtectionDomain.java Tue Dec 08 15:58:49 2009 -0500
@@ -1,5 +1,5 @@
/*
- * Copyright 1997-2006 Sun Microsystems, Inc. All Rights Reserved.
+ * Copyright 1997-2009 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -25,9 +25,15 @@
package java.security;
+import java.util.ArrayList;
+import java.util.Collections;
import java.util.Enumeration;
import java.util.List;
-import java.util.ArrayList;
+import java.util.Map;
+import java.util.WeakHashMap;
+import sun.misc.JavaSecurityProtectionDomainAccess;
+import static sun.misc.JavaSecurityProtectionDomainAccess.ProtectionDomainCache;
+import sun.misc.SharedSecrets;
import sun.security.util.Debug;
import sun.security.util.SecurityConstants;
@@ -72,6 +78,11 @@
or dynamic (via a policy refresh) */
private boolean staticPermissions;
+ /*
+ * An object used as a key when the ProtectionDomain is stored in a Map.
+ */
+ final Key key = new Key();
+
private static final Debug debug = Debug.getInstance("domain");
/**
@@ -238,7 +249,7 @@
/**
* Convert a ProtectionDomain to a String.
*/
- public String toString() {
+ @Override public String toString() {
String pals = "<no principals>";
if (principals != null && principals.length > 0) {
StringBuilder palBuf = new StringBuilder("(principals ");
@@ -396,4 +407,29 @@
return mergedPerms;
}
+
+ /**
+ * Used for storing ProtectionDomains as keys in a Map.
+ */
+ final class Key {}
+
+ static {
+ SharedSecrets.setJavaSecurityProtectionDomainAccess(
+ new JavaSecurityProtectionDomainAccess() {
+ public ProtectionDomainCache getProtectionDomainCache() {
+ return new ProtectionDomainCache() {
+ private final Map<Key, PermissionCollection> map =
+ Collections.synchronizedMap
+ (new WeakHashMap<Key, PermissionCollection>());
+ public void put(ProtectionDomain pd,
+ PermissionCollection pc) {
+ map.put((pd == null ? null : pd.key), pc);
+ }
+ public PermissionCollection get(ProtectionDomain pd) {
+ return pd == null ? map.get(null) : map.get(pd.key);
+ }
+ };
+ }
+ });
+ }
}