Skip to content

Commit

Permalink
add a template instead of a property file; remove implNote; update te…
Browse files Browse the repository at this point in the history
…st and make script accordingly.
  • Loading branch information
JoeWang-Java committed May 24, 2024
1 parent dd7f623 commit 0de8ad6
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 54 deletions.
5 changes: 3 additions & 2 deletions make/modules/java.xml/Copy.gmk
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@ include Modules.gmk

################################################################################
#
# Copy property files from share/conf to CONF_DST_DIR
# Copy property file and template from share/conf to CONF_DST_DIR
#
$(eval $(call SetupCopyFiles, COPY_XML_MODULE_CONF, \
DEST := $(CONF_DST_DIR), \
FILES := $(wildcard $(TOPDIR)/src/java.xml/share/conf/jaxp*.properties*), \
SRC := $(TOPDIR)/src/java.xml/share/conf, \
FILES := jaxp.properties jaxp-strict.template, \
))

TARGETS += $(COPY_XML_MODULE_CONF)
Expand Down
35 changes: 1 addition & 34 deletions src/java.xml/share/classes/module-info.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2023, 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
Expand Down Expand Up @@ -402,13 +402,6 @@
* @implNote
*
* <ul>
* <li><a href="#IN_CF">JAXP Configuration Files</a>
* <ul>
* <li><a href="#IN_CF_DEFAULT">{@code jaxp.properties}</a></li>
* <li><a href="#IN_CF_STRICT">{@code jaxp-strict.properties}</a></li>
* </ul>
* </li>
* <li><a href="#JDKCATALOG">JDK built-in Catalog</a>
* <ul>
* <li><a href="#JC_PROCESS">External Resource Resolution Process with the built-in Catalog</a></li>
Expand All @@ -423,32 +416,6 @@
* </li>
* </ul>
*
* <h2 id="IN_CF">JAXP Configuration Files</h2>
* The JDK provides two <a href="#Conf_CF">JAXP Configuration Files</a>:
*
* <ul>
* <li id="IN_CF_DEFAULT"><a href="#Conf_CF_Default">{@code jaxp.properties}</a>:
* the default configuration that the JDK uses to set property values when XML
* factories are initiated.</li>
*
* <li id="IN_CF_STRICT">{@code jaxp-strict.properties}: a configuration that
* contains more restrictive settings than the default {@code jaxp.properties}.
* In particular:
* <ul>
* <li><a href="#JDKCATALOG_RESOLVE">JDKCatalog Resolve</a> is on "strict" setting </li>
* <li><a href="#ExtFunc">Extension Functions</a> are disabled </li>
* <li><a href="#EELimit">JAXP Limits</a> are set to smaller numbers </li>
* </ul>
*
* Deploying with this configuration prevents processors from unknowingly making
* outbound network connections to fetch DTDs, or processing XML that makes use of
* extension functions.
* </li>
* </ul>
*
* The configuration settings in these properties files are subject to change
* from release to release.
*
* <h2 id="JDKCATALOG">JDK built-in Catalog</h2>
* The JDK has a built-in catalog that hosts the following DTDs defined by the Java Platform:
* <ul>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
################################################################################
# JAXP Strict Configuration File
# JAXP Strict Configuration Template
#
# This property file, jaxp-strict.properties, represents a more secure configuration
# for XML processing. It provides settings that are more restrictive than the
# current default jaxp.properties. In particular:
# This file, jaxp-strict.template, provides a template for creating custom
# configuration files. The settings in this file are more restrictive than those
# in the default configuration, jaxp.properties. In particular:
# - JDKCatalog Resolve is on "strict" setting
# - Extension Functions are disabled
# - JAXP Limits are set to smaller numbers
#
# This configuration file can be set up using the system property
# To create a configuration file, copy the template to a new file with
# the .properties extension, that is:
#
# cp $JAVA_HOME/conf/jaxp-strict.template /path/to/jaxp-strict.properties
#
# The configuration file can then be set up using the system property
# java.xml.config.file to override the default configuration jaxp.properties
# and used to assess the impact of a stricter configuration, for example:
#
# java -Djava.xml.config.file=$JAVA_HOME/conf/jaxp-strict.properties
# java -Djava.xml.config.file=/path/to/jaxp-strict.properties
#
# The system property java.xml.config.file is defined in the java.xml module
# description.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
import common.util.TestBase;
import static common.util.TestBase.CONFIG_DEFAULT;
import static common.util.TestBase.CONFIG_STRICT;
import static common.util.TestBase.CONFIG_TEMPLATE_STRICT;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.stream.IntStream;
import javax.xml.transform.TransformerFactory;

