diff --git a/agent/src/main/java/com/cloud/agent/resource/consoleproxy/ConsoleProxyResource.java b/agent/src/main/java/com/cloud/agent/resource/consoleproxy/ConsoleProxyResource.java index 26f9d4b3d732..abd34dc5c15d 100644 --- a/agent/src/main/java/com/cloud/agent/resource/consoleproxy/ConsoleProxyResource.java +++ b/agent/src/main/java/com/cloud/agent/resource/consoleproxy/ConsoleProxyResource.java @@ -331,7 +331,7 @@ private void launchConsoleProxy(final byte[] ksBits, final String ksPassword, fi final Object resource = this; logger.info("Building class loader for com.cloud.consoleproxy.ConsoleProxy"); if (consoleProxyMain == null) { - logger.info("Running com.cloud.consoleproxy.ConsoleProxy with encryptor password={}", encryptorPassword); + logger.info("Running com.cloud.consoleproxy.ConsoleProxy with encryptor password={}", "******"); consoleProxyMain = new Thread(new ManagedContextRunnable() { @Override protected void runInContext() { diff --git a/core/src/main/java/com/cloud/storage/template/HttpTemplateDownloader.java b/core/src/main/java/com/cloud/storage/template/HttpTemplateDownloader.java index 4c056f256cf0..47f531c2520a 100755 --- a/core/src/main/java/com/cloud/storage/template/HttpTemplateDownloader.java +++ b/core/src/main/java/com/cloud/storage/template/HttpTemplateDownloader.java @@ -151,7 +151,7 @@ private void checkCredentials(String user, String password) { client.getParams().setAuthenticationPreemptive(true); Credentials defaultcreds = new UsernamePasswordCredentials(user, password); client.getState().setCredentials(new AuthScope(hostAndPort.first(), hostAndPort.second(), AuthScope.ANY_REALM), defaultcreds); - logger.info("Added username=" + user + ", password=" + password + "for host " + hostAndPort.first() + ":" + hostAndPort.second()); + logger.info("Added username={}, password=****** for host {}:{}”, user, hostAndPort.first(), hostAndPort.second()); } else { logger.info("No credentials configured for host=" + hostAndPort.first() + ":" + hostAndPort.second()); } diff --git a/engine/schema/src/main/java/com/cloud/upgrade/DatabaseCreator.java b/engine/schema/src/main/java/com/cloud/upgrade/DatabaseCreator.java index 384826227af7..cccfbe8a0065 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/DatabaseCreator.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/DatabaseCreator.java @@ -99,7 +99,7 @@ private static void initDB(String dbPropsFile, String rootPassword, String[] dat String username = dbProperties.getProperty(String.format("db.%s.username", database)); String password = dbProperties.getProperty(String.format("db.%s.password", database)); String dbName = dbProperties.getProperty(String.format("db.%s.name", database)); - System.out.println(String.format("========> Initializing database=%s with host=%s port=%s username=%s password=%s", dbName, host, port, username, password)); + System.out.println(String.format("========> Initializing database=%s with host=%s port=%s username=%s password=******", dbName, host, port, username)); List queries = new ArrayList(); queries.add(String.format("drop database if exists `%s`", dbName)); diff --git a/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/BaremetalDnsmasqResource.java b/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/BaremetalDnsmasqResource.java index 51acfe93d39e..0cc403a31d9f 100644 --- a/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/BaremetalDnsmasqResource.java +++ b/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/BaremetalDnsmasqResource.java @@ -46,10 +46,10 @@ public boolean configure(String name, Map params) throws Configu com.trilead.ssh2.Connection sshConnection = null; try { super.configure(name, params); - logger.debug(String.format("Trying to connect to DHCP server(IP=%1$s, username=%2$s, password=%3$s)", _ip, _username, _password)); + logger.debug(String.format("Trying to connect to DHCP server(IP=%1$s, username=%2$s, password=%3$s)", _ip, _username, "******")); sshConnection = SSHCmdHelper.acquireAuthorizedConnection(_ip, _username, _password); if (sshConnection == null) { - throw new ConfigurationException(String.format("Cannot connect to DHCP server(IP=%1$s, username=%2$s, password=%3$s", _ip, _username, _password)); + throw new ConfigurationException(String.format("Cannot connect to DHCP server(IP=%1$s, username=%2$s, password=%3$s", _ip, _username, "******")); } if (!SSHCmdHelper.sshExecuteCmd(sshConnection, "[ -f '/usr/sbin/dnsmasq' ]")) { diff --git a/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/BaremetalKickStartPxeResource.java b/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/BaremetalKickStartPxeResource.java index 3775f4effc17..30c9775311fb 100644 --- a/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/BaremetalKickStartPxeResource.java +++ b/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/BaremetalKickStartPxeResource.java @@ -131,7 +131,7 @@ private Answer execute(VmDataCommand cmd) { sshConnection.connect(null, 60000, 60000); if (!sshConnection.authenticateWithPassword(_username, _password)) { logger.debug("SSH Failed to authenticate"); - throw new ConfigurationException(String.format("Cannot connect to PING PXE server(IP=%1$s, username=%2$s, password=%3$s", _ip, _username, _password)); + throw new ConfigurationException(String.format("Cannot connect to PING PXE server(IP=%1$s, username=%2$s, password=%3$s", _ip, _username, "******")); } String script = String.format("python /usr/bin/baremetal_user_data.py '%s'", arg); @@ -167,7 +167,7 @@ private Answer execute(PrepareKickstartPxeServerCommand cmd) { sshConnection.connect(null, 60000, 60000); if (!sshConnection.authenticateWithPassword(_username, _password)) { logger.debug("SSH Failed to authenticate"); - throw new ConfigurationException(String.format("Cannot connect to PING PXE server(IP=%1$s, username=%2$s, password=%3$s", _ip, _username, _password)); + throw new ConfigurationException(String.format("Cannot connect to PING PXE server(IP=%1$s, username=%2$s, password=%3$s", _ip, _username, "******")); } String copyTo = String.format("%s/%s", _tftpDir, cmd.getTemplateUuid()); diff --git a/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/BaremetalPingPxeResource.java b/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/BaremetalPingPxeResource.java index 96b2dbfeb935..634db90e5332 100644 --- a/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/BaremetalPingPxeResource.java +++ b/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/BaremetalPingPxeResource.java @@ -151,7 +151,7 @@ protected PreparePxeServerAnswer execute(PreparePxeServerCommand cmd) { sshConnection.connect(null, 60000, 60000); if (!sshConnection.authenticateWithPassword(_username, _password)) { logger.debug("SSH Failed to authenticate"); - throw new ConfigurationException(String.format("Cannot connect to PING PXE server(IP=%1$s, username=%2$s, password=%3$s", _ip, _username, _password)); + throw new ConfigurationException(String.format("Cannot connect to PING PXE server(IP=%1$s, username=%2$s, password=%3$s", _ip, _username, "******")); } String script = @@ -179,7 +179,7 @@ protected Answer execute(PrepareCreateTemplateCommand cmd) { sshConnection.connect(null, 60000, 60000); if (!sshConnection.authenticateWithPassword(_username, _password)) { logger.debug("SSH Failed to authenticate"); - throw new ConfigurationException(String.format("Cannot connect to PING PXE server(IP=%1$s, username=%2$s, password=%3$s", _ip, _username, _password)); + throw new ConfigurationException(String.format("Cannot connect to PING PXE server(IP=%1$s, username=%2$s, password=%3$s", _ip, _username, "******")); } String script = @@ -237,7 +237,7 @@ private Answer execute(VmDataCommand cmd) { sshConnection.connect(null, 60000, 60000); if (!sshConnection.authenticateWithPassword(_username, _password)) { logger.debug("SSH Failed to authenticate"); - throw new ConfigurationException(String.format("Cannot connect to PING PXE server(IP=%1$s, username=%2$s, password=%3$s", _ip, _username, _password)); + throw new ConfigurationException(String.format("Cannot connect to PING PXE server(IP=%1$s, username=%2$s, password=%3$s", _ip, _username, "******")); } String script = String.format("python /usr/bin/baremetal_user_data.py '%s'", arg); diff --git a/server/src/main/java/com/cloud/servlet/ConsoleProxyServlet.java b/server/src/main/java/com/cloud/servlet/ConsoleProxyServlet.java index 265a975af245..efafc798d0af 100644 --- a/server/src/main/java/com/cloud/servlet/ConsoleProxyServlet.java +++ b/server/src/main/java/com/cloud/servlet/ConsoleProxyServlet.java @@ -534,7 +534,7 @@ private boolean verifyRequest(Map requestParameters) { // if api/secret key are passed to the parameters if ((signature == null) || (apiKey == null)) { if (LOGGER.isDebugEnabled()) { - LOGGER.debug("expired session, missing signature, or missing apiKey -- ignoring request...sig: " + signature + ", apiKey: " + apiKey); + LOGGER.debug("expired session, missing signature, or missing apiKey -- ignoring request"); } return false; // no signature, bad request } diff --git a/server/src/main/java/com/cloud/user/AccountManagerImpl.java b/server/src/main/java/com/cloud/user/AccountManagerImpl.java index bbfc8fd36826..122d4e395cae 100644 --- a/server/src/main/java/com/cloud/user/AccountManagerImpl.java +++ b/server/src/main/java/com/cloud/user/AccountManagerImpl.java @@ -3006,7 +3006,8 @@ private UserAccount getUserAccountForSSO(String username, Long domainId, Map getUserDetails(String query) { // Get the size of a file from URL response header. public static long getRemoteSize(String url, Boolean followRedirect) { long remoteSize = 0L; - final String[] methods = new String[]{"HEAD", "GET"}; + final String[] methods = new String[] { "HEAD", "GET" }; IllegalArgumentException exception = null; // Attempting first a HEAD request to avoid downloading the whole file. If // it fails (for example with S3 presigned URL), fallback on a standard GET @@ -225,7 +228,7 @@ public static long getRemoteSize(String url, Boolean followRedirect) { HttpURLConnection httpConn = null; try { URI uri = new URI(url); - httpConn = (HttpURLConnection)uri.toURL().openConnection(); + httpConn = (HttpURLConnection) uri.toURL().openConnection(); httpConn.setRequestMethod(method); httpConn.setConnectTimeout(2000); httpConn.setReadTimeout(5000); @@ -268,16 +271,25 @@ public static Pair validateUrl(String format, String url) throw /** * Verifies whether the provided URL is valid. - * @param skipHostCheck if false, this function will verify whether the provided URL is resolvable, if it is a legal address and if it does not use IPv6 (configured by `skipIpv6Check`). If any of these conditions are false, an exception will be thrown. - * @param skipIpv6Check if false, this function will verify whether the host uses IPv6 and, if it does, an exception will be thrown. This check is also skipped if `skipHostCheck` is true. + * + * @param skipHostCheck if false, this function will verify whether the provided + * URL is resolvable, if it is a legal address and if it + * does not use IPv6 (configured by `skipIpv6Check`). If + * any of these conditions are false, an exception will be + * thrown. + * @param skipIpv6Check if false, this function will verify whether the host + * uses IPv6 and, if it does, an exception will be thrown. + * This check is also skipped if `skipHostCheck` is true. * @return a pair containing the host and the corresponding port. * @throws IllegalArgumentException if the provided URL is invalid. */ - public static Pair validateUrl(String format, String url, boolean skipHostCheck, boolean skipIpv6Check) throws IllegalArgumentException { + public static Pair validateUrl(String format, String url, boolean skipHostCheck, + boolean skipIpv6Check) throws IllegalArgumentException { try { URI uri = new URI(url); if ((uri.getScheme() == null) || - (!uri.getScheme().equalsIgnoreCase("http") && !uri.getScheme().equalsIgnoreCase("https") && !uri.getScheme().equalsIgnoreCase("file"))) { + (!uri.getScheme().equalsIgnoreCase("http") && !uri.getScheme().equalsIgnoreCase("https") + && !uri.getScheme().equalsIgnoreCase("file"))) { throw new IllegalArgumentException("Unsupported scheme for url: " + url); } @@ -305,21 +317,26 @@ public static Pair validateUrl(String format, String url, boole } /** - * Verifies whether the provided host is valid. Throws an `IllegalArgumentException` if: + * Verifies whether the provided host is valid. Throws an + * `IllegalArgumentException` if: *
    - *
  • The host is not resolvable;
  • - *
  • The host address is illegal (any local, link local, loopback or multicast address);
  • - *
  • The host uses IPv6. This check is skipped if `skipIv6Check` is set to true.
  • + *
  • The host is not resolvable;
  • + *
  • The host address is illegal (any local, link local, loopback or multicast + * address);
  • + *
  • The host uses IPv6. This check is skipped if `skipIv6Check` is set to + * true.
  • *
*/ private static void checkHost(String host, boolean skipIpv6Check) { try { InetAddress hostAddr = InetAddress.getByName(host); - if (hostAddr.isAnyLocalAddress() || hostAddr.isLinkLocalAddress() || hostAddr.isLoopbackAddress() || hostAddr.isMulticastAddress()) { + if (hostAddr.isAnyLocalAddress() || hostAddr.isLinkLocalAddress() || hostAddr.isLoopbackAddress() + || hostAddr.isMulticastAddress()) { throw new IllegalArgumentException("Illegal host specified in URL."); } if (!skipIpv6Check && hostAddr instanceof Inet6Address) { - throw new IllegalArgumentException(String.format("IPv6 addresses are not supported (%s).", hostAddr.getHostAddress())); + throw new IllegalArgumentException( + String.format("IPv6 addresses are not supported (%s).", hostAddr.getHostAddress())); } } catch (UnknownHostException uhe) { throw new IllegalArgumentException(String.format("Unable to resolve %s.", host)); @@ -327,14 +344,16 @@ private static void checkHost(String host, boolean skipIpv6Check) { } /** - * Add element to priority list examining node attributes: priority (for urls) and type (for checksums) + * Add element to priority list examining node attributes: priority (for urls) + * and type (for checksums) */ - protected static void addPriorityListElementExaminingNode(String tagName, Node node, List> priorityList) { + protected static void addPriorityListElementExaminingNode(String tagName, Node node, + List> priorityList) { Integer priority = Integer.MAX_VALUE; String first = node.getTextContent(); if (node.hasAttributes()) { NamedNodeMap attributes = node.getAttributes(); - for (int k=0; k> getMultipleValuesFromXML(InputStream is, String[] tagNames) { Map> returnValues = new HashMap>(); @@ -400,7 +420,8 @@ public static Map> getMultipleValuesFromXML(InputStream is, } /** - * Get list of urls on metalink ordered by ascending priority (for those which priority tag is not defined, highest priority value is assumed) + * Get list of urls on metalink ordered by ascending priority (for those which + * priority tag is not defined, highest priority value is assumed) */ public static List getMetalinkUrls(String metalinkUrl) { HttpClient httpClient = getHttpClient(); @@ -417,7 +438,7 @@ public static List getMetalinkUrls(String metalinkUrl) { try { InputStream is = getMethod.getResponseBodyAsStream(); if (status == HttpStatus.SC_OK) { - Map> metalinkUrlsMap = getMultipleValuesFromXML(is, new String[] {"url"}); + Map> metalinkUrlsMap = getMultipleValuesFromXML(is, new String[] { "url" }); if (metalinkUrlsMap.containsKey("url")) { List metalinkUrls = metalinkUrlsMap.get("url"); urls.addAll(metalinkUrls); @@ -450,16 +471,16 @@ public static final Set buildExtensionSet(boolean metalink, String... ba return builder.build(); } - private final static Map> SUPPORTED_EXTENSIONS_BY_FORMAT = - ImmutableMap.>builder() - .put("vhd", buildExtensionSet(false, "vhd")) - .put("vhdx", buildExtensionSet(false, "vhdx")) - .put("qcow2", buildExtensionSet(true, "qcow2", "img")) - .put("ova", buildExtensionSet(true, "ova")) - .put("tar", buildExtensionSet(false, "tar")) - .put("raw", buildExtensionSet(false, "img", "raw")) - .put("vmdk", buildExtensionSet(false, "vmdk")) - .put("iso", buildExtensionSet(true, "iso")) + private final static Map> SUPPORTED_EXTENSIONS_BY_FORMAT = ImmutableMap + .>builder() + .put("vhd", buildExtensionSet(false, "vhd")) + .put("vhdx", buildExtensionSet(false, "vhdx")) + .put("qcow2", buildExtensionSet(true, "qcow2", "img")) + .put("ova", buildExtensionSet(true, "ova")) + .put("tar", buildExtensionSet(false, "tar")) + .put("raw", buildExtensionSet(false, "img", "raw")) + .put("vmdk", buildExtensionSet(false, "vmdk")) + .put("iso", buildExtensionSet(true, "iso")) .build(); public final static Set getSupportedExtensions(String format) { @@ -471,24 +492,23 @@ private static void checkFormat(String format, String uripath) { final String lowerCaseUri = uripath.toLowerCase(); final boolean unknownExtensionForFormat = SUPPORTED_EXTENSIONS_BY_FORMAT.get(format.toLowerCase()) - .stream() - .noneMatch(lowerCaseUri::endsWith); + .stream() + .noneMatch(lowerCaseUri::endsWith); if (unknownExtensionForFormat) { - final Predicate> uriMatchesAnyExtension = - supportedExtensions -> supportedExtensions.stream() - .anyMatch(lowerCaseUri::endsWith); + final Predicate> uriMatchesAnyExtension = supportedExtensions -> supportedExtensions.stream() + .anyMatch(lowerCaseUri::endsWith); boolean unknownExtension = SUPPORTED_EXTENSIONS_BY_FORMAT.values() - .stream() - .noneMatch(uriMatchesAnyExtension); + .stream() + .noneMatch(uriMatchesAnyExtension); if (unknownExtension) { throw new IllegalArgumentException("Please specify a valid " + format.toLowerCase()); } throw new IllegalArgumentException("Please specify a valid URL. " - + "URL:" + uripath + " is an invalid for the format " + format.toLowerCase()); + + "URL:" + uripath + " is an invalid for the format " + format.toLowerCase()); } } @@ -500,8 +520,10 @@ public static InputStream getInputStreamFromUrl(String url, String user, String if ((user != null) && (password != null)) { httpclient.getParams().setAuthenticationPreemptive(true); Credentials defaultcreds = new UsernamePasswordCredentials(user, password); - httpclient.getState().setCredentials(new AuthScope(hostAndPort.first(), hostAndPort.second(), AuthScope.ANY_REALM), defaultcreds); - LOGGER.info("Added username=" + user + ", password=" + password + "for host " + hostAndPort.first() + ":" + hostAndPort.second()); + httpclient.getState().setCredentials( + new AuthScope(hostAndPort.first(), hostAndPort.second(), AuthScope.ANY_REALM), defaultcreds); + LOGGER.info("Added username=" + user + ", password=****** " + "for host " + hostAndPort.first() + ":" + + hostAndPort.second()); } // Execute the method. GetMethod method = new GetMethod(url); @@ -521,6 +543,7 @@ public static InputStream getInputStreamFromUrl(String url, String user, String /** * Expands a given vlan URI to a list of vlan IDs + * * @param vlanAuthority the URI part without the vlan:// scheme * @return returns list of vlan integer ids */ @@ -529,7 +552,7 @@ public static List expandVlanUri(final String vlanAuthority) { if (StringUtils.isEmpty(vlanAuthority)) { return expandedVlans; } - for (final String vlanPart: vlanAuthority.split(",")) { + for (final String vlanPart : vlanAuthority.split(",")) { if (StringUtils.isEmpty(vlanPart)) { continue; } @@ -554,6 +577,7 @@ public static List expandVlanUri(final String vlanAuthority) { /** * Checks if given vlan URI authorities overlap + * * @param vlanRange1 * @param vlanRange2 * @return true if they overlap @@ -652,10 +676,10 @@ private static UriInfo getRbdUrlInfo(String url) { String hostInfo = (firstAt == -1) ? url : StringUtils.substring(url, firstAt + 1, url.length()); int firstSlash = StringUtils.indexOf(hostInfo, "/"); - int lastColon = StringUtils.lastIndexOf(hostInfo,":"); - int lastSquareBracket = StringUtils.lastIndexOf(hostInfo,"]"); - int endOfHost = lastColon == -1 ? (firstSlash > 0 ? firstSlash : hostInfo.length() + 1) : - (lastSquareBracket > lastColon ? lastSquareBracket + 1 : lastColon); + int lastColon = StringUtils.lastIndexOf(hostInfo, ":"); + int lastSquareBracket = StringUtils.lastIndexOf(hostInfo, "]"); + int endOfHost = lastColon == -1 ? (firstSlash > 0 ? firstSlash : hostInfo.length() + 1) + : (lastSquareBracket > lastColon ? lastSquareBracket + 1 : lastColon); String storageHosts = StringUtils.substring(hostInfo, 0, endOfHost); String firstHost = storageHosts.split(",")[0]; String strAfterHosts = StringUtils.substring(hostInfo, endOfHost);