diff --git a/src/main/java/org/bonitasoft/connectors/ws/SecureWSConnector.java b/src/main/java/org/bonitasoft/connectors/ws/SecureWSConnector.java index 7215800..1fc63ac 100644 --- a/src/main/java/org/bonitasoft/connectors/ws/SecureWSConnector.java +++ b/src/main/java/org/bonitasoft/connectors/ws/SecureWSConnector.java @@ -29,6 +29,7 @@ import java.util.Map.Entry; import java.util.Objects; import java.util.logging.Logger; +import javax.xml.XMLConstants; import javax.xml.namespace.QName; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; @@ -109,7 +110,7 @@ public class SecureWSConnector extends AbstractConnector { private static final String PROXY_PASSWORD = "proxyPassword"; - private final Logger LOGGER = Logger.getLogger(this.getClass().getName()); + private final Logger logger = Logger.getLogger(this.getClass().getName()); private Transformer transformer; @@ -181,20 +182,19 @@ public class SecureWSConnector extends AbstractConnector { } } - @SuppressWarnings("unchecked") @Override protected void executeBusinessLogic() throws ConnectorException { configureProxy(); final String serviceNS = (String) getInputParameter(SERVICE_NS); - LOGGER.info(SERVICE_NS + " " + serviceNS); + logger.info(SERVICE_NS + " " + serviceNS); final String serviceName = (String) getInputParameter(SERVICE_NAME); - LOGGER.info(SERVICE_NAME + " " + serviceName); + logger.info(SERVICE_NAME + " " + serviceName); final String portName = (String) getInputParameter(PORT_NAME); - LOGGER.info(PORT_NAME + " " + portName); + logger.info(PORT_NAME + " " + portName); final String binding = (String) getInputParameter(BINDING); - LOGGER.info(BINDING + " " + binding); + logger.info(BINDING + " " + binding); final String endpointAddress = (String) getInputParameter(ENDPOINT_ADDRESS); - LOGGER.info(ENDPOINT_ADDRESS + " " + endpointAddress); + logger.info(ENDPOINT_ADDRESS + " " + endpointAddress); final QName serviceQName = new QName(serviceNS, serviceName); final QName portQName = new QName(serviceNS, portName); @@ -205,15 +205,15 @@ public class SecureWSConnector extends AbstractConnector { dispatch.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpointAddress); final Object authUserName = getInputParameter(USER_NAME); if (authUserName != null) { - LOGGER.info(USER_NAME + " " + authUserName); + logger.info(USER_NAME + " " + authUserName); dispatch.getRequestContext().put(BindingProvider.USERNAME_PROPERTY, authUserName); final Object authPassword = getInputParameter(PASSWORD); - LOGGER.info(PASSWORD + " ********"); + logger.info(PASSWORD + " ********"); dispatch.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, authPassword); } final String soapAction = (String) getInputParameter(SOAP_ACTION); - LOGGER.info(SOAP_ACTION + " " + soapAction); + logger.info(SOAP_ACTION + " " + soapAction); if (soapAction != null) { dispatch.getRequestContext().put(BindingProvider.SOAPACTION_USE_PROPERTY, true); @@ -245,9 +245,9 @@ public class SecureWSConnector extends AbstractConnector { String initialEnvelope = (String) getInputParameter(ENVELOPE); String sanitizedEnvelope = sanitizeString(initialEnvelope); if (!Objects.equals(initialEnvelope, sanitizedEnvelope)) { - LOGGER.warning("Invalid XML characters have been detected in the envelope, they will be removed."); + logger.warning("Invalid XML characters have been detected in the envelope, they will be removed."); } - LOGGER.info(ENVELOPE + " " + sanitizedEnvelope); + logger.info(ENVELOPE + " " + sanitizedEnvelope); Boolean oneWayInvoke = (Boolean) getInputParameter(ONE_WAY_INVOKE); if (oneWayInvoke == null) { @@ -268,9 +268,9 @@ public class SecureWSConnector extends AbstractConnector { restoreConfiguration(); Boolean buildResponseDocumentEnvelope = (Boolean) getInputParameter(BUILD_RESPONSE_DOCUMENT_ENVELOPE); - LOGGER.info(BUILD_RESPONSE_DOCUMENT_ENVELOPE + " " + buildResponseDocumentEnvelope); + logger.info(BUILD_RESPONSE_DOCUMENT_ENVELOPE + " " + buildResponseDocumentEnvelope); Boolean buildResponseDocumentBody = (Boolean) getInputParameter(BUILD_RESPONSE_DOCUMENT_BODY); - LOGGER.info(BUILD_RESPONSE_DOCUMENT_BODY + " " + buildResponseDocumentBody); + logger.info(BUILD_RESPONSE_DOCUMENT_BODY + " " + buildResponseDocumentBody); if (buildResponseDocumentEnvelope == null) { buildResponseDocumentEnvelope = false; } @@ -288,7 +288,7 @@ public class SecureWSConnector extends AbstractConnector { } Boolean printRequestAndResponse = (Boolean) getInputParameter(PRINT_REQUEST_AND_RESPONSE); - LOGGER.info(PRINT_REQUEST_AND_RESPONSE + " " + printRequestAndResponse); + logger.info(PRINT_REQUEST_AND_RESPONSE + " " + printRequestAndResponse); if (printRequestAndResponse == null) { printRequestAndResponse = false; } @@ -323,30 +323,30 @@ public class SecureWSConnector extends AbstractConnector { if (host == null || host.isEmpty()) { return; } - LOGGER.info(PROXY_HOST + " " + host); + logger.info(PROXY_HOST + " " + host); final String protocol = (String) getInputParameter(PROXY_PROTOCOL); - LOGGER.info(PROXY_PROTOCOL + " " + protocol); + logger.info(PROXY_PROTOCOL + " " + protocol); final String port = (String) getInputParameter(PROXY_PORT); - LOGGER.info(PROXY_PORT + " " + port); + logger.info(PROXY_PORT + " " + port); if (SOCKS.equals(protocol)) { System.setProperty("socksProxyHost", host); - LOGGER.info("Setting environment variable: socksProxyHost=" + host); + logger.info("Setting environment variable: socksProxyHost=" + host); System.setProperty("socksProxyPort", port); - LOGGER.info("Setting environment variable: socksProxyPort=" + port); + logger.info("Setting environment variable: socksProxyPort=" + port); } else { final String hostKey = String.format("%s.proxyHost", protocol.toLowerCase()); System.setProperty(hostKey, host); - LOGGER.info("Setting environment variable: " + hostKey + "=" + host); + logger.info("Setting environment variable: " + hostKey + "=" + host); final String portKey = String.format("%s.proxyPort", protocol.toLowerCase()); System.setProperty(portKey, port); - LOGGER.info("Setting environment variable: " + portKey + "=" + port); + logger.info("Setting environment variable: " + portKey + "=" + port); } final String user = (String) getInputParameter(PROXY_USER); - LOGGER.info(PROXY_USER + " " + user); + logger.info(PROXY_USER + " " + user); final String password = (String) getInputParameter(PROXY_PASSWORD); - LOGGER.info(PROXY_PASSWORD + " ********"); + logger.info(PROXY_PASSWORD + " ********"); if (user != null && !user.isEmpty()) { Authenticator.setDefault(new Authenticator() { @@ -392,7 +392,10 @@ public class SecureWSConnector extends AbstractConnector { Document responseDocumentBody = null; if (responseDocumentEnvelope != null) { try { - responseDocumentBody = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(); + DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); + documentBuilderFactory.setAttribute(XMLConstants.ACCESS_EXTERNAL_DTD, ""); + documentBuilderFactory.setAttribute(XMLConstants.ACCESS_EXTERNAL_SCHEMA, ""); + responseDocumentBody = documentBuilderFactory.newDocumentBuilder().newDocument(); } catch (final ParserConfigurationException pce) { throw new ConnectorException(pce); } @@ -417,7 +420,7 @@ public class SecureWSConnector extends AbstractConnector { getTransformer().transform(new DOMSource(responseDocumentBody), new StreamResult(System.err)); } } catch (final TransformerException e) { - e.printStackTrace(); + logger.severe(e.getMessage()); } } @@ -452,7 +455,10 @@ public class SecureWSConnector extends AbstractConnector { Transformer getTransformer() throws TransformerConfigurationException { if (transformer == null) { - transformer = TransformerFactory.newInstance().newTransformer(); + TransformerFactory transformerFactory = TransformerFactory.newInstance(); + transformerFactory.setAttribute(XMLConstants.ACCESS_EXTERNAL_DTD, ""); + transformerFactory.setAttribute(XMLConstants.ACCESS_EXTERNAL_STYLESHEET, ""); + transformer = transformerFactory.newTransformer(); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2"); }