8152821: Merge jdk.internal.misc.JavaSecurityAccess and jdk.internal.misc.JavaSecurityProtectionDomainAccess shared secrets
authorredestad
Fri, 13 Apr 2018 01:04:33 +0200
changeset 49588 ae568aefc5aa
parent 49587 1a87516db0b7
child 49589 4d3f0fea5469
child 49696 508e9f6632fd
8152821: Merge jdk.internal.misc.JavaSecurityAccess and jdk.internal.misc.JavaSecurityProtectionDomainAccess shared secrets Reviewed-by: mullan
src/java.base/share/classes/java/security/ProtectionDomain.java
src/java.base/share/classes/jdk/internal/misc/JavaSecurityAccess.java
src/java.base/share/classes/jdk/internal/misc/JavaSecurityProtectionDomainAccess.java
src/java.base/share/classes/jdk/internal/misc/SharedSecrets.java
src/java.base/share/classes/sun/security/provider/PolicyFile.java
--- a/src/java.base/share/classes/java/security/ProtectionDomain.java	Thu Apr 12 15:26:59 2018 -0700
+++ b/src/java.base/share/classes/java/security/ProtectionDomain.java	Fri Apr 13 01:04:33 2018 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2018, Oracle and/or its affiliates. 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
@@ -33,8 +33,6 @@
 import java.util.Objects;
 import java.util.WeakHashMap;
 import jdk.internal.misc.JavaSecurityAccess;
-import jdk.internal.misc.JavaSecurityProtectionDomainAccess;
-import static jdk.internal.misc.JavaSecurityProtectionDomainAccess.ProtectionDomainCache;
 import jdk.internal.misc.SharedSecrets;
 import sun.security.action.GetPropertyAction;
 import sun.security.provider.PolicyFile;
@@ -110,6 +108,21 @@
 
             return new AccessControlContext(stack.getContext(), acc).optimize();
         }
+
+        @Override
+        public ProtectionDomainCache getProtectionDomainCache() {
+            return new ProtectionDomainCache() {
+                private final Map<Key, PermissionCollection> map =
+                        Collections.synchronizedMap(new WeakHashMap<>());
+                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);
+                }
+            };
+        }
     }
 
     static {
@@ -560,23 +573,4 @@
      */
     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);
-                        }
-                    };
-                }
-            });
-    }
 }
--- a/src/java.base/share/classes/jdk/internal/misc/JavaSecurityAccess.java	Thu Apr 12 15:26:59 2018 -0700
+++ b/src/java.base/share/classes/jdk/internal/misc/JavaSecurityAccess.java	Fri Apr 13 01:04:33 2018 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2010, 2018, Oracle and/or its affiliates. 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
@@ -26,6 +26,7 @@
 package jdk.internal.misc;
 
 import java.security.AccessControlContext;
+import java.security.PermissionCollection;
 import java.security.PrivilegedAction;
 import java.security.ProtectionDomain;
 
@@ -39,4 +40,14 @@
                                   AccessControlContext context);
 
     ProtectionDomain[] getProtectDomains(AccessControlContext context);
+
+    interface ProtectionDomainCache {
+        void put(ProtectionDomain pd, PermissionCollection pc);
+        PermissionCollection get(ProtectionDomain pd);
+    }
+
+    /**
+     * Returns the ProtectionDomainCache.
+     */
+    ProtectionDomainCache getProtectionDomainCache();
 }
