ppkarwasz commented on code in PR #2635:
URL: https://github.com/apache/activemq/pull/2635#discussion_r4179188400


##########
activemq-console/src/main/java/org/apache/activemq/console/command/CreateCommand.java:
##########
@@ -158,10 +160,10 @@ protected void copyActivemqConf(File srcBase, File 
targetBase, String activemqCo
         File dest = new File(targetBase, DEFAULT_TARGET_ACTIVEMQ_CONF);
         context.print("Copying from: " + src.getCanonicalPath() + "\n          
to: " + dest.getCanonicalPath());
 
-        DocumentBuilder builder = 
XmlFactories.getSafeDocumentBuilderFactory().newDocumentBuilder();
+        DocumentBuilder builder = 
SecureDocumentBuilderFactory.newNSInstance().newDocumentBuilder();
         Element docElem = builder.parse(src).getDocumentElement();
 
-        XPath xpath = XPathFactory.newInstance().newXPath();
+        XPath xpath = SecureXPathFactory.newInstance().newXPath();
         Attr brokerNameAttr = (Attr) xpath.evaluate(DEFAULT_BROKERNAME_XPATH, 
docElem, XPathConstants.NODE);

Review Comment:
   This will create a problem with namespaces: the XPath used is 
`/beans/broker/@brokerName`, but both `beans` and `broker` have a namespace, so 
the XPath will not find anything with a namespace sensitive parser.
   
   I see a couple of solutions:
   
   1. Use `newInstance()` instead of `newNSInstance()`, but this means this 
path can not upgrade to `newNSDocumentBuilder()`.
   2. Change the XPath expression to 
`/*[local-name()='beans'/*[local-name()='broker']/@brokerName`.
   3. Or use DOM to find the attribute:
   
      ```java
      Element brokerElement = (Element) docElem.getElementsByTagNameNS("*", 
"broker").item(0);
      Attr brokerNameAttr = brokerElement.getAttributeNodeNS(null, 
"brokerName");
      ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
For further information, visit: https://activemq.apache.org/contact


Reply via email to