Java Code Examples for com.sun.org.apache.xalan.internal.utils.XMLSecurityManager#printWarning()

The following examples show how to use com.sun.org.apache.xalan.internal.utils.XMLSecurityManager#printWarning() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Parser.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Parses a stylesheet and builds the internal abstract syntax tree
 * @param input A SAX2 InputSource can be passed to a SAX reader
 * @return The root of the abstract syntax tree
 */
public SyntaxTreeNode parse(InputSource input) {
    final XMLReader reader = JdkXmlUtils.getXMLReader(_overrideDefaultParser,
            _xsltc.isSecureProcessing());

    JdkXmlUtils.setXMLReaderPropertyIfSupport(reader, XMLConstants.ACCESS_EXTERNAL_DTD,
            _xsltc.getProperty(XMLConstants.ACCESS_EXTERNAL_DTD), true);

    String lastProperty = "";
    try {
        XMLSecurityManager securityManager =
                (XMLSecurityManager) _xsltc.getProperty(XalanConstants.SECURITY_MANAGER);
        for (XMLSecurityManager.Limit limit : XMLSecurityManager.Limit.values()) {
            lastProperty = limit.apiProperty();
            reader.setProperty(lastProperty, securityManager.getLimitValueAsString(limit));
        }
        if (securityManager.printEntityCountInfo()) {
            lastProperty = XalanConstants.JDK_ENTITY_COUNT_INFO;
            reader.setProperty(XalanConstants.JDK_ENTITY_COUNT_INFO, XalanConstants.JDK_YES);
        }
    } catch (SAXException se) {
        XMLSecurityManager.printWarning(reader.getClass().getName(), lastProperty, se);
    }

    return (parse(reader, input));
}
 
Example 2
Source File: Parser.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
/**
 * Parses a stylesheet and builds the internal abstract syntax tree
 * @param input A SAX2 InputSource can be passed to a SAX reader
 * @return The root of the abstract syntax tree
 */
public SyntaxTreeNode parse(InputSource input) {
    final XMLReader reader = JdkXmlUtils.getXMLReader(_overrideDefaultParser,
            _xsltc.isSecureProcessing());

    JdkXmlUtils.setXMLReaderPropertyIfSupport(reader, XMLConstants.ACCESS_EXTERNAL_DTD,
            _xsltc.getProperty(XMLConstants.ACCESS_EXTERNAL_DTD), true);

    String lastProperty = "";
    try {
        XMLSecurityManager securityManager =
                (XMLSecurityManager) _xsltc.getProperty(XalanConstants.SECURITY_MANAGER);
        for (XMLSecurityManager.Limit limit : XMLSecurityManager.Limit.values()) {
            lastProperty = limit.apiProperty();
            reader.setProperty(lastProperty, securityManager.getLimitValueAsString(limit));
        }
        if (securityManager.printEntityCountInfo()) {
            lastProperty = XalanConstants.JDK_ENTITY_COUNT_INFO;
            reader.setProperty(XalanConstants.JDK_ENTITY_COUNT_INFO, XalanConstants.JDK_YES);
        }
    } catch (SAXException se) {
        XMLSecurityManager.printWarning(reader.getClass().getName(), lastProperty, se);
    }

    return (parse(reader, input));
}
 
Example 3
Source File: Parser.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Parses a stylesheet and builds the internal abstract syntax tree
 * @param input A SAX2 InputSource can be passed to a SAX reader
 * @return The root of the abstract syntax tree
 */
public SyntaxTreeNode parse(InputSource input) {
    final XMLReader reader = JdkXmlUtils.getXMLReader(_overrideDefaultParser,
            _xsltc.isSecureProcessing());

    JdkXmlUtils.setXMLReaderPropertyIfSupport(reader, XMLConstants.ACCESS_EXTERNAL_DTD,
            _xsltc.getProperty(XMLConstants.ACCESS_EXTERNAL_DTD), true);

    String lastProperty = "";
    try {
        XMLSecurityManager securityManager =
                (XMLSecurityManager) _xsltc.getProperty(XalanConstants.SECURITY_MANAGER);
        for (XMLSecurityManager.Limit limit : XMLSecurityManager.Limit.values()) {
            lastProperty = limit.apiProperty();
            reader.setProperty(lastProperty, securityManager.getLimitValueAsString(limit));
        }
        if (securityManager.printEntityCountInfo()) {
            lastProperty = XalanConstants.JDK_ENTITY_COUNT_INFO;
            reader.setProperty(XalanConstants.JDK_ENTITY_COUNT_INFO, XalanConstants.JDK_YES);
        }
    } catch (SAXException se) {
        XMLSecurityManager.printWarning(reader.getClass().getName(), lastProperty, se);
    }

    return (parse(reader, input));
}
 
