66import com .cloudbees .plugins .credentials .common .StandardUsernamePasswordCredentials ;
77import com .cloudbees .plugins .credentials .impl .UsernamePasswordCredentialsImpl ;
88import com .github .scribejava .core .builder .ServiceBuilder ;
9- import com .github .scribejava .core .httpclient .HttpClient ;
109import com .github .scribejava .core .model .OAuth2AccessToken ;
1110import com .github .scribejava .core .model .OAuthConstants ;
1211import com .github .scribejava .core .oauth .OAuth20Service ;
1312import com .github .scribejava .httpclient .apache .ApacheHttpClientConfig ;
14- import com .github .scribejava .httpclient .apache .ApacheProvider ;
1513import hudson .model .Descriptor .FormException ;
1614import java .io .IOException ;
1715import java .util .concurrent .ExecutionException ;
1816import jenkins .authentication .tokens .api .AuthenticationTokenException ;
17+ import jenkins .util .SetContextClassLoader ;
1918import org .apache .commons .lang .StringUtils ;
2019import org .apache .http .HttpRequest ;
2120
@@ -32,14 +31,11 @@ public class BitbucketOAuthAuthenticator extends BitbucketAuthenticator {
3231 public BitbucketOAuthAuthenticator (StandardUsernamePasswordCredentials credentials ) throws AuthenticationTokenException {
3332 super (credentials );
3433
35- HttpClient httpClient = new ApacheProvider ().createClient (ApacheHttpClientConfig .defaultConfig ());
36- OAuth20Service service = new ServiceBuilder (credentials .getUsername ())
37- .apiSecret (credentials .getPassword ().getPlainText ())
38- .httpClient (httpClient )
39- // .httpClientConfig(ApacheHttpClientConfig.defaultConfig()) the ServiceLoader does not work well with Jenkins plugin classloader
40- .build (BitbucketOAuth .instance ());
41-
42- try {
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 ());
4339 token = service .getAccessTokenClientCredentialsGrant ();
4440 } catch (IOException | InterruptedException | ExecutionException e ) {
4541 throw new AuthenticationTokenException (e );
0 commit comments