Package overit.geocall.xml
Class ParserProvider
java.lang.Object
overit.geocall.xml.ParserProvider
This class is an implementation of easy security settings for the main XML parsers factories and builders.
Inspired by http://openjdk.java.net/jeps/185
Inspired by http://openjdk.java.net/jeps/185
-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionTool for parsing xml securely.ParserProvider(boolean secureProcessing) Tool for parsing xml securely. -
Method Summary
Modifier and TypeMethodDescriptionprovides aDocumentBuilderFactorybased on current object configurationprovides aSAXParserFactorybased on current object configurationprotected org.apache.xml.resolver.tools.CatalogResolverCollects the xsd_catalog.xml files of every packagage in order to create a catalog of the local XSD files.creates a newDocumentBuilderbased on the current object configurationcreates a newSAXParserbased on the current object configurationvoidsetAccessExternalDtd(String accessExternalDtd) Defines the list of schemas permitted for external DTDsvoidsetAccessExternalSchema(String accessExternalSchema) Defines the list of schemas permitted for external SchemasvoidsetAccessExternalStylesheet(String accessExternalStylesheet) Defines the list of schemas permitted for external stylesheetsvoidsetCatalog(String catalogPath, Object caller) Defines the catalog file to load.voidsetDisallowDoctypeDecl(boolean disallowDoctypeDecl) Defines if allowing or not the DOCTYPE declaration in the XML to be processedvoidsetExternalGeneralEntities(boolean externalGeneralEntities) Defines if allowing or not the loading of external general entities for a XML to be processedvoidsetExternalParameterEntities(boolean externalParameterEntities) Defines if allowing or not the loading of external general entities for a XML to be processedvoidsetLoadExternalDtd(boolean loadExternalDtd) Defines if allowing or not the loading of external DTD for a XML to be processedvoidSets the schema that will be used to validate the XML source during parsing.voidsetValidation(boolean validation) Requests DTD or schema validation of the XML sources
-
Field Details
-
secureProcessing
protected boolean secureProcessing -
disallowDoctypeDecl
-
loadExternalDtd
-
externalGeneralEntities
-
externalParameterEntities
-
accessExternalDtd
-
accessExternalSchema
-
accessExternalStylesheet
-
validation
protected boolean validation -
catalog
-
schema
-
spf
-
dbf
-
-
Constructor Details
-
ParserProvider
public ParserProvider()Tool for parsing xml securely. By default it configures all the factories with FEATURE_SECURE_POLICY, but it offers more methods (most proprietary) to customize parsers to prevent security issues
See https://www.owasp.org/index.php/XML_External_Entity_(XXE)_Prevention_Cheat_Sheet -
ParserProvider
public ParserProvider(boolean secureProcessing) Tool for parsing xml securely. It configures all the factories with FEATURE_SECURE_POLICY dependent on the parametersecureProcessing, but it offers more methods (most proprietary) to customize parsers to prevent security issues
See https://www.owasp.org/index.php/XML_External_Entity_(XXE)_Prevention_Cheat_Sheet- Parameters:
secureProcessing-truefor configuring the factories with the feature FEATURE_SECURE_POLICY
-
-
Method Details
-
setDisallowDoctypeDecl
public void setDisallowDoctypeDecl(boolean disallowDoctypeDecl) Defines if allowing or not the DOCTYPE declaration in the XML to be processed- Parameters:
disallowDoctypeDecl-trueto allow andfalseto get an error if the xml has any kind of DOCTYPE declaration
-
setLoadExternalDtd
public void setLoadExternalDtd(boolean loadExternalDtd) Defines if allowing or not the loading of external DTD for a XML to be processed- Parameters:
loadExternalDtd-trueto allow andfalseto get an error if the xml DOCTYPE refers an external file
-
setExternalGeneralEntities
public void setExternalGeneralEntities(boolean externalGeneralEntities) Defines if allowing or not the loading of external general entities for a XML to be processed- Parameters:
externalGeneralEntities-trueto allow andfalseto get an error resolve external general entities
-
setExternalParameterEntities
public void setExternalParameterEntities(boolean externalParameterEntities) Defines if allowing or not the loading of external general entities for a XML to be processed- Parameters:
externalParameterEntities-trueto allow andfalseto get an error resolve external parameter entities
-
setAccessExternalDtd
Defines the list of schemas permitted for external DTDs- Parameters:
accessExternalDtd- The comma separated list of schemas permitted for external DTDs, or ALL to permit anyone, or empty string to not permit anyone
-
setAccessExternalSchema
Defines the list of schemas permitted for external Schemas- Parameters:
accessExternalSchema- The comma separated list of schemas permitted for external schemas, or ALL to permit anyone, or empty string to not permit anyone
-
setAccessExternalStylesheet
Defines the list of schemas permitted for external stylesheets- Parameters:
accessExternalStylesheet- The comma separated list of schemas permitted for external stylesheets, or ALL to permit anyone, or empty string to not permit anyone
-
setValidation
public void setValidation(boolean validation) Requests DTD or schema validation of the XML sources- Parameters:
validation-truefor enabling DTD or schema validation
-
setCatalog
Defines the catalog file to load. A catalog contains the mapping between a XSD remote URL and the corresponding local file.
The catalog will not been used if thesetValidation(boolean)has been set tofalse- Parameters:
catalogPath- Catalog's path revolved byTreeFactory. It can be relative to thecalleror absolute depending by the path format. A path starting with // is absolute and already resolved. It will not be changed. A path starting with + will be translated tooverit/geocall/basic/and will be resolved. Otherwise the path will be searched all across all the layer customizations relatively to the position of thecallerIf the caller is null, thepathis meant to be absolute, otherwise thepathcould meant to be absolute if it starts with leading /, or could be referred to thecallerposition. In both cases the path will be resolvedcaller- the object requesting the path. It can sometimes carry and Identity with a CustomLayer
-
setSchema
Sets the schema that will be used to validate the XML source during parsing. The schema will not been used if thesetValidation(boolean)has been set tofalse.- Parameters:
schema- the valudating schema
-
getDocumentBuilderFactory
provides aDocumentBuilderFactorybased on current object configuration- Returns:
- a
DocumentBuilderFactorybased on current object configuration - Throws:
ParserConfigurationException- if there is any problem setting up the factory to respect the current object configuration
-
newDocumentBuilder
creates a newDocumentBuilderbased on the current object configuration- Returns:
- a new
DocumentBuilderbased on the current object configuration - Throws:
ParserConfigurationException- if there is any problem setting up the parser to respect the current object configuration
-
getSAXParserFactory
provides aSAXParserFactorybased on current object configuration- Returns:
- a
SAXParserFactorybased on current object configuration - Throws:
ParserConfigurationException- if there is any problem setting up the factory to respect the current object configurationSAXException- if there is an exception setting up the factory to respect the current object configuration
-
newSAXParser
creates a newSAXParserbased on the current object configuration- Returns:
- a new
SAXParserbased on the current object configuration - Throws:
ParserConfigurationException- if there is any problem setting up the parser to respect the current object configurationSAXException- if there is an exception setting up the parser to respect the current object configuration
-
getXsdCatalogResolver
protected org.apache.xml.resolver.tools.CatalogResolver getXsdCatalogResolver()Collects the xsd_catalog.xml files of every packagage in order to create a catalog of the local XSD files. Each catalog entry is a mapping between the remote xsd's URL and the relative local file.
This is useful if the online xsd couldn't be reached.- Returns:
CatalogResolvercreated by the collected catalog.
-