Example 4
Source File: Parser.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Parses a stylesheet and builds the internal abstract syntax tree
 * @param input A SAX2 InputSource can be passed to a SAX reader
 * @return The root of the abstract syntax tree
 */
public SyntaxTreeNode parse(InputSource input) {
    final XMLReader reader = JdkXmlUtils.getXMLReader(_overrideDefaultParser,
            _xsltc.isSecureProcessing());

    JdkXmlUtils.setXMLReaderPropertyIfSupport(reader, XMLConstants.ACCESS_EXTERNAL_DTD,
            _xsltc.getProperty(XMLConstants.ACCESS_EXTERNAL_DTD), true);

    String lastProperty = "";
    try {
        XMLSecurityManager securityManager =
                (XMLSecurityManager) _xsltc.getProperty(XalanConstants.SECURITY_MANAGER);
        for (XMLSecurityManager.Limit limit : XMLSecurityManager.Limit.values()) {
            lastProperty = limit.apiProperty();
            reader.setProperty(lastProperty, securityManager.getLimitValueAsString(limit));
        }
        if (securityManager.printEntityCountInfo()) {
            lastProperty = XalanConstants.JDK_ENTITY_COUNT_INFO;
            reader.setProperty(XalanConstants.JDK_ENTITY_COUNT_INFO, XalanConstants.JDK_YES);
        }
    } catch (SAXException se) {
        XMLSecurityManager.printWarning(reader.getClass().getName(), lastProperty, se);
    }

    return (parse(reader, input));
}
 
Example 5
Source File: JdkXmlUtils.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Sets the XMLReader instance with the specified property if the the
 * property is supported, ignores error if not, issues a warning if so
 * requested.
 *
 * @param reader an XMLReader instance
 * @param property the name of the property
 * @param value the value of the property
 * @param warn a flag indicating whether a warning should be issued
 */
public static void setXMLReaderPropertyIfSupport(XMLReader reader, String property,
        Object value, boolean warn) {
    try {
        reader.setProperty(property, value);
    } catch (SAXNotRecognizedException | SAXNotSupportedException e) {
        if (warn) {
            XMLSecurityManager.printWarning(reader.getClass().getName(),
                    property, e);
        }
    }
}
 
Example 6
Source File: JdkXmlUtils.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns an XMLReader instance. If overrideDefaultParser is requested, use
 * SAXParserFactory or XMLReaderFactory, otherwise use the system-default
 * SAXParserFactory to locate an XMLReader.
 *
 * @param overrideDefaultParser a flag indicating whether a 3rd party's
 * parser implementation may be used to override the system-default one
 * @param secureProcessing a flag indicating whether secure processing is
 * requested
 * @return an XMLReader instance
 */
public static XMLReader getXMLReader(boolean overrideDefaultParser,
        boolean secureProcessing) {
    SAXParserFactory saxFactory;
    XMLReader reader = null;
    String spSAXDriver = SecuritySupport.getSystemProperty(SAX_DRIVER);
    if (spSAXDriver != null) {
        reader = getXMLReaderWXMLReaderFactory();
    } else if (overrideDefaultParser) {
        reader = getXMLReaderWSAXFactory(overrideDefaultParser);
    }

    if (reader != null) {
        if (secureProcessing) {
            try {
                reader.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, secureProcessing);
            } catch (SAXException e) {
                XMLSecurityManager.printWarning(reader.getClass().getName(),
                        XMLConstants.FEATURE_SECURE_PROCESSING, e);
            }
        }
        try {
            reader.setFeature(NAMESPACES_FEATURE, true);
            reader.setFeature(NAMESPACE_PREFIXES_FEATURE, false);
        } catch (SAXException se) {
            // older version of a parser
        }
        return reader;
    }

    // use the system-default
    saxFactory = defaultSAXFactory;

    try {
        reader = saxFactory.newSAXParser().getXMLReader();
    } catch (ParserConfigurationException | SAXException ex) {
        // shall not happen with the system-default reader
    }
    return reader;
}
 
