Skip to content

Commit 66f0442

Browse files
committed
8353232: Standardizing and Unifying XML Component Configurations
Reviewed-by: lancea
1 parent 1c5eb37 commit 66f0442

31 files changed

+463
-264
lines changed

src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/trax/TransformerFactoryImpl.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,15 @@
6969
import jdk.xml.internal.FeaturePropertyBase;
7070
import jdk.xml.internal.JdkConstants;
7171
import jdk.xml.internal.JdkProperty;
72+
import jdk.xml.internal.JdkXmlConfig;
7273
import jdk.xml.internal.JdkXmlFeatures;
7374
import jdk.xml.internal.JdkXmlUtils;
7475
import jdk.xml.internal.JdkProperty.ImplPropMap;
7576
import jdk.xml.internal.JdkProperty.State;
7677
import jdk.xml.internal.TransformErrorListener;
7778
import jdk.xml.internal.XMLSecurityManager;
78-
import jdk.xml.internal.XMLSecurityPropertyManager.Property;
7979
import jdk.xml.internal.XMLSecurityPropertyManager;
80+
import jdk.xml.internal.XMLSecurityPropertyManager.Property;
8081
import org.xml.sax.InputSource;
8182
import org.xml.sax.SAXException;
8283
import org.xml.sax.XMLFilter;
@@ -87,7 +88,7 @@
8788
* @author G. Todd Miller
8889
* @author Morten Jorgensen
8990
* @author Santiago Pericas-Geertsen
90-
* @LastModified: Apr 2025
91+
* @LastModified: May 2025
9192
*/
9293
public class TransformerFactoryImpl
9394
extends SAXTransformerFactory implements SourceLoader
@@ -265,17 +266,18 @@ public PIParamWrapper(String media, String title, String charset) {
265266
* javax.xml.transform.sax.TransformerFactory implementation.
266267
*/
267268
public TransformerFactoryImpl() {
268-
_xmlFeatures = new JdkXmlFeatures(!_isNotSecureProcessing);
269+
JdkXmlConfig config = JdkXmlConfig.getInstance(false);
270+
// security (property) managers updated with current system properties
271+
_xmlSecurityManager = config.getXMLSecurityManager(true);
272+
_xmlSecurityPropertyMgr = config.getXMLSecurityPropertyManager(true);
273+
_xmlFeatures = config.getXMLFeatures(true);
269274
_overrideDefaultParser = _xmlFeatures.getFeature(
270275
JdkXmlFeatures.XmlFeature.JDK_OVERRIDE_PARSER);
271-
_xmlSecurityPropertyMgr = new XMLSecurityPropertyManager();
272276
_accessExternalDTD = _xmlSecurityPropertyMgr.getValue(
273277
Property.ACCESS_EXTERNAL_DTD);
274278
_accessExternalStylesheet = _xmlSecurityPropertyMgr.getValue(
275279
Property.ACCESS_EXTERNAL_STYLESHEET);
276280

277-
//Parser's security manager
278-
_xmlSecurityManager = new XMLSecurityManager(true);
279281
//Unmodifiable hash map with loaded external extension functions
280282
_xsltcExtensionFunctions = null;
281283
_extensionClassLoader = new JdkProperty<>(ImplPropMap.EXTCLSLOADER,

src/java.xml/share/classes/com/sun/org/apache/xerces/internal/dom/DOMConfigurationImpl.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
import javax.xml.XMLConstants;
5454
import javax.xml.catalog.CatalogFeatures;
5555
import jdk.xml.internal.JdkConstants;
56+
import jdk.xml.internal.JdkXmlConfig;
5657
import jdk.xml.internal.JdkXmlUtils;
5758
import jdk.xml.internal.XMLSecurityManager;
5859
import jdk.xml.internal.XMLSecurityPropertyManager;
@@ -71,7 +72,7 @@
7172
*
7273
* @author Elena Litani, IBM
7374
* @author Neeraj Bajaj, Sun Microsystems.
74-
* @LastModified: Apr 2025
75+
* @LastModified: May 2025
7576
*/
7677
public class DOMConfigurationImpl extends ParserConfigurationSettings
7778
implements XMLParserConfiguration, DOMConfiguration {
@@ -414,10 +415,10 @@ protected DOMConfigurationImpl(SymbolTable symbolTable,
414415
fValidationManager = createValidationManager();
415416
setProperty(VALIDATION_MANAGER, fValidationManager);
416417

417-
setProperty(SECURITY_MANAGER, new XMLSecurityManager(true));
418+
setProperty(SECURITY_MANAGER, JdkXmlConfig.getInstance(false).getXMLSecurityManager(false));
418419

419420
setProperty(JdkConstants.XML_SECURITY_PROPERTY_MANAGER,
420-
new XMLSecurityPropertyManager());
421+
JdkXmlConfig.getInstance(false).getXMLSecurityPropertyManager(false));
421422

422423
// add message formatters
423424
if (fErrorReporter.getMessageFormatter(XMLMessageFormatter.XML_DOMAIN) == null) {

src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/PropertyManager.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import javax.xml.stream.XMLOutputFactory;
3232
import javax.xml.stream.XMLResolver;
3333
import jdk.xml.internal.JdkConstants;
34+
import jdk.xml.internal.JdkXmlConfig;
3435
import jdk.xml.internal.JdkXmlUtils;
3536
import jdk.xml.internal.XMLSecurityManager;
3637
import jdk.xml.internal.XMLSecurityPropertyManager;
@@ -44,7 +45,7 @@
4445
* @author K Venugopal
4546
* @author Sunitha Reddy
4647
*
47-
* @LastModified: Apr 2025
48+
* @LastModified: May 2025
4849
*/
4950
public class PropertyManager {
5051

@@ -66,6 +67,7 @@ public class PropertyManager {
6667

6768
HashMap<String, Object> supportedProps = new HashMap<>();
6869

70+
JdkXmlConfig config = JdkXmlConfig.getInstance(true);
6971
private XMLSecurityManager fSecurityManager;
7072
private XMLSecurityPropertyManager fSecurityPropertyMgr;
7173

@@ -141,9 +143,9 @@ private void initConfigurableReaderProperties() {
141143
supportedProps.put(Constants.XERCES_FEATURE_PREFIX + Constants.WARN_ON_DUPLICATE_ENTITYDEF_FEATURE, false);
142144
supportedProps.put(Constants.XERCES_FEATURE_PREFIX + Constants.WARN_ON_UNDECLARED_ELEMDEF_FEATURE, false);
143145

144-
fSecurityManager = new XMLSecurityManager(true);
146+
fSecurityManager = config.getXMLSecurityManager(true);
147+
fSecurityPropertyMgr = config.getXMLSecurityPropertyManager(true);
145148
supportedProps.put(SECURITY_MANAGER, fSecurityManager);
146-
fSecurityPropertyMgr = new XMLSecurityPropertyManager();
147149
supportedProps.put(XML_SECURITY_PROPERTY_MANAGER, fSecurityPropertyMgr);
148150

149151
// Initialize Catalog features
@@ -232,7 +234,7 @@ public void setProperty(String property, Object value) {
232234
}
233235
if (property.equals(JdkConstants.XML_SECURITY_PROPERTY_MANAGER)) {
234236
if (value == null) {
235-
fSecurityPropertyMgr = new XMLSecurityPropertyManager();
237+
fSecurityPropertyMgr = config.getXMLSecurityPropertyManager(true);
236238
} else {
237239
fSecurityPropertyMgr = (XMLSecurityPropertyManager) value;
238240
}

src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/XMLEntityManager.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,14 @@
4949
import java.util.StringTokenizer;
5050
import javax.xml.XMLConstants;
5151
import javax.xml.catalog.CatalogException;
52-
import javax.xml.catalog.CatalogFeatures.Feature;
5352
import javax.xml.catalog.CatalogFeatures;
5453
import javax.xml.catalog.CatalogManager;
5554
import javax.xml.catalog.CatalogResolver;
5655
import javax.xml.stream.XMLInputFactory;
5756
import javax.xml.transform.Source;
58-
import jdk.xml.internal.JdkCatalog;
5957
import jdk.xml.internal.JdkConstants;
6058
import jdk.xml.internal.JdkProperty;
59+
import jdk.xml.internal.JdkXmlConfig;
6160
import jdk.xml.internal.JdkXmlUtils;
6261
import jdk.xml.internal.SecuritySupport;
6362
import jdk.xml.internal.XMLLimitAnalyzer;
@@ -94,7 +93,7 @@
9493
* @author K.Venugopal SUN Microsystems
9594
* @author Neeraj Bajaj SUN Microsystems
9695
* @author Sunitha Reddy SUN Microsystems
97-
* @LastModified: Apr 2025
96+
* @LastModified: May 2025
9897
*/
9998
public class XMLEntityManager implements XMLComponent, XMLEntityResolver {
10099

@@ -436,7 +435,7 @@ public class XMLEntityManager implements XMLComponent, XMLEntityResolver {
436435
* If this constructor is used to create the object, reset() should be invoked on this object
437436
*/
438437
public XMLEntityManager() {
439-
this(null, new XMLSecurityManager(true));
438+
this(null, JdkXmlConfig.getInstance(false).getXMLSecurityManager(false));
440439
}
441440

442441
public XMLEntityManager(XMLSecurityPropertyManager securityPropertyMgr, XMLSecurityManager securityManager) {
@@ -1055,7 +1054,7 @@ public StaxXMLInputSource resolveEntityAsPerStax(XMLResourceIdentifier resourceI
10551054
&& JdkXmlUtils.isResolveContinue(fCatalogFeatures)) {
10561055
initJdkCatalogResolver();
10571056

1058-
staxInputSource = resolveWithCatalogStAX(fDefCR, JdkCatalog.JDKCATALOG, publicId, literalSystemId);
1057+
staxInputSource = resolveWithCatalogStAX(fDefCR, JdkXmlConfig.JDKCATALOG_FILE, publicId, literalSystemId);
10591058
}
10601059

10611060
// Step 4: default resolution if not resolved by a resolver and the RESOLVE
@@ -1697,7 +1696,7 @@ public void reset(XMLComponentManager componentManager)
16971696
// JAXP 1.5 feature
16981697
XMLSecurityPropertyManager spm = (XMLSecurityPropertyManager) componentManager.getProperty(XML_SECURITY_PROPERTY_MANAGER, null);
16991698
if (spm == null) {
1700-
spm = new XMLSecurityPropertyManager();
1699+
spm = JdkXmlConfig.getInstance(false).getXMLSecurityPropertyManager(false);
17011700
}
17021701
fAccessExternalDTD = spm.getValue(XMLSecurityPropertyManager.Property.ACCESS_EXTERNAL_DTD);
17031702

src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/xs/XMLSchemaLoader.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
import java.util.WeakHashMap;
7575
import javax.xml.XMLConstants;
7676
import jdk.xml.internal.JdkConstants;
77+
import jdk.xml.internal.JdkXmlConfig;
7778
import jdk.xml.internal.JdkXmlUtils;
7879
import jdk.xml.internal.XMLSecurityManager;
7980
import jdk.xml.internal.XMLSecurityPropertyManager;
@@ -102,7 +103,7 @@
102103
* @xerces.internal
103104
*
104105
* @author Neil Graham, IBM
105-
* @LastModified: Apr 2025
106+
* @LastModified: May 2025
106107
*/
107108

108109
public class XMLSchemaLoader implements XMLGrammarLoader, XMLComponent, XSElementDeclHelper,
@@ -1001,13 +1002,13 @@ public void reset(XMLComponentManager componentManager) throws XMLConfigurationE
10011002

10021003
XMLSecurityPropertyManager spm = (XMLSecurityPropertyManager)componentManager.getProperty(XML_SECURITY_PROPERTY_MANAGER);
10031004
if (spm == null) {
1004-
spm = new XMLSecurityPropertyManager();
1005+
spm = JdkXmlConfig.getInstance(false).getXMLSecurityPropertyManager(false);
10051006
setProperty(XML_SECURITY_PROPERTY_MANAGER, spm);
10061007
}
10071008

10081009
XMLSecurityManager sm = (XMLSecurityManager)componentManager.getProperty(SECURITY_MANAGER);
10091010
if (sm == null)
1010-
setProperty(SECURITY_MANAGER,new XMLSecurityManager(true));
1011+
setProperty(SECURITY_MANAGER, JdkXmlConfig.getInstance(false).getXMLSecurityManager(false));
10111012

10121013
faccessExternalSchema = spm.getValue(XMLSecurityPropertyManager.Property.ACCESS_EXTERNAL_SCHEMA);
10131014

src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/xs/traversers/XSDHandler.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@
105105
import javax.xml.stream.XMLStreamException;
106106
import javax.xml.stream.XMLStreamReader;
107107
import jdk.xml.internal.JdkConstants;
108+
import jdk.xml.internal.JdkXmlConfig;
108109
import jdk.xml.internal.JdkXmlUtils;
109110
import jdk.xml.internal.SecuritySupport;
110111
import jdk.xml.internal.XMLSecurityManager;
@@ -131,7 +132,7 @@
131132
* @author Neil Graham, IBM
132133
* @author Pavani Mukthipudi, Sun Microsystems
133134
*
134-
* @LastModified: Apr 2025
135+
* @LastModified: May 2025
135136
*/
136137
public class XSDHandler {
137138

@@ -735,7 +736,8 @@ private void createAnnotationValidator() {
735736
fAnnotationValidator.setFeature(XMLSCHEMA_VALIDATION, true);
736737
fAnnotationValidator.setProperty(XMLGRAMMAR_POOL, fGrammarBucketAdapter);
737738
/** set security manager and XML Security Property Manager **/
738-
fAnnotationValidator.setProperty(SECURITY_MANAGER, (fSecurityManager != null) ? fSecurityManager : new XMLSecurityManager(true));
739+
fAnnotationValidator.setProperty(SECURITY_MANAGER,
740+
(fSecurityManager != null) ? fSecurityManager : JdkXmlConfig.getInstance(false).getXMLSecurityManager(false));
739741
fAnnotationValidator.setProperty(XML_SECURITY_PROPERTY_MANAGER, fSecurityPropertyMgr);
740742
/** Set error handler. **/
741743
fAnnotationValidator.setProperty(ERROR_HANDLER, (fErrorHandler != null) ? fErrorHandler : new DefaultErrorHandler());

src/java.xml/share/classes/com/sun/org/apache/xerces/internal/jaxp/DocumentBuilderFactoryImpl.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
import javax.xml.parsers.DocumentBuilderFactory;
3030
import javax.xml.parsers.ParserConfigurationException;
3131
import javax.xml.validation.Schema;
32+
33+
import jdk.xml.internal.JdkXmlConfig;
3234
import jdk.xml.internal.JdkXmlUtils;
3335
import jdk.xml.internal.XMLSecurityManager;
3436
import jdk.xml.internal.XMLSecurityPropertyManager;
@@ -39,7 +41,7 @@
3941
/**
4042
* @author Rajiv Mordani
4143
* @author Edwin Goei
42-
* @LastModified: Apr 2025
44+
* @LastModified: May 2025
4345
*/
4446
public class DocumentBuilderFactoryImpl extends DocumentBuilderFactory {
4547
/** These are DocumentBuilderFactory attributes not DOM attributes */
@@ -54,8 +56,15 @@ public class DocumentBuilderFactoryImpl extends DocumentBuilderFactory {
5456
private boolean fSecureProcess = true;
5557

5658
// used to verify attributes
57-
XMLSecurityManager fSecurityManager = new XMLSecurityManager(true);
58-
XMLSecurityPropertyManager fSecurityPropertyMgr = new XMLSecurityPropertyManager();
59+
XMLSecurityManager fSecurityManager;
60+
XMLSecurityPropertyManager fSecurityPropertyMgr;
61+
62+
public DocumentBuilderFactoryImpl() {
63+
JdkXmlConfig config = JdkXmlConfig.getInstance(false);
64+
// security (property) managers updated with current system properties
65+
fSecurityManager = config.getXMLSecurityManager(true);
66+
fSecurityPropertyMgr = config.getXMLSecurityPropertyManager(true);
67+
}
5968

6069
/**
6170
* Creates a new instance of a {@link javax.xml.parsers.DocumentBuilder}

src/java.xml/share/classes/com/sun/org/apache/xerces/internal/jaxp/DocumentBuilderImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
/**
6060
* @author Rajiv Mordani
6161
* @author Edwin Goei
62-
* @LastModified: Apr 2025
62+
* @LastModified: May 2025
6363
*/
6464
public class DocumentBuilderImpl extends DocumentBuilder
6565
implements JAXPConstants
@@ -140,7 +140,7 @@ public class DocumentBuilderImpl extends DocumentBuilder
140140
{
141141
domParser = new DOMParser();
142142

143-
fSecurityPropertyMgr = new XMLSecurityPropertyManager();
143+
fSecurityPropertyMgr = dbf.fSecurityPropertyMgr;
144144
domParser.setProperty(XML_SECURITY_PROPERTY_MANAGER, fSecurityPropertyMgr);
145145

146146
fSecurityManager = dbf.fSecurityManager;

src/java.xml/share/classes/com/sun/org/apache/xerces/internal/jaxp/SAXParserFactoryImpl.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import javax.xml.parsers.SAXParser;
2929
import javax.xml.parsers.SAXParserFactory;
3030
import javax.xml.validation.Schema;
31+
import jdk.xml.internal.JdkXmlConfig;
3132
import jdk.xml.internal.XMLSecurityManager;
3233
import jdk.xml.internal.XMLSecurityPropertyManager;
3334
import org.xml.sax.SAXException;
@@ -42,7 +43,7 @@
4243
* @author Rajiv Mordani
4344
* @author Edwin Goei
4445
*
45-
* @LastModified: Apr 2025
46+
* @LastModified: May 2025
4647
*/
4748
public class SAXParserFactoryImpl extends SAXParserFactory {
4849

@@ -68,8 +69,14 @@ public class SAXParserFactoryImpl extends SAXParserFactory {
6869
private boolean fSecureProcess = true;
6970

7071
// Security Managers
71-
XMLSecurityManager fSecurityManager = new XMLSecurityManager(true);
72-
XMLSecurityPropertyManager fSecurityPropertyMgr = new XMLSecurityPropertyManager();
72+
XMLSecurityManager fSecurityManager;
73+
XMLSecurityPropertyManager fSecurityPropertyMgr;
74+
75+
public SAXParserFactoryImpl() {
76+
JdkXmlConfig config = JdkXmlConfig.getInstance(false);
77+
fSecurityManager = config.getXMLSecurityManager(true);
78+
fSecurityPropertyMgr = config.getXMLSecurityPropertyManager(true);
79+
}
7380

7481
/**
7582
* Creates a new instance of <code>SAXParser</code> using the currently

src/java.xml/share/classes/com/sun/org/apache/xerces/internal/jaxp/SAXParserImpl.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import javax.xml.validation.Schema;
4444
import jdk.xml.internal.FeaturePropertyBase;
4545
import jdk.xml.internal.JdkConstants;
46+
import jdk.xml.internal.JdkXmlConfig;
4647
import jdk.xml.internal.JdkXmlUtils;
4748
import jdk.xml.internal.XMLSecurityManager;
4849
import jdk.xml.internal.XMLSecurityPropertyManager;
@@ -64,7 +65,7 @@
6465
* @author Rajiv Mordani
6566
* @author Edwin Goei
6667
*
67-
* @LastModified: Apr 2025
68+
* @LastModified: May 2025
6869
*/
6970
@SuppressWarnings("deprecation")
7071
public class SAXParserImpl extends javax.xml.parsers.SAXParser
@@ -412,7 +413,7 @@ public JAXPSAXParser() {
412413
* it is null.
413414
*/
414415
if (fSecurityManager == null) {
415-
fSecurityManager = new XMLSecurityManager(true);
416+
fSecurityManager = JdkXmlConfig.getInstance(false).getXMLSecurityManager(false);
416417
}
417418
try {
418419
super.setProperty(SECURITY_MANAGER, fSecurityManager);
@@ -423,7 +424,7 @@ public JAXPSAXParser() {
423424
}
424425

425426
if (fSecurityPropertyMgr == null) {
426-
fSecurityPropertyMgr = new XMLSecurityPropertyManager();
427+
fSecurityPropertyMgr = JdkXmlConfig.getInstance(false).getXMLSecurityPropertyManager(false);
427428
}
428429
try {
429430
super.setProperty(XML_SECURITY_PROPERTY_MANAGER, fSecurityPropertyMgr);

src/java.xml/share/classes/com/sun/org/apache/xerces/internal/jaxp/validation/StreamValidatorHelper.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2013, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2013, 2025, Oracle and/or its affiliates. All rights reserved.
33
*/
44
/*
55
* Licensed to the Apache Software Foundation (ASF) under one or more
@@ -23,6 +23,7 @@
2323
import com.sun.org.apache.xerces.internal.impl.XMLErrorReporter;
2424
import com.sun.org.apache.xerces.internal.impl.msg.XMLMessageFormatter;
2525
import com.sun.org.apache.xerces.internal.parsers.XML11Configuration;
26+
import jdk.xml.internal.JdkXmlConfig;
2627
import jdk.xml.internal.XMLSecurityManager;
2728
import com.sun.org.apache.xerces.internal.xni.XNIException;
2829
import com.sun.org.apache.xerces.internal.xni.parser.XMLInputSource;
@@ -49,7 +50,7 @@
4950
*
5051
* @author Michael Glavassevich, IBM
5152
* @author Sunitha Reddy
52-
* @LastModified: July 2023
53+
* @LastModified: May 2025
5354
*/
5455
final class StreamValidatorHelper implements ValidatorHelper {
5556

@@ -190,7 +191,7 @@ else if (fComponentManager.getFeature(PARSER_SETTINGS)) {
190191
private XMLParserConfiguration initialize() {
191192
XML11Configuration config = new XML11Configuration();
192193
if (fComponentManager.getFeature(XMLConstants.FEATURE_SECURE_PROCESSING)) {
193-
config.setProperty(SECURITY_MANAGER, new XMLSecurityManager());
194+
config.setProperty(SECURITY_MANAGER, JdkXmlConfig.getInstance(false).getXMLSecurityManager(false));
194195
}
195196
config.setProperty(ENTITY_RESOLVER, fComponentManager.getProperty(ENTITY_RESOLVER));
196197
config.setProperty(ERROR_HANDLER, fComponentManager.getProperty(ERROR_HANDLER));

0 commit comments

Comments
 (0)