9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 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 com.sun.org.apache.xalan.internal.utils; 27 28 import com.sun.org.apache.xalan.internal.XalanConstants; 29 30 31 /** 32 * This class is not the same as that in Xerces. It is used to manage the 33 * state of corresponding Xerces properties and pass the values over to 34 * the Xerces Security Manager. 35 * 36 * @author Joe Wang Oracle Corp. 37 * 38 */ 39 public final class XMLSecurityManager { 40 41 /** 42 * States of the settings of a property, in the order: default value, value 43 * set by FEATURE_SECURE_PROCESSING, jaxp.properties file, jaxp system 44 * properties, and jaxp api properties 45 */ 46 public static enum State { 47 //this order reflects the overriding order 48 396 public boolean printEntityCountInfo() { 397 return printEntityCountInfo.equals(XalanConstants.JDK_YES); 398 } 399 /** 400 * Read from system properties, or those in jaxp.properties 401 */ 402 private void readSystemProperties() { 403 404 for (Limit limit : Limit.values()) { 405 if (!getSystemProperty(limit, limit.systemProperty())) { 406 //if system property is not found, try the older form if any 407 for (NameMap nameMap : NameMap.values()) { 408 String oldName = nameMap.getOldName(limit.systemProperty()); 409 if (oldName != null) { 410 getSystemProperty(limit, oldName); 411 } 412 } 413 } 414 } 415 416 } 417 418 /** 419 * Read from system properties, or those in jaxp.properties 420 * 421 * @param property the type of the property 422 * @param sysPropertyName the name of system property 423 */ 424 private boolean getSystemProperty(Limit limit, String sysPropertyName) { 425 try { 426 String value = SecuritySupport.getSystemProperty(sysPropertyName); 427 if (value != null && !value.equals("")) { 428 values[limit.ordinal()] = Integer.parseInt(value); 429 states[limit.ordinal()] = State.SYSTEMPROPERTY; 430 return true; 431 } 432 433 value = SecuritySupport.readJAXPProperty(sysPropertyName); 434 if (value != null && !value.equals("")) { 435 values[limit.ordinal()] = Integer.parseInt(value); | 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 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 com.sun.org.apache.xalan.internal.utils; 27 28 import com.sun.org.apache.xalan.internal.XalanConstants; 29 import java.util.concurrent.CopyOnWriteArrayList; 30 import org.xml.sax.SAXException; 31 32 33 /** 34 * This class is not the same as that in Xerces. It is used to manage the 35 * state of corresponding Xerces properties and pass the values over to 36 * the Xerces Security Manager. 37 * 38 * @author Joe Wang Oracle Corp. 39 * 40 */ 41 public final class XMLSecurityManager { 42 43 /** 44 * States of the settings of a property, in the order: default value, value 45 * set by FEATURE_SECURE_PROCESSING, jaxp.properties file, jaxp system 46 * properties, and jaxp api properties 47 */ 48 public static enum State { 49 //this order reflects the overriding order 50 398 public boolean printEntityCountInfo() { 399 return printEntityCountInfo.equals(XalanConstants.JDK_YES); 400 } 401 /** 402 * Read from system properties, or those in jaxp.properties 403 */ 404 private void readSystemProperties() { 405 406 for (Limit limit : Limit.values()) { 407 if (!getSystemProperty(limit, limit.systemProperty())) { 408 //if system property is not found, try the older form if any 409 for (NameMap nameMap : NameMap.values()) { 410 String oldName = nameMap.getOldName(limit.systemProperty()); 411 if (oldName != null) { 412 getSystemProperty(limit, oldName); 413 } 414 } 415 } 416 } 417 418 } 419 420 // Array list to store printed warnings for each SAX parser used 421 private static final CopyOnWriteArrayList<String> printedWarnings = new CopyOnWriteArrayList<>(); 422 423 /** 424 * Prints out warnings if a parser does not support the specified feature/property. 425 * 426 * @param parserClassName the name of the parser class 427 * @param propertyName the property name 428 * @param exception the exception thrown by the parser 429 */ 430 public static void printWarning(String parserClassName, String propertyName, SAXException exception) { 431 String key = parserClassName+":"+propertyName; 432 if (printedWarnings.addIfAbsent(key)) { 433 System.err.println( "Warning: "+parserClassName+": "+exception.getMessage()); 434 } 435 } 436 437 /** 438 * Read from system properties, or those in jaxp.properties 439 * 440 * @param property the type of the property 441 * @param sysPropertyName the name of system property 442 */ 443 private boolean getSystemProperty(Limit limit, String sysPropertyName) { 444 try { 445 String value = SecuritySupport.getSystemProperty(sysPropertyName); 446 if (value != null && !value.equals("")) { 447 values[limit.ordinal()] = Integer.parseInt(value); 448 states[limit.ordinal()] = State.SYSTEMPROPERTY; 449 return true; 450 } 451 452 value = SecuritySupport.readJAXPProperty(sysPropertyName); 453 if (value != null && !value.equals("")) { 454 values[limit.ordinal()] = Integer.parseInt(value); |