File size: 9,517 Bytes
62cfde8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
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");
         }