Class SecureSAXParserFactory
SAXParserFactory instances.
Beyond the three universal guarantees on org.apache.commons.xml.secure, XInclude resolution is denied by default. When
setXIncludeAware(true) is called on the returned factory, the parser will process xi:include
elements but every external resource lookup is rejected. To permit specific trusted resources, install an EntityResolver on the XMLReader that allow-lists them; any href the resolver does not explicitly allow stays blocked.
Not a SAXParserFactory itself, so none of the JAXP static factory methods is inherited: a caller cannot reach a non-secured factory through this class
by calling an inherited method such as newDefaultInstance(). The secure factories are instances of a nested, non-public wrapper class.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic SAXParserFactoryReturns a new, secureSAXParserFactoryof the system-default implementation.static SAXParserFactoryReturns a new, secure, namespace-awareSAXParserFactoryof the system-default implementation, enabling namespace awareness onnewDefaultInstance(), the behaviorSAXParserFactory.newDefaultNSInstance()(Java 13 or later) is specified to have.static SAXParserFactoryReturns a new, secureSAXParserFactory.static SAXParserFactorynewInstance(String factoryClassName, ClassLoader classLoader) Returns a new, secureSAXParserFactoryof the given implementation class.static SAXParserFactoryReturns a new, secure, namespace-awareSAXParserFactory, enabling namespace awareness onnewInstance(), the behaviorSAXParserFactory.newNSInstance()(Java 13 or later) is specified to have.static SAXParserFactorynewNSInstance(String factoryClassName, ClassLoader classLoader) Returns a new, secure, namespace-awareSAXParserFactoryof the given implementation class, enabling namespace awareness onnewInstance(String, ClassLoader), the behaviorSAXParserFactory.newNSInstance(String, ClassLoader)(Java 13 or later) is specified to have.
-
Method Details
-
newDefaultInstance
Returns a new, secureSAXParserFactoryof the system-default implementation.Obtained as by
SAXParserFactory.newDefaultInstance()where the platform provides it (Java 9 or later), by instantiating the JDK's built-in implementation directly on Java 8, and by the standardnewInstance()lookup where the platform provides neither (for example, Android, whose lookup is itself pinned to the platform implementation).- Returns:
- A secure factory.
- Throws:
IllegalStateException- Thrown if a required secure setting cannot be applied to the underlying implementation.FactoryConfigurationError- Thrown from thenewInstance()lookup this method falls back to on a platform that provides neithernewDefaultInstance()nor the JDK's built-in implementation (for example Android).
-
newDefaultNSInstance
Returns a new, secure, namespace-awareSAXParserFactoryof the system-default implementation, enabling namespace awareness onnewDefaultInstance(), the behaviorSAXParserFactory.newDefaultNSInstance()(Java 13 or later) is specified to have.- Returns:
- A secure, namespace-aware factory.
- Throws:
IllegalStateException- Thrown if a required secure setting cannot be applied to the underlying implementation.FactoryConfigurationError- Thrown from thenewInstance()lookupnewDefaultInstance()falls back to on a platform that provides neithernewDefaultInstance()nor the JDK's built-in implementation (for example Android).
-
newInstance
Returns a new, secureSAXParserFactory.- Returns:
- A secure factory.
- Throws:
IllegalStateException- Thrown if a required secure setting cannot be applied to the underlying implementation.FactoryConfigurationError- Thrown fromSAXParserFactoryin case of aservice configuration erroror if the implementation is not available or cannot be instantiated.
-
newInstance
Returns a new, secureSAXParserFactoryof the given implementation class.- Parameters:
factoryClassName- The fully qualified class name of theSAXParserFactoryimplementation.classLoader- The class loader used to load the factory class;nullmeans the current thread's context class loader.- Returns:
- A secure factory.
- Throws:
IllegalStateException- Thrown if a required secure setting cannot be applied to the underlying implementation.FactoryConfigurationError- Thrown iffactoryClassNameisnullor the factory class cannot be loaded or instantiated.
-
newNSInstance
Returns a new, secure, namespace-awareSAXParserFactory, enabling namespace awareness onnewInstance(), the behaviorSAXParserFactory.newNSInstance()(Java 13 or later) is specified to have.- Returns:
- A secure, namespace-aware factory.
- Throws:
IllegalStateException- Thrown if a required secure setting cannot be applied to the underlying implementation.FactoryConfigurationError- Thrown fromSAXParserFactoryin case of aservice configuration erroror if the implementation is not available or cannot be instantiated.
-
newNSInstance
Returns a new, secure, namespace-awareSAXParserFactoryof the given implementation class, enabling namespace awareness onnewInstance(String, ClassLoader), the behaviorSAXParserFactory.newNSInstance(String, ClassLoader)(Java 13 or later) is specified to have.- Parameters:
factoryClassName- The fully qualified class name of theSAXParserFactoryimplementation.classLoader- The class loader used to load the factory class;nullmeans the current thread's context class loader.- Returns:
- A secure, namespace-aware factory.
- Throws:
IllegalStateException- Thrown if a required secure setting cannot be applied to the underlying implementation.FactoryConfigurationError- Thrown iffactoryClassNameisnullor the factory class cannot be loaded or instantiated.
-