Skip to content

Commit

Permalink
8265248: Implementation Specific Properties: change prefix, plus add …
Browse files Browse the repository at this point in the history
…existing properties

Reviewed-by: lancea, rriggs
  • Loading branch information
JoeWang-Java committed May 26, 2021
1 parent c59484e commit 8c4719a
Show file tree
Hide file tree
Showing 60 changed files with 1,994 additions and 1,101 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 2021, 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 All @@ -25,12 +25,13 @@

package com.sun.org.apache.xalan.internal.utils;

import com.sun.org.apache.xalan.internal.XalanConstants;
import jdk.xml.internal.JdkConstants;
import jdk.xml.internal.SecuritySupport;

/**
* This is the base class for features and properties
*
* @LastModified: May 2021
*/
public abstract class FeaturePropertyBase {

Expand Down Expand Up @@ -113,9 +114,9 @@ public boolean setValue(String propertyName, State state, boolean value) {
int index = getIndex(propertyName);
if (index > -1) {
if (value) {
setValue(index, state, XalanConstants.FEATURE_TRUE);
setValue(index, state, JdkConstants.FEATURE_TRUE);
} else {
setValue(index, state, XalanConstants.FEATURE_FALSE);
setValue(index, state, JdkConstants.FEATURE_FALSE);
}
return true;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2021, 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 All @@ -25,8 +25,10 @@

package com.sun.org.apache.xalan.internal.utils;

import com.sun.org.apache.xalan.internal.XalanConstants;
import java.util.concurrent.CopyOnWriteArrayList;
import jdk.xml.internal.JdkConstants;
import jdk.xml.internal.JdkProperty.ImplPropMap;
import jdk.xml.internal.JdkProperty.State;
import jdk.xml.internal.SecuritySupport;
import org.xml.sax.SAXException;

Expand All @@ -41,51 +43,30 @@
*/
public final class XMLSecurityManager {

/**
* States of the settings of a property, in the order: default value, value
* set by FEATURE_SECURE_PROCESSING, jaxp.properties file, jaxp system
* properties, and jaxp api properties
*/
public static enum State {
//this order reflects the overriding order

DEFAULT("default"), FSP("FEATURE_SECURE_PROCESSING"),
JAXPDOTPROPERTIES("jaxp.properties"), SYSTEMPROPERTY("system property"),
APIPROPERTY("property");

final String literal;
State(String literal) {
this.literal = literal;
}

String literal() {
return literal;
}
}

/**
* Limits managed by the security manager
*/
@SuppressWarnings("deprecation")
public static enum Limit {

ENTITY_EXPANSION_LIMIT("EntityExpansionLimit", XalanConstants.JDK_ENTITY_EXPANSION_LIMIT,
XalanConstants.SP_ENTITY_EXPANSION_LIMIT, 0, 64000),
MAX_OCCUR_NODE_LIMIT("MaxOccurLimit", XalanConstants.JDK_MAX_OCCUR_LIMIT,
XalanConstants.SP_MAX_OCCUR_LIMIT, 0, 5000),
ELEMENT_ATTRIBUTE_LIMIT("ElementAttributeLimit", XalanConstants.JDK_ELEMENT_ATTRIBUTE_LIMIT,
XalanConstants.SP_ELEMENT_ATTRIBUTE_LIMIT, 0, 10000),
TOTAL_ENTITY_SIZE_LIMIT("TotalEntitySizeLimit", XalanConstants.JDK_TOTAL_ENTITY_SIZE_LIMIT,
XalanConstants.SP_TOTAL_ENTITY_SIZE_LIMIT, 0, 50000000),
GENERAL_ENTITY_SIZE_LIMIT("MaxEntitySizeLimit", XalanConstants.JDK_GENERAL_ENTITY_SIZE_LIMIT,
XalanConstants.SP_GENERAL_ENTITY_SIZE_LIMIT, 0, 0),
PARAMETER_ENTITY_SIZE_LIMIT("MaxEntitySizeLimit", XalanConstants.JDK_PARAMETER_ENTITY_SIZE_LIMIT,
XalanConstants.SP_PARAMETER_ENTITY_SIZE_LIMIT, 0, 1000000),
MAX_ELEMENT_DEPTH_LIMIT("MaxElementDepthLimit", XalanConstants.JDK_MAX_ELEMENT_DEPTH,
XalanConstants.SP_MAX_ELEMENT_DEPTH, 0, 0),
MAX_NAME_LIMIT("MaxXMLNameLimit", XalanConstants.JDK_XML_NAME_LIMIT,
XalanConstants.SP_XML_NAME_LIMIT, 1000, 1000),
ENTITY_REPLACEMENT_LIMIT("EntityReplacementLimit", XalanConstants.JDK_ENTITY_REPLACEMENT_LIMIT,
XalanConstants.SP_ENTITY_REPLACEMENT_LIMIT, 0, 3000000);
ENTITY_EXPANSION_LIMIT("EntityExpansionLimit", JdkConstants.JDK_ENTITY_EXPANSION_LIMIT,
JdkConstants.SP_ENTITY_EXPANSION_LIMIT, 0, 64000),
MAX_OCCUR_NODE_LIMIT("MaxOccurLimit", JdkConstants.JDK_MAX_OCCUR_LIMIT,
JdkConstants.SP_MAX_OCCUR_LIMIT, 0, 5000),
ELEMENT_ATTRIBUTE_LIMIT("ElementAttributeLimit", JdkConstants.JDK_ELEMENT_ATTRIBUTE_LIMIT,
JdkConstants.SP_ELEMENT_ATTRIBUTE_LIMIT, 0, 10000),
TOTAL_ENTITY_SIZE_LIMIT("TotalEntitySizeLimit", JdkConstants.JDK_TOTAL_ENTITY_SIZE_LIMIT,
JdkConstants.SP_TOTAL_ENTITY_SIZE_LIMIT, 0, 50000000),
GENERAL_ENTITY_SIZE_LIMIT("MaxEntitySizeLimit", JdkConstants.JDK_GENERAL_ENTITY_SIZE_LIMIT,
JdkConstants.SP_GENERAL_ENTITY_SIZE_LIMIT, 0, 0),
PARAMETER_ENTITY_SIZE_LIMIT("MaxEntitySizeLimit", JdkConstants.JDK_PARAMETER_ENTITY_SIZE_LIMIT,
JdkConstants.SP_PARAMETER_ENTITY_SIZE_LIMIT, 0, 1000000),
MAX_ELEMENT_DEPTH_LIMIT("MaxElementDepthLimit", JdkConstants.JDK_MAX_ELEMENT_DEPTH,
JdkConstants.SP_MAX_ELEMENT_DEPTH, 0, 0),
MAX_NAME_LIMIT("MaxXMLNameLimit", JdkConstants.JDK_XML_NAME_LIMIT,
JdkConstants.SP_XML_NAME_LIMIT, 1000, 1000),
ENTITY_REPLACEMENT_LIMIT("EntityReplacementLimit", JdkConstants.JDK_ENTITY_REPLACEMENT_LIMIT,
JdkConstants.SP_ENTITY_REPLACEMENT_LIMIT, 0, 3000000);

final String key;
final String apiProperty;
Expand All @@ -101,12 +82,36 @@ public static enum Limit {
this.secureValue = secureValue;
}

public boolean equalsAPIPropertyName(String propertyName) {
return (propertyName == null) ? false : apiProperty.equals(propertyName);
/**
* Checks whether the specified name is a limit. Checks both the
* property and System Property which is now the new property name.
*
* @param name the specified name
* @return true if there is a match, false otherwise
*/
public boolean is(String name) {
// current spec: new property name == systemProperty
return (systemProperty != null && systemProperty.equals(name)) ||
// current spec: apiProperty is legacy
(apiProperty.equals(name));
}

public boolean equalsSystemPropertyName(String propertyName) {
return (propertyName == null) ? false : systemProperty.equals(propertyName);
/**
* Returns the state of a property name. By the specification as of JDK 17,
* the "jdk.xml." prefixed System property name is also the current API
* name. The URI-based qName is legacy.
*
* @param name the property name
* @return the state of the property name, null if no match
*/
public State getState(String name) {
if (systemProperty != null && systemProperty.equals(name)) {
return State.APIPROPERTY;
} else if (apiProperty.equals(name)) {
//the URI-style qName is legacy
return State.LEGACY_APIPROPERTY;
}
return null;
}

public String key() {
Expand All @@ -117,7 +122,7 @@ public String apiProperty() {
return apiProperty;
}

String systemProperty() {
public String systemProperty() {
return systemProperty;
}

Expand All @@ -135,12 +140,12 @@ int secureValue() {
*/
public static enum NameMap {

ENTITY_EXPANSION_LIMIT(XalanConstants.SP_ENTITY_EXPANSION_LIMIT,
XalanConstants.ENTITY_EXPANSION_LIMIT),
MAX_OCCUR_NODE_LIMIT(XalanConstants.SP_MAX_OCCUR_LIMIT,
XalanConstants.MAX_OCCUR_LIMIT),
ELEMENT_ATTRIBUTE_LIMIT(XalanConstants.SP_ELEMENT_ATTRIBUTE_LIMIT,
XalanConstants.ELEMENT_ATTRIBUTE_LIMIT);
ENTITY_EXPANSION_LIMIT(JdkConstants.SP_ENTITY_EXPANSION_LIMIT,
JdkConstants.ENTITY_EXPANSION_LIMIT),
MAX_OCCUR_NODE_LIMIT(JdkConstants.SP_MAX_OCCUR_LIMIT,
JdkConstants.MAX_OCCUR_LIMIT),
ELEMENT_ATTRIBUTE_LIMIT(JdkConstants.SP_ELEMENT_ATTRIBUTE_LIMIT,
JdkConstants.ELEMENT_ATTRIBUTE_LIMIT);
final String newName;
final String oldName;

Expand Down Expand Up @@ -230,7 +235,11 @@ public void setSecureProcessing(boolean secure) {
public boolean setLimit(String propertyName, State state, Object value) {
int index = getIndex(propertyName);
if (index > -1) {
setLimit(index, state, value);
State pState = state;
if (index != indexEntityCountInfo && state == State.APIPROPERTY) {
pState = (Limit.values()[index]).getState(propertyName);
}
setLimit(index, pState, value);
return true;
}
return false;
Expand Down Expand Up @@ -259,14 +268,17 @@ public void setLimit(int index, State state, Object value) {
//if it's explicitly set, it's treated as yes no matter the value
printEntityCountInfo = (String)value;
} else {
int temp = 0;
try {
int temp;
if (value instanceof Integer) {
temp = (Integer)value;
} else {
temp = Integer.parseInt((String) value);
if (temp < 0) {
temp = 0;
}
} catch (NumberFormatException e) {}
setLimit(index, state, temp); }
}
setLimit(index, state, temp);
}
}

/**
Expand All @@ -279,7 +291,7 @@ public void setLimit(int index, State state, Object value) {
public void setLimit(int index, State state, int value) {
if (index == indexEntityCountInfo) {
//if it's explicitly set, it's treated as yes no matter the value
printEntityCountInfo = XalanConstants.JDK_YES;
printEntityCountInfo = JdkConstants.JDK_YES;
} else {
//only update if it shall override
if (state.compareTo(states[index]) >= 0) {
Expand Down Expand Up @@ -377,13 +389,14 @@ public String getStateLiteral(Limit limit) {
*/
public int getIndex(String propertyName) {
for (Limit limit : Limit.values()) {
if (limit.equalsAPIPropertyName(propertyName)) {
// see JDK-8265248, accept both the URL and jdk.xml as prefix
if (limit.is(propertyName)) {
//internally, ordinal is used as index
return limit.ordinal();
}
}
//special property to return entity count info
if (propertyName.equals(XalanConstants.JDK_ENTITY_COUNT_INFO)) {
if (ImplPropMap.ENTITYCOUNT.is(propertyName)) {
return indexEntityCountInfo;
}
return -1;
Expand All @@ -399,7 +412,7 @@ public boolean isSet(int index) {
}

public boolean printEntityCountInfo() {
return printEntityCountInfo.equals(XalanConstants.JDK_YES);
return printEntityCountInfo.equals(JdkConstants.JDK_YES);
}
/**
* Read from system properties, or those in jaxp.properties
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2021, 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 All @@ -25,9 +25,8 @@

package com.sun.org.apache.xalan.internal.utils;


import com.sun.org.apache.xalan.internal.XalanConstants;
import javax.xml.XMLConstants;
import jdk.xml.internal.JdkConstants;

/**
* This class manages security related properties
Expand All @@ -40,9 +39,9 @@ public final class XMLSecurityPropertyManager extends FeaturePropertyBase {
*/
public static enum Property {
ACCESS_EXTERNAL_DTD(XMLConstants.ACCESS_EXTERNAL_DTD,
XalanConstants.EXTERNAL_ACCESS_DEFAULT),
JdkConstants.EXTERNAL_ACCESS_DEFAULT),
ACCESS_EXTERNAL_STYLESHEET(XMLConstants.ACCESS_EXTERNAL_STYLESHEET,
XalanConstants.EXTERNAL_ACCESS_DEFAULT);
JdkConstants.EXTERNAL_ACCESS_DEFAULT);

final String name;
final String defaultValue;
Expand Down Expand Up @@ -94,9 +93,9 @@ public int getIndex(String propertyName){
*/
private void readSystemProperties() {
getSystemProperty(Property.ACCESS_EXTERNAL_DTD,
XalanConstants.SP_ACCESS_EXTERNAL_DTD);
JdkConstants.SP_ACCESS_EXTERNAL_DTD);
getSystemProperty(Property.ACCESS_EXTERNAL_STYLESHEET,
XalanConstants.SP_ACCESS_EXTERNAL_STYLESHEET);
JdkConstants.SP_ACCESS_EXTERNAL_STYLESHEET);
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2007, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2007, 2021, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
Expand All @@ -23,7 +23,6 @@

package com.sun.org.apache.xalan.internal.xsltc.compiler;

import com.sun.org.apache.xalan.internal.XalanConstants;
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ClassGenerator;
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ErrorMsg;
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodGenerator;
Expand All @@ -32,6 +31,7 @@
import com.sun.org.apache.xml.internal.utils.SystemIDResolver;
import java.util.Iterator;
import javax.xml.XMLConstants;
import jdk.xml.internal.JdkConstants;
import jdk.xml.internal.SecuritySupport;
import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;
Expand All @@ -41,7 +41,7 @@
* @author Morten Jorgensen
* @author Erwin Bolwidt <ejb@klomp.org>
* @author Gunnlaugur Briem <gthb@dimon.is>
* @LastModified: Sep 2017
* @LastModified: May 2021
*/
final class Import extends TopLevelElement {

Expand Down Expand Up @@ -85,7 +85,7 @@ public void parseContents(final Parser parser) {
docToLoad = SystemIDResolver.getAbsoluteURI(docToLoad, currLoadedDoc);
String accessError = SecuritySupport.checkAccess(docToLoad,
(String)xsltc.getProperty(XMLConstants.ACCESS_EXTERNAL_STYLESHEET),
XalanConstants.ACCESS_EXTERNAL_ALL);
JdkConstants.ACCESS_EXTERNAL_ALL);

if (accessError != null) {
final ErrorMsg msg = new ErrorMsg(ErrorMsg.ACCESSING_XSLT_TARGET_ERR,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2007, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2007, 2021, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
Expand All @@ -23,7 +23,6 @@

package com.sun.org.apache.xalan.internal.xsltc.compiler;

import com.sun.org.apache.xalan.internal.XalanConstants;
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ClassGenerator;
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ErrorMsg;
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodGenerator;
Expand All @@ -32,6 +31,7 @@
import com.sun.org.apache.xml.internal.utils.SystemIDResolver;
import java.util.Iterator;
import javax.xml.XMLConstants;
import jdk.xml.internal.JdkConstants;
import jdk.xml.internal.SecuritySupport;
import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;
Expand All @@ -41,7 +41,7 @@
* @author Morten Jorgensen
* @author Erwin Bolwidt <ejb@klomp.org>
* @author Gunnlaugur Briem <gthb@dimon.is>
* @LastModified: Sep 2017
* @LastModified: May 2021
*/
final class Include extends TopLevelElement {

Expand Down Expand Up @@ -85,7 +85,7 @@ public void parseContents(final Parser parser) {
docToLoad = SystemIDResolver.getAbsoluteURI(docToLoad, currLoadedDoc);
String accessError = SecuritySupport.checkAccess(docToLoad,
(String)xsltc.getProperty(XMLConstants.ACCESS_EXTERNAL_STYLESHEET),
XalanConstants.ACCESS_EXTERNAL_ALL);
JdkConstants.ACCESS_EXTERNAL_ALL);

if (accessError != null) {
final ErrorMsg msg = new ErrorMsg(ErrorMsg.ACCESSING_XSLT_TARGET_ERR,
Expand Down
Loading

1 comment on commit 8c4719a

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.