Skip to content

Commit 82bd063

Browse files
authored
feat: Allow configuring OSS Index user/pw directly (#7640)
1 parent 37f296b commit 82bd063

File tree

2 files changed

+33
-5
lines changed

2 files changed

+33
-5
lines changed

maven/src/main/java/org/owasp/dependencycheck/maven/BaseDependencyCheckMojo.java

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -765,13 +765,34 @@ public abstract class BaseDependencyCheckMojo extends AbstractMojo implements Ma
765765
private String ossindexAnalyzerUrl;
766766

767767
/**
768-
* The id of a server defined in the settings.xml that configures the
769-
* credentials (username and password) for a OSS Index service.
768+
* The id of a server defined in the settings.xml to authenticate Sonatype
769+
* OSS Index requests and profit from higher rate limits. Provide the OSS
770+
* account email address as username and password or API token as password.
770771
*/
771772
@SuppressWarnings("CanBeFinal")
772773
@Parameter(property = "ossIndexServerId")
773774
private String ossIndexServerId;
774775

776+
/**
777+
* OSS account email address as an alternative to the indirection through
778+
* the ossIndexServerId (see above). Both ossIndexUsername and
779+
* ossIndexPassword must be set to use this approach instead of the server
780+
* ID.
781+
*/
782+
@SuppressWarnings("CanBeFinal")
783+
@Parameter(property = "ossIndexUsername")
784+
private String ossIndexUsername;
785+
786+
/**
787+
* OSS password or API token as an alternative to the indirection through
788+
* the ossIndexServerId (see above). Both ossIndexUsername and
789+
* ossIndexPassword must be set to use this approach instead of the server
790+
* ID.
791+
*/
792+
@SuppressWarnings("CanBeFinal")
793+
@Parameter(property = "ossIndexPassword")
794+
private String ossIndexPassword;
795+
775796
/**
776797
* Whether we should only warn about Sonatype OSS Index remote errors
777798
* instead of failing the goal completely.
@@ -2427,7 +2448,12 @@ protected void populateSettings() throws MojoFailureException, MojoExecutionExce
24272448
settings.setBooleanIfNotNull(Settings.KEYS.ANALYZER_SWIFT_PACKAGE_RESOLVED_ENABLED, swiftPackageResolvedAnalyzerEnabled);
24282449
settings.setBooleanIfNotNull(Settings.KEYS.ANALYZER_OSSINDEX_ENABLED, ossindexAnalyzerEnabled);
24292450
settings.setStringIfNotEmpty(Settings.KEYS.ANALYZER_OSSINDEX_URL, ossindexAnalyzerUrl);
2430-
configureServerCredentials(ossIndexServerId, Settings.KEYS.ANALYZER_OSSINDEX_USER, Settings.KEYS.ANALYZER_OSSINDEX_PASSWORD);
2451+
if (StringUtils.isEmpty(ossIndexUsername) || StringUtils.isEmpty(ossIndexPassword)) {
2452+
configureServerCredentials(ossIndexServerId, Settings.KEYS.ANALYZER_OSSINDEX_USER, Settings.KEYS.ANALYZER_OSSINDEX_PASSWORD);
2453+
} else {
2454+
settings.setStringIfNotEmpty(Settings.KEYS.ANALYZER_OSSINDEX_USER, ossIndexUsername);
2455+
settings.setStringIfNotEmpty(Settings.KEYS.ANALYZER_OSSINDEX_PASSWORD, ossIndexPassword);
2456+
}
24312457
settings.setBooleanIfNotNull(Settings.KEYS.ANALYZER_OSSINDEX_USE_CACHE, ossindexAnalyzerUseCache);
24322458
settings.setBooleanIfNotNull(Settings.KEYS.ANALYZER_OSSINDEX_WARN_ONLY_ON_REMOTE_ERRORS, ossIndexWarnOnlyOnRemoteErrors);
24332459
if (retirejs != null) {
@@ -2517,8 +2543,8 @@ protected void populateSettings() throws MojoFailureException, MojoExecutionExce
25172543
* <p>
25182544
* When a serverId is given, then its values are used instead of the less secure direct values.<br />
25192545
* A serverId with username/password will fill the `userKey` and `passwordKey` settings for Basic Auth. A serverId with only password
2520-
* filled will fill the `tokenKey` fro Bearer Auth.<br/>
2521-
* In absence of the serverId any non-null value will be transferred to the settings.
2546+
* filled will fill the `tokenKey` from Bearer Auth.<br/>
2547+
* In absence of the serverId, any non-null value will be transferred to the settings.
25222548
*
25232549
* @param serverId The serverId specified for the connection or {@code null}
25242550
* @param usernameValue The username specified for the connection or {@code null}

maven/src/site/markdown/configuration.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ knownExploitedUrl | Sets URL to the CISA Known Exploited Vulne
6464
ossindexAnalyzerEnabled | Sets whether the [OSS Index Analyzer](../analyzers/oss-index-analyzer.html) will be enabled. This analyzer requires an internet connection. | true
6565
ossindexAnalyzerUseCache | Sets whether the OSS Index Analyzer will cache results. Cached results expire after 24 hours. | true
6666
ossIndexServerId | The id of [a server](https://maven.apache.org/settings.html#Servers) defined in the `settings.xml` to authenticate Sonatype OSS Index requests and profit from higher rate limits. Provide the OSS account email address as `username` and password or API token as `password`. | &nbsp;
67+
ossIndexUsername | OSS account email address as an alternative to the indirection through the `ossIndexServerId` (see above). Both `ossIndexUsername` and `ossIndexPassword` must be set to use this approach instead of the server ID. | &nbsp;
68+
ossIndexPassword | OSS password or API token as an alternative to the indirection through the `ossIndexServerId` (see above). Both `ossIndexUsername` and `ossIndexPassword` must be set to use this approach instead of the server ID. | &nbsp;
6769
ossindexAnalyzerUrl | The OSS Index server URL | https://ossindex.sonatype.org
6870
ossIndexWarnOnlyOnRemoteErrors | Sets whether remote errors from the OSS Index (e.g. BAD GATEWAY, RATE LIMIT EXCEEDED) will result in warnings only instead of failing execution. | false
6971
nexusAnalyzerEnabled | Sets whether Nexus Analyzer will be used (requires Nexus Pro). This analyzer is superceded by the Central Analyzer; however, you can configure this to run against a Nexus Pro installation. | true

0 commit comments

Comments
 (0)