From fe4a24a65131c3414a4805270959dc0fc2e3746e Mon Sep 17 00:00:00 2001 From: Jeremy Long Date: Wed, 18 Mar 2015 10:07:01 -0400 Subject: [PATCH] removed nexus auth test code Former-commit-id: 9b5f8cbceb5a6a273dfd7ba85bf16510dab3ddb5 --- .../data/nexus/NexusSearch.java | 27 ++--------------- .../owasp/dependencycheck/utils/Settings.java | 8 ----- .../utils/URLConnectionFactory.java | 29 ------------------- 3 files changed, 2 insertions(+), 62 deletions(-) diff --git a/dependency-check-core/src/main/java/org/owasp/dependencycheck/data/nexus/NexusSearch.java b/dependency-check-core/src/main/java/org/owasp/dependencycheck/data/nexus/NexusSearch.java index 1e9d5b9c7..a1a66ab25 100644 --- a/dependency-check-core/src/main/java/org/owasp/dependencycheck/data/nexus/NexusSearch.java +++ b/dependency-check-core/src/main/java/org/owasp/dependencycheck/data/nexus/NexusSearch.java @@ -74,23 +74,9 @@ public class NexusSearch { && Settings.getBoolean(Settings.KEYS.ANALYZER_NEXUS_PROXY)) { useProxy = true; LOGGER.fine("Using proxy"); - if (Settings.getString(Settings.KEYS.ANALYZER_NEXUS_USER) != null) { - LOGGER.fine("Unable to use nexus authentication while using a proxy. Consider disabling the use of a proxy with Nexus."); - } } else { useProxy = false; LOGGER.fine("Not using proxy"); - userName = Settings.getString(Settings.KEYS.ANALYZER_NEXUS_USER); - String tmp = Settings.getString(Settings.KEYS.ANALYZER_NEXUS_PASSWORD); - if (tmp != null) { - password = tmp.toCharArray(); - } else { - if (userName != null) { - userName = null; - LOGGER.fine("Nexus password is not set yet user name was configured. Disabling the use of authentication for Nexus."); - } - } - } } catch (InvalidSettingException ise) { useProxy = false; @@ -120,12 +106,7 @@ public class NexusSearch { // 2) Otherwise, don't use the proxy (either the proxy isn't configured, // or proxy is specifically set to false HttpURLConnection conn; - if (useProxy && userName == null) { - conn = URLConnectionFactory.createHttpURLConnection(url, useProxy); - } else { - conn = URLConnectionFactory.createHttpURLConnection(url, userName, password); - } - + conn = URLConnectionFactory.createHttpURLConnection(url, useProxy); conn.setDoOutput(true); // JSON would be more elegant, but there's not currently a dependency @@ -190,11 +171,7 @@ public class NexusSearch { HttpURLConnection conn; try { URL url = new URL(rootURL, "status"); - if (useProxy && userName == null) { - conn = URLConnectionFactory.createHttpURLConnection(url, useProxy); - } else { - conn = URLConnectionFactory.createHttpURLConnection(url, userName, password); - } + conn = URLConnectionFactory.createHttpURLConnection(url, useProxy); conn.addRequestProperty("Accept", "application/xml"); conn.connect(); if (conn.getResponseCode() != 200) { diff --git a/dependency-check-utils/src/main/java/org/owasp/dependencycheck/utils/Settings.java b/dependency-check-utils/src/main/java/org/owasp/dependencycheck/utils/Settings.java index 89c94a7de..40c495c20 100644 --- a/dependency-check-utils/src/main/java/org/owasp/dependencycheck/utils/Settings.java +++ b/dependency-check-utils/src/main/java/org/owasp/dependencycheck/utils/Settings.java @@ -200,14 +200,6 @@ public final class Settings { * The properties key for using the proxy to reach Nexus. */ public static final String ANALYZER_NEXUS_PROXY = "analyzer.nexus.proxy"; - /** - * The properties key for the Nexus user name. - */ - public static final String ANALYZER_NEXUS_USER = "analyzer.nexus.user"; - /** - * The properties key for the Nexus user's password. - */ - public static final String ANALYZER_NEXUS_PASSWORD = "analyzer.nexus.password"; /** * The properties key for whether the Central analyzer is enabled. */ diff --git a/dependency-check-utils/src/main/java/org/owasp/dependencycheck/utils/URLConnectionFactory.java b/dependency-check-utils/src/main/java/org/owasp/dependencycheck/utils/URLConnectionFactory.java index 3b3f7a5f6..b0b40ece8 100644 --- a/dependency-check-utils/src/main/java/org/owasp/dependencycheck/utils/URLConnectionFactory.java +++ b/dependency-check-utils/src/main/java/org/owasp/dependencycheck/utils/URLConnectionFactory.java @@ -117,33 +117,4 @@ public final class URLConnectionFactory { } return conn; } - - /** - * Utility method to create an HttpURLConnection. This version of createHttpURLConnection does not utilize any proxy - * configuration; but does provide the ability to authenticate to the site. - * - * @param url the URL to connect to - * @param username the user name for authentication to the given site - * @param password the password for authentication to the given site - * @return a newly constructed HttpURLConnection - * @throws URLConnectionFailureException thrown if there is an exception - */ - public static HttpURLConnection createHttpURLConnection(URL url, final String username, final char[] password) - throws URLConnectionFailureException { - HttpURLConnection conn = null; - try { - Authenticator.setDefault(new Authenticator() { - protected PasswordAuthentication getPasswordAuthentication() { - return new PasswordAuthentication(username, password); - } - }); - conn = (HttpURLConnection) url.openConnection(); - final int timeout = Settings.getInt(Settings.KEYS.CONNECTION_TIMEOUT, 60000); - conn.setConnectTimeout(timeout); - conn.setInstanceFollowRedirects(true); - } catch (IOException ioe) { - throw new URLConnectionFailureException("Error getting connection.", ioe); - } - return conn; - } }