Package overit.geocall.xml
Class XMLMode
java.lang.Object
overit.geocall.xml.XMLMode
This class is an implementation of easy security settings for the main XML resource factories and builders.
Inspired by http://openjdk.java.net/jeps/185
Inspired by http://openjdk.java.net/jeps/185
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionXMLMode()Object to configure XMLTree and other xml tools to define the parsing and building mode, in particular to restrict policies and to prevent security issues
See https://www.owasp.org/index.php/XML_External_Entity_(XXE)_Prevention_Cheat_Sheet -
Method Summary
Modifier and TypeMethodDescriptiongetSchemaFactory(String schemaLanguage) voidsetAccessExternalDtd(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 stylesheetssetCatalog(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 processedSets the schema that will be used to validate the XML source during parsing.Sets the schema that will be used to validate the XML source during parsing.setValidation(boolean validation) Defines if allowing or not the validation of the XML sources
-
Field Details
-
disallowDoctypeDecl
-
loadExternalDtd
-
externalGeneralEntities
-
externalParameterEntities
-
accessExternalDtd
-
accessExternalSchema
-
accessExternalStylesheet
-
validation
protected boolean validation -
catalog
-
schema
-
-
Constructor Details
-
XMLMode
public XMLMode()Object to configure XMLTree and other xml tools to define the parsing and building mode, in particular to restrict policies and to prevent security issues
See https://www.owasp.org/index.php/XML_External_Entity_(XXE)_Prevention_Cheat_Sheet
-
-
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 not 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 not 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
Defines if allowing or not the validation of the XML sources- Parameters:
validation-trueto allow andfalseto not validate XML during load- Returns:
thisinstance of XMLMode
-
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- Returns:
thisinstance of XMLMode
-
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:
xsdPath- Schema'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- Returns:
thisinstance of XMLMode
-
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:
xsdUrl- Url referencing the xsd file. It could point to a remote location or to an absolute path of the local filesystem- Returns:
thisinstance of XMLMode
-
getDocumentBuilder
public DocumentBuilder getDocumentBuilder(DocumentBuilderFactory dbf) throws ParserConfigurationException - Throws:
ParserConfigurationException
-
getTransformerFactory
-
getSchemaFactory
public SchemaFactory getSchemaFactory(String schemaLanguage) throws SAXNotRecognizedException, SAXNotSupportedException -
getSAXParser
public SAXParser getSAXParser(SAXParserFactory spf) throws ParserConfigurationException, SAXException
-