< prev index next >

src/java.base/share/classes/sun/security/provider/PolicyFile.java

Print this page




  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package sun.security.provider;
  27 
  28 import java.io.*;
  29 import java.lang.reflect.*;
  30 import java.net.MalformedURLException;
  31 import java.net.URL;
  32 import java.net.URI;
  33 import java.nio.file.Paths;
  34 import java.util.*;
  35 import java.security.*;
  36 import java.security.cert.Certificate;
  37 import java.security.cert.X509Certificate;
  38 import javax.security.auth.Subject;
  39 import javax.security.auth.x500.X500Principal;
  40 import java.io.FilePermission;
  41 import java.net.SocketPermission;
  42 import java.net.NetPermission;
  43 import java.util.concurrent.atomic.AtomicReference;
  44 import jdk.internal.misc.JavaSecurityProtectionDomainAccess;
  45 import static jdk.internal.misc.JavaSecurityProtectionDomainAccess.ProtectionDomainCache;
  46 import jdk.internal.misc.SharedSecrets;
  47 import sun.security.util.*;
  48 import sun.net.www.ParseUtil;
  49 
  50 /**
  51  * This class represents a default Policy implementation for the
  52  * "JavaPolicy" type.
  53  *


 288     private static final Class<?>[] PARAMS2 = { String.class, String.class };
 289 
 290     /**
 291      * When a policy file has a syntax error, the exception code may generate
 292      * another permission check and this can cause the policy file to be parsed
 293      * repeatedly, leading to a StackOverflowError or ClassCircularityError.
 294      * To avoid this, this set is populated with policy files that have been
 295      * previously parsed and have syntax errors, so that they can be
 296      * subsequently ignored.
 297      */
 298     private static AtomicReference<Set<URL>> badPolicyURLs =
 299         new AtomicReference<>(new HashSet<>());
 300 
 301     // The default.policy file
 302     private static final URL DEFAULT_POLICY_URL =
 303         AccessController.doPrivileged(new PrivilegedAction<>() {
 304             @Override
 305             public URL run() {
 306                 String sep = File.separator;
 307                 try {
 308                     return Paths.get(System.getProperty("java.home"),
 309                                      "lib", "security",
 310                                      "default.policy").toUri().toURL();
 311                 } catch (MalformedURLException mue) {
 312                     // should not happen
 313                     throw new Error("Malformed default.policy URL: " + mue);
 314                 }
 315             }
 316         });
 317 
 318     /**
 319      * Initializes the Policy object and reads the default policy
 320      * configuration file(s) into the Policy object.
 321      */
 322     public PolicyFile() {
 323         init((URL)null);
 324     }
 325 
 326     /**
 327      * Initializes the Policy object and reads the default policy
 328      * from the specified URL only.




  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package sun.security.provider;
  27 
  28 import java.io.*;
  29 import java.lang.reflect.*;
  30 import java.net.MalformedURLException;
  31 import java.net.URL;
  32 import java.net.URI;
  33 import java.nio.file.Path;
  34 import java.util.*;
  35 import java.security.*;
  36 import java.security.cert.Certificate;
  37 import java.security.cert.X509Certificate;
  38 import javax.security.auth.Subject;
  39 import javax.security.auth.x500.X500Principal;
  40 import java.io.FilePermission;
  41 import java.net.SocketPermission;
  42 import java.net.NetPermission;
  43 import java.util.concurrent.atomic.AtomicReference;
  44 import jdk.internal.misc.JavaSecurityProtectionDomainAccess;
  45 import static jdk.internal.misc.JavaSecurityProtectionDomainAccess.ProtectionDomainCache;
  46 import jdk.internal.misc.SharedSecrets;
  47 import sun.security.util.*;
  48 import sun.net.www.ParseUtil;
  49 
  50 /**
  51  * This class represents a default Policy implementation for the
  52  * "JavaPolicy" type.
  53  *


 288     private static final Class<?>[] PARAMS2 = { String.class, String.class };
 289 
 290     /**
 291      * When a policy file has a syntax error, the exception code may generate
 292      * another permission check and this can cause the policy file to be parsed
 293      * repeatedly, leading to a StackOverflowError or ClassCircularityError.
 294      * To avoid this, this set is populated with policy files that have been
 295      * previously parsed and have syntax errors, so that they can be
 296      * subsequently ignored.
 297      */
 298     private static AtomicReference<Set<URL>> badPolicyURLs =
 299         new AtomicReference<>(new HashSet<>());
 300 
 301     // The default.policy file
 302     private static final URL DEFAULT_POLICY_URL =
 303         AccessController.doPrivileged(new PrivilegedAction<>() {
 304             @Override
 305             public URL run() {
 306                 String sep = File.separator;
 307                 try {
 308                     return Path.get(System.getProperty("java.home"),
 309                                      "lib", "security",
 310                                      "default.policy").toUri().toURL();
 311                 } catch (MalformedURLException mue) {
 312                     // should not happen
 313                     throw new Error("Malformed default.policy URL: " + mue);
 314                 }
 315             }
 316         });
 317 
 318     /**
 319      * Initializes the Policy object and reads the default policy
 320      * configuration file(s) into the Policy object.
 321      */
 322     public PolicyFile() {
 323         init((URL)null);
 324     }
 325 
 326     /**
 327      * Initializes the Policy object and reads the default policy
 328      * from the specified URL only.


< prev index next >