8152821: Merge jdk.internal.misc.JavaSecurityAccess and jdk.internal.misc.JavaSecurityProtectionDomainAccess shared secrets
Reviewed-by: mullan
This commit is contained in:
parent
9ec65a4f0f
commit
f5a681373f
src/java.base/share/classes
java/security
jdk/internal/misc
sun/security/provider
@ -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.Map;
|
||||
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 @@ public class ProtectionDomain {
|
||||
|
||||
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 @@ public class ProtectionDomain {
|
||||
*/
|
||||
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);
|
||||
}
|
||||
};
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -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 @@ public interface JavaSecurityAccess {
|
||||
AccessControlContext context);
|
||||
|
||||
ProtectionDomain[] getProtectDomains(AccessControlContext context);
|
||||
|
||||
interface ProtectionDomainCache {
|
||||
void put(ProtectionDomain pd, PermissionCollection pc);
|
||||
PermissionCollection get(ProtectionDomain pd);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the ProtectionDomainCache.
|
||||
*/
|
||||
ProtectionDomainCache getProtectionDomainCache();
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
@ -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.FilePermission;
|
||||
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 @@ public class SharedSecrets {
|
||||
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 @@ public class SharedSecrets {
|
||||
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;
|
||||
}
|
||||
|
@ -41,8 +41,8 @@ import java.io.FilePermission;
|
||||
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 @@ public class PolicyFile extends java.security.Policy {
|
||||
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();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user