Skip to content

Commit c8c12e2

Browse files
authored
OAuth authenticator leaks Apache HTTP client I/O Dispatcher threads (#919)
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.
1 parent e729230 commit c8c12e2

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@
147147
</dependency>
148148
<dependency>
149149
<groupId>com.github.scribejava</groupId>
150-
<artifactId>scribejava-httpclient-apache</artifactId>
150+
<artifactId>scribejava-core</artifactId>
151151
<version>8.3.3</version>
152152
</dependency>
153153
</dependencies>

src/main/java/com/cloudbees/jenkins/plugins/bitbucket/api/credentials/BitbucketOAuthAuthenticator.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
import com.cloudbees.plugins.credentials.common.StandardUsernamePasswordCredentials;
77
import com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl;
88
import com.github.scribejava.core.builder.ServiceBuilder;
9+
import com.github.scribejava.core.httpclient.jdk.JDKHttpClientConfig;
910
import com.github.scribejava.core.model.OAuth2AccessToken;
1011
import com.github.scribejava.core.model.OAuthConstants;
1112
import com.github.scribejava.core.oauth.OAuth20Service;
12-
import com.github.scribejava.httpclient.apache.ApacheHttpClientConfig;
1313
import hudson.model.Descriptor.FormException;
1414
import java.io.IOException;
1515
import java.util.concurrent.ExecutionException;
@@ -31,11 +31,11 @@ public class BitbucketOAuthAuthenticator extends BitbucketAuthenticator {
3131
public BitbucketOAuthAuthenticator(StandardUsernamePasswordCredentials credentials) throws AuthenticationTokenException {
3232
super(credentials);
3333

34-
try (SetContextClassLoader cl = new SetContextClassLoader(this.getClass())) {
35-
OAuth20Service service = new ServiceBuilder(credentials.getUsername())
36-
.apiSecret(credentials.getPassword().getPlainText())
37-
.httpClientConfig(ApacheHttpClientConfig.defaultConfig())
38-
.build(BitbucketOAuth.instance());
34+
try (SetContextClassLoader cl = new SetContextClassLoader(this.getClass());
35+
OAuth20Service service = new ServiceBuilder(credentials.getUsername())
36+
.apiSecret(credentials.getPassword().getPlainText())
37+
.httpClientConfig(JDKHttpClientConfig.defaultConfig())
38+
.build(BitbucketOAuth.instance())) {
3939
token = service.getAccessTokenClientCredentialsGrant();
4040
} catch (IOException | InterruptedException | ExecutionException e) {
4141
throw new AuthenticationTokenException(e);

0 commit comments

Comments
 (0)