|
31 | 31 | import java.security.UnrecoverableKeyException; |
32 | 32 | import java.security.cert.CertificateException; |
33 | 33 | import java.security.cert.X509Certificate; |
| 34 | +import java.util.ArrayList; |
| 35 | +import java.util.Collections; |
34 | 36 | import java.util.HashMap; |
35 | 37 | import java.util.List; |
36 | 38 | import java.util.Map; |
|
41 | 43 | import javax.inject.Inject; |
42 | 44 | import javax.naming.ConfigurationException; |
43 | 45 |
|
| 46 | +import org.apache.commons.lang.StringEscapeUtils; |
44 | 47 | import org.apache.http.HttpResponse; |
45 | 48 | import org.apache.http.HttpStatus; |
46 | 49 | import org.apache.http.client.ClientProtocolException; |
|
130 | 133 | import com.cloud.utils.ssh.SshHelper; |
131 | 134 | import com.cloud.vm.VirtualMachine; |
132 | 135 | import com.cloud.vm.VirtualMachineName; |
133 | | - |
134 | 136 | /** |
135 | 137 | * Implementation of dummy resource to be returned from discoverer. |
136 | 138 | **/ |
@@ -472,8 +474,8 @@ public final Answer executeRequest(final Command cmd) { |
472 | 474 | // Only Answer instances are returned by remote agents. |
473 | 475 | // E.g. see Response.getAnswers() |
474 | 476 | Answer[] result = s_gson.fromJson(ansStr, Answer[].class); |
475 | | - s_logger.debug("executeRequest received response " |
476 | | - + s_gson.toJson(result)); |
| 477 | + String logResult = cleanPassword(StringEscapeUtils.unescapeJava(result.toString())); |
| 478 | + s_logger.debug("executeRequest received response " + logResult); |
477 | 479 | if (result.length > 0) { |
478 | 480 | return result[0]; |
479 | 481 | } |
@@ -1741,8 +1743,10 @@ public static String postHttpRequest(final String jsonCmd, |
1741 | 1743 | // comment to use Apache HttpClient |
1742 | 1744 | // http://stackoverflow.com/a/2793153/939250, but final comment is to |
1743 | 1745 | // use Apache. |
1744 | | - s_logger.debug("POST request to" + agentUri.toString() |
1745 | | - + " with contents" + jsonCmd); |
| 1746 | + String logMessage = StringEscapeUtils.unescapeJava(jsonCmd); |
| 1747 | + logMessage = cleanPassword(logMessage); |
| 1748 | + s_logger.debug("POST request to " + agentUri.toString() |
| 1749 | + + " with contents " + logMessage); |
1746 | 1750 |
|
1747 | 1751 | // Create request |
1748 | 1752 | HttpClient httpClient = null; |
@@ -1783,7 +1787,7 @@ public boolean isTrusted(X509Certificate[] chain, String authType) |
1783 | 1787 | request.addHeader("content-type", "application/json"); |
1784 | 1788 | request.setEntity(cmdJson); |
1785 | 1789 | s_logger.debug("Sending cmd to " + agentUri.toString() |
1786 | | - + " cmd data:" + jsonCmd); |
| 1790 | + + " cmd data:" + logMessage); |
1787 | 1791 | HttpResponse response = httpClient.execute(request); |
1788 | 1792 |
|
1789 | 1793 | // Unsupported commands will not route. |
@@ -1811,7 +1815,8 @@ public boolean isTrusted(X509Certificate[] chain, String authType) |
1811 | 1815 | return null; |
1812 | 1816 | } else { |
1813 | 1817 | result = EntityUtils.toString(response.getEntity()); |
1814 | | - s_logger.debug("POST response is" + result); |
| 1818 | + String logResult = cleanPassword(StringEscapeUtils.unescapeJava(result)); |
| 1819 | + s_logger.debug("POST response is " + logResult); |
1815 | 1820 | } |
1816 | 1821 | } catch (ClientProtocolException protocolEx) { |
1817 | 1822 | // Problem with HTTP message exchange |
@@ -1937,4 +1942,22 @@ protected String connect(final String vmName, final String ipAddress, final int |
1937 | 1942 | return "Unable to connect"; |
1938 | 1943 | } |
1939 | 1944 |
|
| 1945 | + public static String cleanPassword(String logString) { |
| 1946 | + String cleanLogString = null; |
| 1947 | + if (logString != null) { |
| 1948 | + cleanLogString = logString; |
| 1949 | + String[] temp = logString.split(","); |
| 1950 | + int i = 0; |
| 1951 | + if (temp != null) { |
| 1952 | + while (i < temp.length) { |
| 1953 | + temp[i] = StringUtils.cleanString(temp[i]); |
| 1954 | + i++; |
| 1955 | + } |
| 1956 | + List<String> stringList = new ArrayList<String>(); |
| 1957 | + Collections.addAll(stringList, temp); |
| 1958 | + cleanLogString = StringUtils.join(stringList, ","); |
| 1959 | + } |
| 1960 | + } |
| 1961 | + return cleanLogString; |
| 1962 | + } |
1940 | 1963 | } |
0 commit comments