Class XmlSecurity
java.lang.Object
cloud.opencode.base.xml.security.XmlSecurity
XML Security Configuration - Provides secure XML parser configuration
XML 安全配置 - 提供安全的 XML 解析器配置
This class provides methods to configure XML parsers securely to prevent XXE (XML External Entity) attacks and other XML-related security threats.
此类提供配置安全 XML 解析器的方法,以防止 XXE(XML 外部实体)攻击和其他 XML 相关安全威胁。
Security Features | 安全特性:
- Disables external entities (XXE protection) - 禁用外部实体(XXE 防护)
- Disables DTD processing - 禁用 DTD 处理
- Limits entity expansion - 限制实体扩展
- Disables external parameter entities - 禁用外部参数实体
Usage Examples | 使用示例:
// Create secure DocumentBuilderFactory
DocumentBuilderFactory factory = XmlSecurity.createSecureDocumentBuilderFactory();
// Or secure an existing factory
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
XmlSecurity.secure(factory);
- Since:
- JDK 25, opencode-base-xml V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intDefault entity expansion limit. -
Method Summary
Modifier and TypeMethodDescriptionstatic DocumentBuilderFactoryCreates a secure DocumentBuilderFactory.static SAXParserFactoryCreates a secure SAXParserFactory.static SchemaFactoryCreates a secure SchemaFactory for XSD validation.static TransformerFactoryCreates a secure TransformerFactory.static XMLInputFactoryCreates a secure XMLInputFactory.static voiddisableDtd(DocumentBuilderFactory factory) Disables DTD processing on a DocumentBuilderFactory.static voidDisables external entities on a DocumentBuilderFactory.static DocumentBuilderFactorysecure(DocumentBuilderFactory factory) Configures a DocumentBuilderFactory with secure settings.static SAXParserFactorysecure(SAXParserFactory factory) Configures a SAXParserFactory with secure settings.static XMLInputFactorysecure(XMLInputFactory factory) Configures an XMLInputFactory with secure settings.static TransformerFactorysecure(TransformerFactory factory) Configures a TransformerFactory with secure settings.static SchemaFactorysecure(SchemaFactory factory) Configures a SchemaFactory with secure settings.static voidsetEntityExpansionLimit(DocumentBuilderFactory factory, int limit) Sets the entity expansion limit on a DocumentBuilderFactory.
-
Field Details
-
DEFAULT_ENTITY_EXPANSION_LIMIT
public static final int DEFAULT_ENTITY_EXPANSION_LIMITDefault entity expansion limit. 默认实体扩展限制。- See Also:
-
-
Method Details
-
secure
Configures a DocumentBuilderFactory with secure settings. 使用安全设置配置 DocumentBuilderFactory。- Parameters:
factory- the factory to configure | 要配置的工厂- Returns:
- the configured factory | 配置后的工厂
-
secure
Configures a SAXParserFactory with secure settings. 使用安全设置配置 SAXParserFactory。- Parameters:
factory- the factory to configure | 要配置的工厂- Returns:
- the configured factory | 配置后的工厂
-
secure
Configures an XMLInputFactory with secure settings. 使用安全设置配置 XMLInputFactory。- Parameters:
factory- the factory to configure | 要配置的工厂- Returns:
- the configured factory | 配置后的工厂
-
secure
Configures a TransformerFactory with secure settings. 使用安全设置配置 TransformerFactory。- Parameters:
factory- the factory to configure | 要配置的工厂- Returns:
- the configured factory | 配置后的工厂
-
secure
Configures a SchemaFactory with secure settings. 使用安全设置配置 SchemaFactory。- Parameters:
factory- the factory to configure | 要配置的工厂- Returns:
- the configured factory | 配置后的工厂
-
createSecureDocumentBuilderFactory
Creates a secure DocumentBuilderFactory. 创建安全的 DocumentBuilderFactory。- Returns:
- a secure factory | 安全的工厂
-
createSecureSAXParserFactory
Creates a secure SAXParserFactory. 创建安全的 SAXParserFactory。- Returns:
- a secure factory | 安全的工厂
-
createSecureXMLInputFactory
Creates a secure XMLInputFactory. 创建安全的 XMLInputFactory。- Returns:
- a secure factory | 安全的工厂
-
createSecureTransformerFactory
Creates a secure TransformerFactory. 创建安全的 TransformerFactory。- Returns:
- a secure factory | 安全的工厂
-
createSecureSchemaFactory
Creates a secure SchemaFactory for XSD validation. 创建用于 XSD 验证的安全 SchemaFactory。- Returns:
- a secure factory | 安全的工厂
-
disableExternalEntities
Disables external entities on a DocumentBuilderFactory. 在 DocumentBuilderFactory 上禁用外部实体。- Parameters:
factory- the factory to configure | 要配置的工厂
-
disableDtd
Disables DTD processing on a DocumentBuilderFactory. 在 DocumentBuilderFactory 上禁用 DTD 处理。- Parameters:
factory- the factory to configure | 要配置的工厂
-
setEntityExpansionLimit
Sets the entity expansion limit on a DocumentBuilderFactory. 在 DocumentBuilderFactory 上设置实体扩展限制。- Parameters:
factory- the factory to configure | 要配置的工厂limit- the maximum number of entity expansions | 最大实体扩展数
-