Example 7
Source File: JdkXmlUtils.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Sets the XMLReader instance with the specified property if the the
 * property is supported, ignores error if not, issues a warning if so
 * requested.
 *
 * @param reader an XMLReader instance
 * @param property the name of the property
 * @param value the value of the property
 * @param warn a flag indicating whether a warning should be issued
 */
public static void setXMLReaderPropertyIfSupport(XMLReader reader, String property,
        Object value, boolean warn) {
    try {
        reader.setProperty(property, value);
    } catch (SAXNotRecognizedException | SAXNotSupportedException e) {
        if (warn) {
            XMLSecurityManager.printWarning(reader.getClass().getName(),
                    property, e);
        }
    }
}
 
Example 8
Source File: JdkXmlUtils.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns an XMLReader instance. If overrideDefaultParser is requested, use
 * SAXParserFactory or XMLReaderFactory, otherwise use the system-default
 * SAXParserFactory to locate an XMLReader.
 *
 * @param overrideDefaultParser a flag indicating whether a 3rd party's
 * parser implementation may be used to override the system-default one
 * @param secureProcessing a flag indicating whether secure processing is
 * requested
 * @return an XMLReader instance
 */
public static XMLReader getXMLReader(boolean overrideDefaultParser,
        boolean secureProcessing) {
    SAXParserFactory saxFactory;
    XMLReader reader = null;
    String spSAXDriver = SecuritySupport.getSystemProperty(SAX_DRIVER);
    if (spSAXDriver != null) {
        reader = getXMLReaderWXMLReaderFactory();
    } else if (overrideDefaultParser) {
        reader = getXMLReaderWSAXFactory(overrideDefaultParser);
    }

    if (reader != null) {
        if (secureProcessing) {
            try {
                reader.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, secureProcessing);
            } catch (SAXException e) {
                XMLSecurityManager.printWarning(reader.getClass().getName(),
                        XMLConstants.FEATURE_SECURE_PROCESSING, e);
            }
        }
        try {
            reader.setFeature(NAMESPACES_FEATURE, true);
            reader.setFeature(NAMESPACE_PREFIXES_FEATURE, false);
        } catch (SAXException se) {
            // older version of a parser
        }
        return reader;
    }

    // use the system-default
    saxFactory = defaultSAXFactory;

    try {
        reader = saxFactory.newSAXParser().getXMLReader();
    } catch (ParserConfigurationException | SAXException ex) {
        // shall not happen with the system-default reader
    }
    return reader;
}
 
Example 9
Source File: JdkXmlUtils.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Sets the XMLReader instance with the specified property if the the
 * property is supported, ignores error if not, issues a warning if so
 * requested.
 *
 * @param reader an XMLReader instance
 * @param property the name of the property
 * @param value the value of the property
 * @param warn a flag indicating whether a warning should be issued
 */
public static void setXMLReaderPropertyIfSupport(XMLReader reader, String property,
        Object value, boolean warn) {
    try {
        reader.setProperty(property, value);
    } catch (SAXNotRecognizedException | SAXNotSupportedException e) {
        if (warn) {
            XMLSecurityManager.printWarning(reader.getClass().getName(),
                    property, e);
        }
    }
}
 
Example 10
Source File: JdkXmlUtils.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns an XMLReader instance. If overrideDefaultParser is requested, use
 * SAXParserFactory or XMLReaderFactory, otherwise use the system-default
 * SAXParserFactory to locate an XMLReader.
 *
 * @param overrideDefaultParser a flag indicating whether a 3rd party's
 * parser implementation may be used to override the system-default one
 * @param secureProcessing a flag indicating whether secure processing is
 * requested
 * @return an XMLReader instance
 */