Expand All @@ -33,13 +37,15 @@
* @library /javax/xml/jaxp/libs /javax/xml/jaxp/unittest
* @modules java.xml/jdk.xml.internal
* @run driver common.config.ConfigFileTest 0 // verifies jaxp.properties
* @run driver common.config.ConfigFileTest 1 // verifies jaxp-strict.properties
* @summary verifies the JAXP configuration files jaxp.properties and
* jaxp-strict.properties.
* @run driver common.config.ConfigFileTest 1 // verifies jaxp-strict.template
* @summary verifies the default JAXP configuration file jaxp.properties and
* strict template jaxp-strict.template.
*/
public class ConfigFileTest {
// system property for custom configuration file
static final String SP_CONFIG = "java.xml.config.file";
// target directory
static String TEST_DIR = System.getProperty("test.classes");

// properties in the configuration file
String[] keys = {
Expand All @@ -64,7 +70,7 @@ public class ConfigFileTest {
boolean[] propertyIsFeature ={true, true, false, false, false, false,
false, false, false, false, false, false, false, false, false, false};

// values from jaxp-strict.properties
// values from jaxp-strict.template
String[] strictValues ={"false", "false", "strict", "allow", "2500", "100000",
"100000", "15000", "100000", "10000", "5000", "0", "1000", "10", "100", "10000"};

Expand All @@ -77,10 +83,13 @@ public static void main(String args[]) throws Exception {
}

public void run(String index) throws Exception {
String conf = System.getProperty("java.home") + "/conf/";
if (index.equals("0")) {
verifyConfig(CONFIG_DEFAULT, defaultValues);
verifyConfig(conf + CONFIG_DEFAULT, defaultValues);
} else {
verifyConfig(CONFIG_STRICT, strictValues);
Path config = Paths.get(TEST_DIR, CONFIG_STRICT);
Files.copy(Paths.get(conf, CONFIG_TEMPLATE_STRICT), config);
verifyConfig(config.toString(), strictValues);
}
}

Expand All @@ -90,8 +99,7 @@ public void run(String index) throws Exception {
* @param values expected values in the configuration file
*/
private void verifyConfig(String filename, String[] values) {
String javaHome = System.getProperty("java.home");
System.setProperty(SP_CONFIG, javaHome + "/conf/" + filename);
System.setProperty(SP_CONFIG, filename);

TransformerFactory tf = TransformerFactory.newInstance();
IntStream.range(0, keys.length).forEach(i -> {
Expand Down
5 changes: 1 addition & 4 deletions test/jaxp/javax/xml/jaxp/unittest/common/util/TestBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public class TestBase {
// JAXP Configuration Files to be added to $JAVA_HOME/conf/
public static final String CONFIG_DEFAULT = "jaxp.properties";
public static final String CONFIG_STRICT = "jaxp-strict.properties";
public static final String CONFIG_COMPAT = "jaxp-compat.properties";
public static final String CONFIG_TEMPLATE_STRICT = "jaxp-strict.template";

public static final String UNKNOWN_HOST = "invalid.site.com";

Expand All @@ -139,9 +139,6 @@ public static enum Properties {
// config file: CATALOG = strict
CONFIG_FILE_CATALOG_STRICT(null, CONFIG_FILE, Type.FEATURE, getPath(CONFIG_FILE_PATH, CONFIG_CATALOG_STRICT)),
CONFIG_FILE_DTD2(null, CONFIG_FILE, Type.FEATURE, getPath(CONFIG_FILE_PATH, JCF_DTD2)),
// JAXP Configuration Files to be added to $JAVA_HOME/conf/
CONFIG_FILE_STRICT(null, CONFIG_FILE, Type.FEATURE, getPath(CONFIG_FILE_PATH, CONFIG_STRICT)),
CONFIG_FILE_COMPAT(null, CONFIG_FILE, Type.FEATURE, getPath(CONFIG_FILE_PATH, CONFIG_COMPAT)),

FSP(XMLConstants.FEATURE_SECURE_PROCESSING, null, Type.FEATURE, "true"),
FSP_FALSE(XMLConstants.FEATURE_SECURE_PROCESSING, null, Type.FEATURE, "false"),
Expand Down

0 comments on commit 0de8ad6

Please sign in to comment.