Class SecureDocumentBuilderFactory
DocumentBuilderFactory 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 DocumentBuilder that allow-lists them; any href the resolver does not explicitly allow
stays blocked.
Not a DocumentBuilderFactory 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 DocumentBuilderFactoryReturns a new, secureDocumentBuilderFactoryof the system-default implementation.static DocumentBuilderFactoryReturns a new, secure, namespace-awareDocumentBuilderFactoryof the system-default implementation, enabling namespace awareness onnewDefaultInstance(), the behaviorDocumentBuilderFactory.newDefaultNSInstance()(Java 13 or later) is specified to have.static DocumentBuilderFactoryReturns a new, secureDocumentBuilderFactory.static DocumentBuilderFactorynewInstance(String factoryClassName, ClassLoader classLoader) Returns a new, secureDocumentBuilderFactoryof the given implementation class.static DocumentBuilderFactoryReturns a new, secure, namespace-awareDocumentBuilderFactory, enabling namespace awareness onnewInstance(), the behaviorDocumentBuilderFactory.newNSInstance()(Java 13 or later) is specified to have.static DocumentBuilderFactorynewNSInstance(String factoryClassName, ClassLoader classLoader) Returns a new, secure, namespace-awareDocumentBuilderFactoryof the given implementation class, enabling namespace awareness onnewInstance(String, ClassLoader), the behaviorDocumentBuilderFactory.newNSInstance(String, ClassLoader)(Java 13 or later) is specified to have.
-
Method Details
-
newDefaultInstance
Returns a new, secureDocumentBuilderFactoryof the system-default implementation.Obtained as by
DocumentBuilderFactory.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-awareDocumentBuilderFactoryof the system-default implementation, enabling namespace awareness onnewDefaultInstance(), the behaviorDocumentBuilderFactory.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, secureDocumentBuilderFactory.- Returns:
- A secure factory.
- Throws:
IllegalStateException- Thrown if a required secure setting cannot be applied to the underlying implementation.IllegalStateException- Thrown if a (non-Android) factory cannot support the secure processing featureXMLConstants.FEATURE_SECURE_PROCESSING.FactoryConfigurationError- Thrown from a factory in case of aservice configuration erroror if the implementation is not available or cannot be instantiated.
-
newInstance
Returns a new, secureDocumentBuilderFactoryof the given implementation class.- Parameters:
factoryClassName- The fully qualified class name of theDocumentBuilderFactoryimplementation.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.IllegalStateException- Thrown if a (non-Android) factory cannot support the secure processing featureXMLConstants.FEATURE_SECURE_PROCESSING.FactoryConfigurationError- Thrown iffactoryClassNameisnullor the factory class cannot be loaded or instantiated.
-
newNSInstance
Returns a new, secure, namespace-awareDocumentBuilderFactory, enabling namespace awareness onnewInstance(), the behaviorDocumentBuilderFactory.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 from a factory in case of aservice configuration erroror if the implementation is not available or cannot be instantiated.
-
newNSInstance
public static DocumentBuilderFactory newNSInstance(String factoryClassName, ClassLoader classLoader) Returns a new, secure, namespace-awareDocumentBuilderFactoryof the given implementation class, enabling namespace awareness onnewInstance(String, ClassLoader), the behaviorDocumentBuilderFactory.newNSInstance(String, ClassLoader)(Java 13 or later) is specified to have.- Parameters:
factoryClassName- The fully qualified class name of theDocumentBuilderFactoryimplementation.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.
-