From e89ed1d24b66e1f2d38a42705a3a401480523d98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Frimberger?= Date: Thu, 19 Dec 2024 17:54:55 +0100 Subject: [PATCH] feat: support for authType=bearerToken for NPM proxy repository (GH-540) --- ...oryApiRequestToConfigurationConverter.java | 1 + .../rest/api/SimpleApiRepositoryAdapter.java | 3 ++- ...entConnectionAuthenticationAttributes.java | 21 ++++++++++++++++++- ...uthenticationAttributesWithPreemptive.java | 7 ++++--- 4 files changed, 27 insertions(+), 5 deletions(-) diff --git a/components/nexus-repository-services/src/main/java/org/sonatype/nexus/repository/rest/api/ProxyRepositoryApiRequestToConfigurationConverter.java b/components/nexus-repository-services/src/main/java/org/sonatype/nexus/repository/rest/api/ProxyRepositoryApiRequestToConfigurationConverter.java index 41d019d18f..71acd4d2a6 100644 --- a/components/nexus-repository-services/src/main/java/org/sonatype/nexus/repository/rest/api/ProxyRepositoryApiRequestToConfigurationConverter.java +++ b/components/nexus-repository-services/src/main/java/org/sonatype/nexus/repository/rest/api/ProxyRepositoryApiRequestToConfigurationConverter.java @@ -90,6 +90,7 @@ private void convertAuthentication( authenticationConfiguration.set("password", authentication.getPassword()); authenticationConfiguration.set("ntlmHost", authentication.getNtlmHost()); authenticationConfiguration.set("ntlmDomain", authentication.getNtlmDomain()); + authenticationConfiguration.set("bearerToken", authentication.getBearerToken()); } } diff --git a/components/nexus-repository-services/src/main/java/org/sonatype/nexus/repository/rest/api/SimpleApiRepositoryAdapter.java b/components/nexus-repository-services/src/main/java/org/sonatype/nexus/repository/rest/api/SimpleApiRepositoryAdapter.java index 6962ceb9df..0b0b5114d0 100644 --- a/components/nexus-repository-services/src/main/java/org/sonatype/nexus/repository/rest/api/SimpleApiRepositoryAdapter.java +++ b/components/nexus-repository-services/src/main/java/org/sonatype/nexus/repository/rest/api/SimpleApiRepositoryAdapter.java @@ -206,8 +206,9 @@ protected HttpClientAttributes getHttpClientAttributes(final Repository reposito String username = authenticationMap.get("username", String.class); String ntlmHost = authenticationMap.get("ntlmHost", String.class); String ntlmDomain = authenticationMap.get("ntlmDomain", String.class); + String bearerToken = authenticationMap.get("bearerToken", String.class); - authentication = new HttpClientConnectionAuthenticationAttributes(type, username, null, ntlmHost, ntlmDomain); + authentication = new HttpClientConnectionAuthenticationAttributes(type, username, null, ntlmHost, ntlmDomain, bearerToken); } HttpClientConnectionAttributes connection = null; diff --git a/components/nexus-repository-services/src/main/java/org/sonatype/nexus/repository/rest/api/model/HttpClientConnectionAuthenticationAttributes.java b/components/nexus-repository-services/src/main/java/org/sonatype/nexus/repository/rest/api/model/HttpClientConnectionAuthenticationAttributes.java index 14b56e3a59..1fc0993662 100644 --- a/components/nexus-repository-services/src/main/java/org/sonatype/nexus/repository/rest/api/model/HttpClientConnectionAuthenticationAttributes.java +++ b/components/nexus-repository-services/src/main/java/org/sonatype/nexus/repository/rest/api/model/HttpClientConnectionAuthenticationAttributes.java @@ -35,25 +35,40 @@ public class HttpClientConnectionAuthenticationAttributes @ApiModelProperty(access = "writeOnly") protected final String password; + @ApiModelProperty(access = "writeOnly") + protected final String bearerToken; + @ApiModelProperty protected final String ntlmHost; @ApiModelProperty protected final String ntlmDomain; + public HttpClientConnectionAuthenticationAttributes( + @JsonProperty("type") final String type, + @JsonProperty("username") final String username, + @JsonProperty(value = "password", access = Access.WRITE_ONLY) final String password, + @JsonProperty("ntlmHost") final String ntlmHost, + @JsonProperty("ntlmDomain") final String ntlmDomain) + { + this(type, username, password, ntlmHost, ntlmDomain, null); + } + @JsonCreator public HttpClientConnectionAuthenticationAttributes( @JsonProperty("type") final String type, @JsonProperty("username") final String username, @JsonProperty(value = "password", access = Access.WRITE_ONLY) final String password, @JsonProperty("ntlmHost") final String ntlmHost, - @JsonProperty("ntlmDomain") final String ntlmDomain) + @JsonProperty("ntlmDomain") final String ntlmDomain, + @JsonProperty(value = "bearerToken", access = Access.WRITE_ONLY) final String bearerToken) { this.type = type; this.username = username; this.password = password; this.ntlmHost = ntlmHost; this.ntlmDomain = ntlmDomain; + this.bearerToken = bearerToken; } public String getType() { @@ -75,4 +90,8 @@ public String getNtlmHost() { public String getNtlmDomain() { return ntlmDomain; } + + public String getBearerToken() { + return bearerToken; + } } diff --git a/plugins/nexus-repository-maven/src/main/java/org/sonatype/nexus/repository/maven/rest/HttpClientConnectionAuthenticationAttributesWithPreemptive.java b/plugins/nexus-repository-maven/src/main/java/org/sonatype/nexus/repository/maven/rest/HttpClientConnectionAuthenticationAttributesWithPreemptive.java index 1783d14856..4e0b6592ef 100644 --- a/plugins/nexus-repository-maven/src/main/java/org/sonatype/nexus/repository/maven/rest/HttpClientConnectionAuthenticationAttributesWithPreemptive.java +++ b/plugins/nexus-repository-maven/src/main/java/org/sonatype/nexus/repository/maven/rest/HttpClientConnectionAuthenticationAttributesWithPreemptive.java @@ -39,9 +39,10 @@ public HttpClientConnectionAuthenticationAttributesWithPreemptive( @JsonProperty("username") final String username, @JsonProperty(value = "password", access = Access.WRITE_ONLY) final String password, @JsonProperty("ntlmHost") final String ntlmHost, - @JsonProperty("ntlmDomain") final String ntlmDomain) + @JsonProperty("ntlmDomain") final String ntlmDomain, + @JsonProperty(value = "bearerToken", access = Access.WRITE_ONLY) final String bearerToken) { - super(type, username, password, ntlmHost, ntlmDomain); + super(type, username, password, ntlmHost, ntlmDomain, bearerToken); this.preemptive = preemptive; } @@ -49,7 +50,7 @@ public HttpClientConnectionAuthenticationAttributesWithPreemptive( final HttpClientConnectionAuthenticationAttributes auth, final Boolean preemptive) { - super(auth.getType(), auth.getUsername(), auth.getPassword(), auth.getNtlmHost(), auth.getNtlmDomain()); + super(auth.getType(), auth.getUsername(), auth.getPassword(), auth.getNtlmHost(), auth.getNtlmDomain(), auth.getBearerToken()); this.preemptive = preemptive; }