--- a/src/java.base/share/classes/jdk/internal/misc/JavaSecurityProtectionDomainAccess.java	Thu Apr 12 15:26:59 2018 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,39 +0,0 @@
-/*
- * Copyright (c) 2009, Oracle and/or its affiliates. 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
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.  Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-package jdk.internal.misc;
-
-import java.security.PermissionCollection;
-import java.security.ProtectionDomain;
-
-public interface JavaSecurityProtectionDomainAccess {
-    interface ProtectionDomainCache {
-        void put(ProtectionDomain pd, PermissionCollection pc);
-        PermissionCollection get(ProtectionDomain pd);
-    }
-    /**
-     * Returns the ProtectionDomainCache.
-     */
-    ProtectionDomainCache getProtectionDomainCache();
-}
--- a/src/java.base/share/classes/jdk/internal/misc/SharedSecrets.java	Thu Apr 12 15:26:59 2018 -0700
+++ b/src/java.base/share/classes/jdk/internal/misc/SharedSecrets.java	Fri Apr 13 01:04:33 2018 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2002, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2002, 2018, Oracle and/or its affiliates. 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
@@ -35,7 +35,6 @@
 import java.io.ObjectInputStream;
 import java.io.RandomAccessFile;
 import java.security.ProtectionDomain;
-import java.security.AccessController;
 
 /** A repository of "shared secrets", which are a mechanism for
     calling implementation-private methods in another package without
@@ -63,7 +62,6 @@
     private static JavaNioAccess javaNioAccess;
     private static JavaIOFileDescriptorAccess javaIOFileDescriptorAccess;
     private static JavaIOFilePermissionAccess javaIOFilePermissionAccess;
-    private static JavaSecurityProtectionDomainAccess javaSecurityProtectionDomainAccess;
     private static JavaSecurityAccess javaSecurityAccess;
     private static JavaUtilZipFileAccess javaUtilZipFileAccess;
     private static JavaUtilResourceBundleAccess javaUtilResourceBundleAccess;
@@ -235,25 +233,13 @@
         return javaIOFileDescriptorAccess;
     }
 
-    public static void setJavaSecurityProtectionDomainAccess
-        (JavaSecurityProtectionDomainAccess jspda) {
-            javaSecurityProtectionDomainAccess = jspda;
-    }
-
-    public static JavaSecurityProtectionDomainAccess
-        getJavaSecurityProtectionDomainAccess() {
-            if (javaSecurityProtectionDomainAccess == null)
-                unsafe.ensureClassInitialized(ProtectionDomain.class);
-            return javaSecurityProtectionDomainAccess;
-    }
-
     public static void setJavaSecurityAccess(JavaSecurityAccess jsa) {
         javaSecurityAccess = jsa;
     }
 
     public static JavaSecurityAccess getJavaSecurityAccess() {
         if (javaSecurityAccess == null) {
-            unsafe.ensureClassInitialized(AccessController.class);
+            unsafe.ensureClassInitialized(ProtectionDomain.class);
         }
         return javaSecurityAccess;
     }
--- a/src/java.base/share/classes/sun/security/provider/PolicyFile.java	Thu Apr 12 15:26:59 2018 -0700
+++ b/src/java.base/share/classes/sun/security/provider/PolicyFile.java	Fri Apr 13 01:04:33 2018 +0200
@@ -41,8 +41,8 @@
 import java.net.SocketPermission;
 import java.net.NetPermission;
 import java.util.concurrent.atomic.AtomicReference;
-import jdk.internal.misc.JavaSecurityProtectionDomainAccess;
-import static jdk.internal.misc.JavaSecurityProtectionDomainAccess.ProtectionDomainCache;
+import jdk.internal.misc.JavaSecurityAccess;
+import static jdk.internal.misc.JavaSecurityAccess.ProtectionDomainCache;
 import jdk.internal.misc.SharedSecrets;
 import sun.security.util.*;
 import sun.net.www.ParseUtil;
@@ -2202,8 +2202,8 @@
             aliasMapping = Collections.synchronizedMap(new HashMap<>(11));
 
             pdMapping = new ProtectionDomainCache[numCaches];
-            JavaSecurityProtectionDomainAccess jspda
-                = SharedSecrets.getJavaSecurityProtectionDomainAccess();
+            JavaSecurityAccess jspda
+                = SharedSecrets.getJavaSecurityAccess();
             for (int i = 0; i < numCaches; i++) {
                 pdMapping[i] = jspda.getProtectionDomainCache();
             }