25
25
package com .cloudbees .jenkins .plugins .bitbucket .api ;
26
26
27
27
import com .cloudbees .jenkins .plugins .bitbucket .endpoints .BitbucketCloudEndpoint ;
28
- import com .cloudbees .plugins .credentials .common .StandardCredentials ;
29
28
import com .cloudbees .plugins .credentials .common .StandardUsernameCredentials ;
29
+ import hudson .plugins .git .GitSCM ;
30
30
import jenkins .authentication .tokens .api .AuthenticationTokenContext ;
31
31
import org .apache .http .HttpHost ;
32
32
import org .apache .http .HttpRequest ;
36
36
/**
37
37
* Support for various different methods of authenticating with Bitbucket
38
38
*/
39
- public abstract class BitbucketAuthenticator {
40
-
41
- private final String id ;
39
+ public interface BitbucketAuthenticator {
42
40
43
41
/**
44
42
* The key for bitbucket URL as reported in an {@link AuthenticationTokenContext}
45
43
*/
46
- public static final String SERVER_URL = "bitbucket.server.uri" ;
44
+ static final String SERVER_URL = "bitbucket.server.uri" ;
47
45
48
46
/**
49
47
* The key for URL scheme as reported in an {@link AuthenticationTokenContext}
50
48
*/
51
- public static final String SCHEME = "bitbucket.server.uri.scheme" ;
49
+ static final String SCHEME = "bitbucket.server.uri.scheme" ;
52
50
53
51
/**
54
52
* The key for Bitbucket instance type as reported in an {@link AuthenticationTokenContext}
55
53
*/
56
- public static final String BITBUCKET_INSTANCE_TYPE = "bitbucket.server.type" ;
54
+ static final String BITBUCKET_INSTANCE_TYPE = "bitbucket.server.type" ;
57
55
58
56
/**
59
57
* Purpose value for bitbucket cloud (i.e. bitbucket.org)
60
58
*/
61
- public static final String BITBUCKET_INSTANCE_TYPE_CLOUD = "BITBUCKET_CLOUD" ;
59
+ static final String BITBUCKET_INSTANCE_TYPE_CLOUD = "BITBUCKET_CLOUD" ;
62
60
63
61
/**
64
62
* Purpose value for bitbucket server
65
63
*/
66
- public static final String BITBUCKET_INSTANCE_TYPE_SERVER = "BITBUCKET_SERVER" ;
67
-
68
- /**
69
- * Constructor
70
- *
71
- * @param credentials credentials instance this authenticator will use
72
- */
73
- protected BitbucketAuthenticator (StandardCredentials credentials ) {
74
- id = credentials .getId ();
75
- }
64
+ static final String BITBUCKET_INSTANCE_TYPE_SERVER = "BITBUCKET_SERVER" ;
76
65
77
66
/**
78
67
* @return id of the credentials used.
79
68
*/
80
- public String getId () {
81
- return id ;
82
- }
69
+ String getId ();
83
70
84
71
/**
85
72
* Configures an {@link HttpClientBuilder}. Override if you need to adjust connection setup.
86
73
* @param builder The client builder.
87
74
*/
88
- public void configureBuilder (HttpClientBuilder builder ) {
89
- // override to configure HttpClientBuilder
75
+ default void configureBuilder (HttpClientBuilder builder ) {
90
76
}
91
77
92
78
/**
93
79
* Configures an {@link HttpClientContext}. Override
94
80
* @param context The connection context
95
81
* @param host host being connected to
96
82
*/
97
- public void configureContext (HttpClientContext context , HttpHost host ) {
98
- // override to configure HttpClientContext
83
+ default void configureContext (HttpClientContext context , HttpHost host ) {
99
84
}
100
85
101
86
/**
@@ -104,17 +89,20 @@ public void configureContext(HttpClientContext context, HttpHost host) {
104
89
*
105
90
* @param request the request.
106
91
*/
107
- public void configureRequest (HttpRequest request ) {
108
- // override to configure HttpRequest
92
+ default void configureRequest (HttpRequest request ) {
109
93
}
110
94
111
-
112
95
/**
113
- * Provides credentials that can be used for authenticated interactions with SCM.
96
+ * Provides credentials that can be used for authenticated interactions with
97
+ * SCM.
114
98
*
115
- * @return credentials to be passed to {@link org.jenkinsci.plugins.gitclient.GitClient#setCredentials(StandardUsernameCredentials)}
99
+ * @return credentials to be passed to
100
+ * {@link org.jenkinsci.plugins.gitclient.GitClient#setCredentials(StandardUsernameCredentials)}.
101
+ * If {@code null} force {@link GitSCM} to obtain credentials in the
102
+ * standard way, from the credential provider, using the credential
103
+ * identifier provided by {@link #getId()}.
116
104
*/
117
- public StandardUsernameCredentials getCredentialsForSCM () {
105
+ default StandardUsernameCredentials getCredentialsForSCM () {
118
106
return null ;
119
107
}
120
108
0 commit comments