public static XMLReader getXMLReader(boolean overrideDefaultParser,
        boolean secureProcessing) {
    SAXParserFactory saxFactory;
    XMLReader reader = null;
    String spSAXDriver = SecuritySupport.getSystemProperty(SAX_DRIVER);
    if (spSAXDriver != null) {
        reader = getXMLReaderWXMLReaderFactory();
    } else if (overrideDefaultParser) {
        reader = getXMLReaderWSAXFactory(overrideDefaultParser);
    }

    if (reader != null) {
        if (secureProcessing) {
            try {
                reader.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, secureProcessing);
            } catch (SAXException e) {
                XMLSecurityManager.printWarning(reader.getClass().getName(),
                        XMLConstants.FEATURE_SECURE_PROCESSING, e);
            }
        }
        try {
            reader.setFeature(NAMESPACES_FEATURE, true);
            reader.setFeature(NAMESPACE_PREFIXES_FEATURE, false);
        } catch (SAXException se) {
            // older version of a parser
        }
        return reader;
    }

    // use the system-default
    saxFactory = defaultSAXFactory;

    try {
        reader = saxFactory.newSAXParser().getXMLReader();
    } catch (ParserConfigurationException | SAXException ex) {
        // shall not happen with the system-default reader
    }
    return reader;
}
 
Example 11
Source File: JdkXmlUtils.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * Sets the XMLReader instance with the specified property if the the
 * property is supported, ignores error if not, issues a warning if so
 * requested.
 *
 * @param reader an XMLReader instance
 * @param property the name of the property
 * @param value the value of the property
 * @param warn a flag indicating whether a warning should be issued
 */
public static void setXMLReaderPropertyIfSupport(XMLReader reader, String property,
        Object value, boolean warn) {
    try {
        reader.setProperty(property, value);
    } catch (SAXNotRecognizedException | SAXNotSupportedException e) {
        if (warn) {
            XMLSecurityManager.printWarning(reader.getClass().getName(),
                    property, e);
        }
    }
}
 
Example 12
Source File: JdkXmlUtils.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * Returns an XMLReader instance. If overrideDefaultParser is requested, use
 * SAXParserFactory or XMLReaderFactory, otherwise use the system-default
 * SAXParserFactory to locate an XMLReader.
 *
 * @param overrideDefaultParser a flag indicating whether a 3rd party's
 * parser implementation may be used to override the system-default one
 * @param secureProcessing a flag indicating whether secure processing is
 * requested
 * @param useXMLReaderFactory a flag indicating when the XMLReader should be
 * created using XMLReaderFactory. True is a compatibility mode that honors
 * the property org.xml.sax.driver (see JDK-6490921).
 * @return an XMLReader instance
 */
public static XMLReader getXMLReader(boolean overrideDefaultParser,
        boolean secureProcessing) {
    SAXParserFactory saxFactory;
    XMLReader reader = null;
    String spSAXDriver = SecuritySupport.getSystemProperty(SAX_DRIVER);
    if (spSAXDriver != null) {
        reader = getXMLReaderWXMLReaderFactory();
    } else if (overrideDefaultParser) {
        reader = getXMLReaderWSAXFactory(overrideDefaultParser);
    }

    if (reader != null) {
        if (secureProcessing) {
            try {
                reader.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, secureProcessing);
            } catch (SAXException e) {
                XMLSecurityManager.printWarning(reader.getClass().getName(),
                        XMLConstants.FEATURE_SECURE_PROCESSING, e);
            }
        }
        try {
            reader.setFeature(NAMESPACES_FEATURE, true);
            reader.setFeature(NAMESPACE_PREFIXES_FEATURE, false);
        } catch (SAXException se) {
            // older version of a parser
        }
        return reader;
    }

    // use the system-default
    saxFactory = defaultSAXFactory;

    try {
        reader = saxFactory.newSAXParser().getXMLReader();
    } catch (ParserConfigurationException | SAXException ex) {
        // shall not happen with the system-default reader
    }
    return reader;
}
 
Example 13
Source File: JdkXmlUtils.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Sets the XMLReader instance with the specified property if the the
 * property is supported, ignores error if not, issues a warning if so
 * requested.
 *
 * @param reader an XMLReader instance
 * @param property the name of the property
 * @param value the value of the property
 * @param warn a flag indicating whether a warning should be issued
 */
public static void setXMLReaderPropertyIfSupport(XMLReader reader, String property,
        Object value, boolean warn) {
    try {
        reader.setProperty(property, value);
    } catch (SAXNotRecognizedException | SAXNotSupportedException e) {
        if (warn) {
            XMLSecurityManager.printWarning(reader.getClass().getName(),
                    property, e);
        }
    }
}