Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2005, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 2024, 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 @@ -46,7 +46,7 @@
* @author K Venugopal
* @author Sunitha Reddy
*
* @LastModified: Nov 2023
* @LastModified: Jan 2024
*/
public class PropertyManager {

Expand Down Expand Up @@ -184,6 +184,9 @@ public boolean containsProperty(String property) {
* @return the value of a property
*/
public Object getProperty(String property) {
if (XMLInputFactory.SUPPORT_DTD.equals(property)) {
return fSecurityManager.is(XMLSecurityManager.Limit.STAX_SUPPORT_DTD);
}
/**
* Check to see if the property is managed by the security manager *
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 2024, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
Expand Down Expand Up @@ -79,7 +79,7 @@
* @author Arnaud Le Hors, IBM
* @author Andy Clark, IBM
*
* @LastModified: July 2023
* @LastModified: Jan 2024
*/
@SuppressWarnings("deprecation")
public abstract class AbstractSAXParser
Expand Down Expand Up @@ -1831,6 +1831,11 @@ else if (featureId.startsWith(XERCES_FEATURES_PREFIX)) {
}
*/

// Handle properties managed by XMLSecurityManager
if (featureId.equals(XMLSecurityManager.DISALLOW_DTD)) {
return securityManager.is(XMLSecurityManager.Limit.XERCES_DISALLOW_DTD);
}

return fConfiguration.getFeature(featureId);
}
catch (XMLConfigurationException e) {
Expand Down
132 changes: 132 additions & 0 deletions test/jaxp/javax/xml/jaxp/unittest/common/dtd/DTDPropertiesTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
/*
* Copyright (c) 2024, 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.
*
* 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 common.dtd;

import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import javax.xml.stream.XMLInputFactory;
import org.testng.Assert;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import org.xml.sax.XMLReader;

/*
* @test
* @bug 8322214
* @library /javax/xml/jaxp/libs /javax/xml/jaxp/unittest
* @run testng common.dtd.DTDPropertiesTest
* @summary Verifies the getProperty function on DTD properties works the same
* as before the property 'jdk.xml.dtd.support' was introduced.
*/
public class DTDPropertiesTest {
// Xerces Property
public static final String DISALLOW_DTD = "http://apache.org/xml/features/disallow-doctype-decl";

/*
* DataProvider for verifying Xerces' disallow-DTD feature
* Fields: property name, setting (null indicates not specified), expected
*/
@DataProvider(name = "XercesProperty")
public Object[][] getXercesProperty() throws Exception {
return new Object[][] {
{ DISALLOW_DTD, null, false},
{ DISALLOW_DTD, true, true},
{ DISALLOW_DTD, false, false},
};
}

/*
* DataProvider for verifying StAX's supportDTD feature
* Fields: property name, setting (null indicates not specified), expected
*/
@DataProvider(name = "StAXProperty")
public Object[][] getStAXProperty() throws Exception {
return new Object[][] {
{ XMLInputFactory.SUPPORT_DTD, null, true},
{ XMLInputFactory.SUPPORT_DTD, true, true},
{ XMLInputFactory.SUPPORT_DTD, false, false},
};
}

/**
* Verifies the disallow DTD feature with SAX.
*
* @param name the name of the property
* @param setting the setting of the property, null means not specified
* @param expected the expected value
* @throws Exception if the test fails
*/
@Test(dataProvider = "XercesProperty")
public void testSAX(String name, Boolean setting, Boolean expected) throws Exception {
SAXParserFactory spf = SAXParserFactory.newDefaultInstance();
if (setting != null) {
spf.setFeature(name, setting);
}
Assert.assertEquals((Boolean)spf.getFeature(name), expected);
System.out.println(spf.getFeature(name));


SAXParser saxParser = spf.newSAXParser();
XMLReader reader = saxParser.getXMLReader();
Assert.assertEquals((Boolean)reader.getFeature(name), expected);
System.out.println(reader.getFeature(name));
}

/**
* Verifies the disallow DTD feature with DOM.
*
* @param name the name of the property
* @param setting the setting of the property, null means not specified
* @param expected the expected value
* @throws Exception if the test fails
*/
@Test(dataProvider = "XercesProperty")
public void testDOM(String name, Boolean setting, Boolean expected) throws Exception {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newDefaultInstance();
if (setting != null) {
dbf.setFeature(name, setting);
}
Assert.assertEquals((Boolean)dbf.getFeature(name), expected);
System.out.println(dbf.getFeature(name));
}

/**
* Verifies the StAX's supportDTD feature.
*
* @param name the name of the property
* @param setting the setting of the property, null means not specified
* @param expected the expected value
* @throws Exception if the test fails
*/
@Test(dataProvider = "StAXProperty")
public void testStAX(String name, Boolean setting, Boolean expected) throws Exception {
XMLInputFactory xif = XMLInputFactory.newInstance();
if (setting != null) {
xif.setProperty(name, setting);
}
Assert.assertEquals((Boolean)xif.getProperty(name), expected);
System.out.println((Boolean)xif.getProperty(name));
}
}