From 5f0ad1f3e69320ec75a771570987fcac052715aa Mon Sep 17 00:00:00 2001 From: Nikolas Falco Date: Thu, 21 Nov 2024 17:30:35 +0100 Subject: [PATCH] Change the configured http client provider in scribejava from Apache HTTP Client to JDK HTTP Client, as in the previous implementation with the scribe library. There is no gain in using a client with a pooled connection manager that is destroyed every time a new token is requested. This commit fix the ClassNotFoundException issue of org.apache.logging.log4j.spi.LoggerAdapter (commons-logging is marked as a scope dependency in the pom-plugin) when scm is used in a scripted pipeline. --- pom.xml | 2 +- .../api/credentials/BitbucketOAuthAuthenticator.java | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/pom.xml b/pom.xml index 6c2e7e1b6..5573f2921 100644 --- a/pom.xml +++ b/pom.xml @@ -146,7 +146,7 @@ com.github.scribejava - scribejava-httpclient-apache + scribejava-core 8.3.3 diff --git a/src/main/java/com/cloudbees/jenkins/plugins/bitbucket/api/credentials/BitbucketOAuthAuthenticator.java b/src/main/java/com/cloudbees/jenkins/plugins/bitbucket/api/credentials/BitbucketOAuthAuthenticator.java index a49e7fe88..81a669144 100644 --- a/src/main/java/com/cloudbees/jenkins/plugins/bitbucket/api/credentials/BitbucketOAuthAuthenticator.java +++ b/src/main/java/com/cloudbees/jenkins/plugins/bitbucket/api/credentials/BitbucketOAuthAuthenticator.java @@ -6,10 +6,10 @@ import com.cloudbees.plugins.credentials.common.StandardUsernamePasswordCredentials; import com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl; import com.github.scribejava.core.builder.ServiceBuilder; +import com.github.scribejava.core.httpclient.jdk.JDKHttpClientConfig; import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.oauth.OAuth20Service; -import com.github.scribejava.httpclient.apache.ApacheHttpClientConfig; import hudson.model.Descriptor.FormException; import java.io.IOException; import java.util.concurrent.ExecutionException; @@ -31,11 +31,11 @@ public class BitbucketOAuthAuthenticator extends BitbucketAuthenticator { public BitbucketOAuthAuthenticator(StandardUsernamePasswordCredentials credentials) throws AuthenticationTokenException { super(credentials); - try (SetContextClassLoader cl = new SetContextClassLoader(this.getClass())) { - OAuth20Service service = new ServiceBuilder(credentials.getUsername()) - .apiSecret(credentials.getPassword().getPlainText()) - .httpClientConfig(ApacheHttpClientConfig.defaultConfig()) - .build(BitbucketOAuth.instance()); + try (SetContextClassLoader cl = new SetContextClassLoader(this.getClass()); + OAuth20Service service = new ServiceBuilder(credentials.getUsername()) + .apiSecret(credentials.getPassword().getPlainText()) + .httpClientConfig(JDKHttpClientConfig.defaultConfig()) + .build(BitbucketOAuth.instance())) { token = service.getAccessTokenClientCredentialsGrant(); } catch (IOException | InterruptedException | ExecutionException e) { throw new AuthenticationTokenException(e);