--- old/src/java.base/share/classes/sun/security/provider/PolicyFile.java 2019-03-05 14:49:26.000000000 -0500 +++ new/src/java.base/share/classes/sun/security/provider/PolicyFile.java 2019-03-05 14:49:25.000000000 -0500 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2019, 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 @@ -30,6 +30,7 @@ import java.net.MalformedURLException; import java.net.URL; import java.net.URI; +import java.nio.file.Files; import java.nio.file.Path; import java.util.*; import java.security.*; @@ -37,7 +38,6 @@ import java.security.cert.X509Certificate; import javax.security.auth.Subject; import javax.security.auth.x500.X500Principal; -import java.io.FilePermission; import java.net.SocketPermission; import java.net.NetPermission; import java.util.concurrent.ConcurrentHashMap; @@ -273,23 +273,6 @@ private static Set badPolicyURLs = Collections.newSetFromMap(new ConcurrentHashMap()); - // The default.policy file - private static final URL DEFAULT_POLICY_URL = - AccessController.doPrivileged(new PrivilegedAction<>() { - @Override - public URL run() { - String sep = File.separator; - try { - return Path.of(StaticProperty.javaHome(), - "lib", "security", - "default.policy").toUri().toURL(); - } catch (MalformedURLException mue) { - // should not happen - throw new Error("Malformed default.policy URL: " + mue); - } - } - }); - /** * Initializes the Policy object and reads the default policy * configuration file(s) into the Policy object. @@ -349,13 +332,10 @@ private void initPolicyFile(final PolicyInfo newInfo, final URL url) { // always load default.policy - if (debug != null) { - debug.println("reading " + DEFAULT_POLICY_URL); - } AccessController.doPrivileged(new PrivilegedAction<>() { @Override public Void run() { - init(DEFAULT_POLICY_URL, newInfo, true); + initDefaultPolicy(newInfo); return null; } }); @@ -373,7 +353,7 @@ AccessController.doPrivileged(new PrivilegedAction<>() { @Override public Void run() { - if (init(url, newInfo, false) == false) { + if (init(url, newInfo) == false) { // use static policy if all else fails initStaticPolicy(newInfo); } @@ -429,7 +409,7 @@ if (debug != null) { debug.println("reading "+policyURL); } - if (init(policyURL, newInfo, false)) { + if (init(policyURL, newInfo)) { loaded_policy = true; } } catch (Exception e) { @@ -472,7 +452,7 @@ if (debug != null) { debug.println("reading " + policy_url); } - if (init(policy_url, newInfo, false)) { + if (init(policy_url, newInfo)) { loaded_policy = true; } } catch (Exception e) { @@ -492,11 +472,34 @@ return loadedPolicy; } + private void initDefaultPolicy(PolicyInfo newInfo) { + Path defaultPolicy = Path.of(StaticProperty.javaHome(), + "lib", + "security", + "default.policy"); + if (debug != null) { + debug.println("reading " + defaultPolicy); + } + try (BufferedReader br = Files.newBufferedReader(defaultPolicy)) { + + PolicyParser pp = new PolicyParser(expandProperties); + pp.read(br); + + Enumeration enum_ = pp.grantElements(); + while (enum_.hasMoreElements()) { + PolicyParser.GrantEntry ge = enum_.nextElement(); + addGrantEntry(ge, null, newInfo); + } + } catch (Exception e) { + throw new InternalError("Failed to load default.policy", e); + } + } + /** * Reads a policy configuration into the Policy object using a * Reader object. */ - private boolean init(URL policy, PolicyInfo newInfo, boolean defPolicy) { + private boolean init(URL policy, PolicyInfo newInfo) { // skip parsing policy file if it has been previously parsed and // has syntax errors @@ -537,9 +540,6 @@ } return true; } catch (PolicyParser.ParsingException pe) { - if (defPolicy) { - throw new InternalError("Failed to load default.policy", pe); - } // record bad policy file to avoid later reparsing it badPolicyURLs.add(policy); Object[] source = {policy, pe.getNonlocalizedMessage()}; @@ -549,9 +549,6 @@ pe.printStackTrace(); } } catch (Exception e) { - if (defPolicy) { - throw new InternalError("Failed to load default.policy", e); - } if (debug != null) { debug.println("error parsing "+policy); debug.println(e.toString());