6
6
import com .cloudbees .plugins .credentials .common .StandardUsernamePasswordCredentials ;
7
7
import com .cloudbees .plugins .credentials .impl .UsernamePasswordCredentialsImpl ;
8
8
import com .github .scribejava .core .builder .ServiceBuilder ;
9
- import com .github .scribejava .core .httpclient .HttpClient ;
10
9
import com .github .scribejava .core .model .OAuth2AccessToken ;
11
10
import com .github .scribejava .core .model .OAuthConstants ;
12
11
import com .github .scribejava .core .oauth .OAuth20Service ;
13
12
import com .github .scribejava .httpclient .apache .ApacheHttpClientConfig ;
14
- import com .github .scribejava .httpclient .apache .ApacheProvider ;
15
13
import hudson .model .Descriptor .FormException ;
16
14
import java .io .IOException ;
17
15
import java .util .concurrent .ExecutionException ;
18
16
import jenkins .authentication .tokens .api .AuthenticationTokenException ;
17
+ import jenkins .util .SetContextClassLoader ;
19
18
import org .apache .commons .lang .StringUtils ;
20
19
import org .apache .http .HttpRequest ;
21
20
@@ -32,14 +31,11 @@ public class BitbucketOAuthAuthenticator extends BitbucketAuthenticator {
32
31
public BitbucketOAuthAuthenticator (StandardUsernamePasswordCredentials credentials ) throws AuthenticationTokenException {
33
32
super (credentials );
34
33
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 ());
43
39
token = service .getAccessTokenClientCredentialsGrant ();
44
40
} catch (IOException | InterruptedException | ExecutionException e ) {
45
41
throw new AuthenticationTokenException (e );
0 commit comments