diff --git a/ci/images/releasescripts/src/main/java/io/spring/concourse/releasescripts/artifactory/ArtifactoryService.java b/ci/images/releasescripts/src/main/java/io/spring/concourse/releasescripts/artifactory/ArtifactoryService.java index d8d0071723..370f345f79 100644 --- a/ci/images/releasescripts/src/main/java/io/spring/concourse/releasescripts/artifactory/ArtifactoryService.java +++ b/ci/images/releasescripts/src/main/java/io/spring/concourse/releasescripts/artifactory/ArtifactoryService.java @@ -30,6 +30,7 @@ import org.springframework.http.MediaType; import org.springframework.http.RequestEntity; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Component; +import org.springframework.util.StringUtils; import org.springframework.web.client.HttpClientErrorException; import org.springframework.web.client.RestTemplate; @@ -53,19 +54,18 @@ public class ArtifactoryService { private final RestTemplate restTemplate; - private final ArtifactoryProperties artifactoryProperties; - private final BintrayService bintrayService; private static final ConsoleLogger console = new ConsoleLogger(); public ArtifactoryService(RestTemplateBuilder builder, ArtifactoryProperties artifactoryProperties, BintrayService bintrayService) { - this.artifactoryProperties = artifactoryProperties; this.bintrayService = bintrayService; String username = artifactoryProperties.getUsername(); String password = artifactoryProperties.getPassword(); - builder = builder.basicAuthentication(username, password); + if (StringUtils.hasLength(username)) { + builder = builder.basicAuthentication(username, password); + } this.restTemplate = builder.build(); } diff --git a/ci/images/releasescripts/src/main/java/io/spring/concourse/releasescripts/bintray/BintrayService.java b/ci/images/releasescripts/src/main/java/io/spring/concourse/releasescripts/bintray/BintrayService.java index c5b38b74bb..2cc1fe779e 100644 --- a/ci/images/releasescripts/src/main/java/io/spring/concourse/releasescripts/bintray/BintrayService.java +++ b/ci/images/releasescripts/src/main/java/io/spring/concourse/releasescripts/bintray/BintrayService.java @@ -31,6 +31,7 @@ import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.RequestEntity; import org.springframework.stereotype.Component; +import org.springframework.util.StringUtils; import org.springframework.web.client.HttpClientErrorException; import org.springframework.web.client.RestTemplate; @@ -65,7 +66,9 @@ public class BintrayService { this.sonatypeService = sonatypeService; String username = bintrayProperties.getUsername(); String apiKey = bintrayProperties.getApiKey(); - builder = builder.basicAuthentication(username, apiKey); + if (StringUtils.hasLength(username)) { + builder = builder.basicAuthentication(username, apiKey); + } this.restTemplate = builder.build(); } diff --git a/ci/images/releasescripts/src/main/java/io/spring/concourse/releasescripts/sonatype/SonatypeService.java b/ci/images/releasescripts/src/main/java/io/spring/concourse/releasescripts/sonatype/SonatypeService.java index 61a4f3e26d..ce2ff317d2 100644 --- a/ci/images/releasescripts/src/main/java/io/spring/concourse/releasescripts/sonatype/SonatypeService.java +++ b/ci/images/releasescripts/src/main/java/io/spring/concourse/releasescripts/sonatype/SonatypeService.java @@ -23,6 +23,7 @@ import org.springframework.boot.web.client.RestTemplateBuilder; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Component; +import org.springframework.util.StringUtils; import org.springframework.web.client.HttpClientErrorException; import org.springframework.web.client.RestTemplate; @@ -38,15 +39,14 @@ public class SonatypeService { private final RestTemplate restTemplate; - private final SonatypeProperties sonatypeProperties; - private static final ConsoleLogger console = new ConsoleLogger(); public SonatypeService(RestTemplateBuilder builder, SonatypeProperties sonatypeProperties) { - this.sonatypeProperties = sonatypeProperties; String username = sonatypeProperties.getUserToken(); - String apiKey = sonatypeProperties.getPasswordToken(); - builder = builder.basicAuthentication(username, apiKey); + String password = sonatypeProperties.getPasswordToken(); + if (StringUtils.hasLength(username)) { + builder = builder.basicAuthentication(username, password); + } this.restTemplate = builder.build(); }