From 9d609b6085f6d7e3c88b9e7ef141adfb6921847a Mon Sep 17 00:00:00 2001 From: Jeremy Long Date: Sun, 2 Mar 2014 18:16:12 -0500 Subject: [PATCH] added configuration for whether or not the nexus analyzer should use the configured proxy Former-commit-id: 99f3110346941ebc00c14ae1c00220eef76c1e9f --- .../taskdefs/DependencyCheckTask.java | 23 +++++++++++++++++++ .../src/site/markdown/configuration.md | 1 + .../java/org/owasp/dependencycheck/App.java | 3 ++- .../owasp/dependencycheck/cli/CliParser.java | 23 +++++++++++++++++++ .../src/site/markdown/arguments.md | 1 + .../maven/DependencyCheckMojo.java | 7 ++++++ .../src/site/markdown/configuration.md | 1 + 7 files changed, 58 insertions(+), 1 deletion(-) diff --git a/dependency-check-ant/src/main/java/org/owasp/dependencycheck/taskdefs/DependencyCheckTask.java b/dependency-check-ant/src/main/java/org/owasp/dependencycheck/taskdefs/DependencyCheckTask.java index e71af47ce..8c982fbfd 100644 --- a/dependency-check-ant/src/main/java/org/owasp/dependencycheck/taskdefs/DependencyCheckTask.java +++ b/dependency-check-ant/src/main/java/org/owasp/dependencycheck/taskdefs/DependencyCheckTask.java @@ -502,6 +502,28 @@ public class DependencyCheckTask extends Task { public void setNexusUrl(String nexusUrl) { this.nexusUrl = nexusUrl; } + /** + * Whether or not the defined proxy should be used when connecting to Nexus. + */ + private boolean nexusUsesProxy = true; + + /** + * Get the value of nexusUsesProxy + * + * @return the value of nexusUsesProxy + */ + public boolean isNexusUsesProxy() { + return nexusUsesProxy; + } + + /** + * Set the value of nexusUsesProxy + * + * @param nexusUsesProxy new value of nexusUsesProxy + */ + public void setNexusUsesProxy(boolean nexusUsesProxy) { + this.nexusUsesProxy = nexusUsesProxy; + } /** * The database driver name; such as org.h2.Driver. @@ -867,6 +889,7 @@ public class DependencyCheckTask extends Task { if (nexusUrl != null && !nexusUrl.isEmpty()) { Settings.setString(Settings.KEYS.ANALYZER_NEXUS_URL, nexusUrl); } + Settings.setBoolean(Settings.KEYS.ANALYZER_NEXUS_PROXY, nexusUsesProxy); if (databaseDriverName != null && !databaseDriverName.isEmpty()) { Settings.setString(Settings.KEYS.DB_DRIVER_NAME, databaseDriverName); } diff --git a/dependency-check-ant/src/site/markdown/configuration.md b/dependency-check-ant/src/site/markdown/configuration.md index 3545b885b..48465e4b0 100644 --- a/dependency-check-ant/src/site/markdown/configuration.md +++ b/dependency-check-ant/src/site/markdown/configuration.md @@ -37,6 +37,7 @@ ProxyPassword | Defines the proxy password. | Optional | ConnectionTimeout | The connection timeout used when downloading data files from the Internet. | Optional | nexusAnalyzerEnabled | The connection timeout used when downloading data files from the Internet. | Optional | nexusUrl | The connection timeout used when downloading data files from the Internet. | Optional | +nexusUsesProxy | Whether or not the defined proxy should be used when connecting to Nexus. | Optional | true databaseDriverName | The name of the database driver. Example: org.h2.Driver. | Optional | databaseDriverPath | The path to the database driver JAR file; only used if the driver is not in the class path. | Optional | connectionString | The connection string used to connect to the database. | Optional | diff --git a/dependency-check-cli/src/main/java/org/owasp/dependencycheck/App.java b/dependency-check-cli/src/main/java/org/owasp/dependencycheck/App.java index f5447d524..9f7d04576 100644 --- a/dependency-check-cli/src/main/java/org/owasp/dependencycheck/App.java +++ b/dependency-check-cli/src/main/java/org/owasp/dependencycheck/App.java @@ -160,6 +160,7 @@ public class App { final String suppressionFile = cli.getSuppressionFile(); final boolean nexusDisabled = cli.isNexusDisabled(); final String nexusUrl = cli.getNexusUrl(); + final boolean nexusUsesProxy = cli.isNexusUsesProxy(); final String databaseDriverName = cli.getDatabaseDriverName(); final String databaseDriverPath = cli.getDatabaseDriverPath(); final String connectionString = cli.getConnectionString(); @@ -215,7 +216,7 @@ public class App { if (nexusUrl != null && !nexusUrl.isEmpty()) { Settings.setString(Settings.KEYS.ANALYZER_NEXUS_URL, nexusUrl); } - + Settings.setBoolean(Settings.KEYS.ANALYZER_NEXUS_PROXY, nexusUsesProxy); if (databaseDriverName != null && !databaseDriverName.isEmpty()) { Settings.setString(Settings.KEYS.DB_DRIVER_NAME, databaseDriverName); } diff --git a/dependency-check-cli/src/main/java/org/owasp/dependencycheck/cli/CliParser.java b/dependency-check-cli/src/main/java/org/owasp/dependencycheck/cli/CliParser.java index fa01d0c97..b5e06673c 100644 --- a/dependency-check-cli/src/main/java/org/owasp/dependencycheck/cli/CliParser.java +++ b/dependency-check-cli/src/main/java/org/owasp/dependencycheck/cli/CliParser.java @@ -204,6 +204,10 @@ public final class CliParser { .withDescription("The url to the Nexus Server.") .create(); + final Option nexusUsesProxy = OptionBuilder.withArgName("true/false").hasArg().withLongOpt(ArgumentName.NEXUS_URL) + .withDescription("Whether or not the configured proxy should be used when connecting to Nexus.") + .create(); + final Option additionalZipExtensions = OptionBuilder.withArgName("extensions").hasArg() .withLongOpt(ArgumentName.ADDITIONAL_ZIP_EXTENSIONS) .withDescription("A comma seperated list of additional extensions to be scanned as ZIP files " @@ -227,6 +231,7 @@ public final class CliParser { .addOption(suppressionFile) .addOption(disableNexusAnalyzer) .addOption(nexusUrl) + .addOption(nexusUsesProxy) .addOption(additionalZipExtensions); } @@ -342,6 +347,20 @@ public final class CliParser { } } + /** + * Returns true if the Nexus Analyzer should use the configured proxy to connect to Nexus; otherwise false is + * returned. + * + * @return true if the Nexus Analyzer should use the configured proxy to connect to Nexus; otherwise false + */ + public boolean isNexusUsesProxy() { + if (line == null || !line.hasOption(ArgumentName.NEXUS_USES_PROXY)) { + return true; + } else { + return Boolean.parseBoolean(line.getOptionValue(ArgumentName.NEXUS_USES_PROXY)); + } + } + /** * Displays the command line help message to the standard output. */ @@ -697,6 +716,10 @@ public final class CliParser { * The URL of the nexus server. */ public static final String NEXUS_URL = "nexus"; + /** + * Whether or not the defined proxy should be used when connecting to Nexus. + */ + public static final String NEXUS_USES_PROXY = "nexusUsesProxy"; /** * The CLI argument name for setting the connection string. */ diff --git a/dependency-check-cli/src/site/markdown/arguments.md b/dependency-check-cli/src/site/markdown/arguments.md index 756999048..e16bab883 100644 --- a/dependency-check-cli/src/site/markdown/arguments.md +++ b/dependency-check-cli/src/site/markdown/arguments.md @@ -28,4 +28,5 @@ Short | Argument Name | Parameter | Description | Requirement | \-\-dbUser | \ | The username used to connect to the database. | Optional | \-\-disableNexus | | Disable the Nexus Analyzer. | Optional | \-\-nexus | \ | The url to the Nexus Server. | Optional + | \-\-nexusUsesProxy | \ | Whether or not the defined proxy should be used when connecting to Nexus. | Optional | \-\-zipExtensions | \ | A comma-separated list of additional file extensions to be treated like a ZIP file, the contents will be extracted and analyzed. | Optional \ No newline at end of file diff --git a/dependency-check-maven/src/main/java/org/owasp/dependencycheck/maven/DependencyCheckMojo.java b/dependency-check-maven/src/main/java/org/owasp/dependencycheck/maven/DependencyCheckMojo.java index 3068c39aa..cec783ceb 100644 --- a/dependency-check-maven/src/main/java/org/owasp/dependencycheck/maven/DependencyCheckMojo.java +++ b/dependency-check-maven/src/main/java/org/owasp/dependencycheck/maven/DependencyCheckMojo.java @@ -198,6 +198,12 @@ public class DependencyCheckMojo extends AbstractMojo implements MavenMultiPageR @SuppressWarnings({"CanBeFinal", "FieldCanBeLocal"}) @Parameter(property = "nexusUrl", defaultValue = "", required = false) private String nexusUrl; + /** + * Whether or not the configured proxy is used to connect to Nexus. + */ + @SuppressWarnings({"CanBeFinal", "FieldCanBeLocal"}) + @Parameter(property = "nexusUsesProxy", defaultValue = "true", required = false) + private boolean nexusUsesProxy = true; /** * The database connection string. */ @@ -751,6 +757,7 @@ public class DependencyCheckMojo extends AbstractMojo implements MavenMultiPageR if (nexusUrl != null && !nexusUrl.isEmpty()) { Settings.setString(Settings.KEYS.ANALYZER_NEXUS_URL, nexusUrl); } + Settings.setBoolean(Settings.KEYS.ANALYZER_NEXUS_PROXY, nexusUsesProxy); if (databaseDriverName != null && !databaseDriverName.isEmpty()) { Settings.setString(Settings.KEYS.DB_DRIVER_NAME, databaseDriverName); } diff --git a/dependency-check-maven/src/site/markdown/configuration.md b/dependency-check-maven/src/site/markdown/configuration.md index da8a4f3c1..af3efb2f2 100644 --- a/dependency-check-maven/src/site/markdown/configuration.md +++ b/dependency-check-maven/src/site/markdown/configuration.md @@ -17,6 +17,7 @@ proxyUsername | Defines the proxy user name. | proxyPassword | Defines the proxy password. | nexusAnalyzerEnabled | Sets whether Nexus Analyzer will be used. | nexusUrl | Defines the Nexus URL. | +nexusUsesProxy | Whether or not the defined proxy should be used when connecting to Nexus. | true databaseDriverName | The name of the database driver. Example: org.h2.Driver. | databaseDriverPath | The path to the database driver JAR file; only used if the driver is not in the class path. | connectionString | The connection string used to connect to the database. |