2525package com .cloudbees .jenkins .plugins .bitbucket .api ;
2626
2727import com .cloudbees .jenkins .plugins .bitbucket .endpoints .BitbucketCloudEndpoint ;
28- import com .cloudbees .plugins .credentials .common .StandardCredentials ;
2928import com .cloudbees .plugins .credentials .common .StandardUsernameCredentials ;
29+ import hudson .plugins .git .GitSCM ;
3030import jenkins .authentication .tokens .api .AuthenticationTokenContext ;
3131import org .apache .http .HttpHost ;
3232import org .apache .http .HttpRequest ;
3636/**
3737 * Support for various different methods of authenticating with Bitbucket
3838 */
39- public abstract class BitbucketAuthenticator {
40-
41- private final String id ;
39+ public interface BitbucketAuthenticator {
4240
4341 /**
4442 * The key for bitbucket URL as reported in an {@link AuthenticationTokenContext}
4543 */
46- public static final String SERVER_URL = "bitbucket.server.uri" ;
44+ static final String SERVER_URL = "bitbucket.server.uri" ;
4745
4846 /**
4947 * The key for URL scheme as reported in an {@link AuthenticationTokenContext}
5048 */
51- public static final String SCHEME = "bitbucket.server.uri.scheme" ;
49+ static final String SCHEME = "bitbucket.server.uri.scheme" ;
5250
5351 /**
5452 * The key for Bitbucket instance type as reported in an {@link AuthenticationTokenContext}
5553 */
56- public static final String BITBUCKET_INSTANCE_TYPE = "bitbucket.server.type" ;
54+ static final String BITBUCKET_INSTANCE_TYPE = "bitbucket.server.type" ;
5755
5856 /**
5957 * Purpose value for bitbucket cloud (i.e. bitbucket.org)
6058 */
61- public static final String BITBUCKET_INSTANCE_TYPE_CLOUD = "BITBUCKET_CLOUD" ;
59+ static final String BITBUCKET_INSTANCE_TYPE_CLOUD = "BITBUCKET_CLOUD" ;
6260
6361 /**
6462 * Purpose value for bitbucket server
6563 */
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" ;
7665
7766 /**
7867 * @return id of the credentials used.
7968 */
80- public String getId () {
81- return id ;
82- }
69+ String getId ();
8370
8471 /**
8572 * Configures an {@link HttpClientBuilder}. Override if you need to adjust connection setup.
8673 * @param builder The client builder.
8774 */
88- public void configureBuilder (HttpClientBuilder builder ) {
89- // override to configure HttpClientBuilder
75+ default void configureBuilder (HttpClientBuilder builder ) {
9076 }
9177
9278 /**
9379 * Configures an {@link HttpClientContext}. Override
9480 * @param context The connection context
9581 * @param host host being connected to
9682 */
97- public void configureContext (HttpClientContext context , HttpHost host ) {
98- // override to configure HttpClientContext
83+ default void configureContext (HttpClientContext context , HttpHost host ) {
9984 }
10085
10186 /**
@@ -104,17 +89,20 @@ public void configureContext(HttpClientContext context, HttpHost host) {
10489 *
10590 * @param request the request.
10691 */
107- public void configureRequest (HttpRequest request ) {
108- // override to configure HttpRequest
92+ default void configureRequest (HttpRequest request ) {
10993 }
11094
111-
11295 /**
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.
11498 *
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()}.
116104 */
117- public StandardUsernameCredentials getCredentialsForSCM () {
105+ default StandardUsernameCredentials getCredentialsForSCM () {
118106 return null ;
119107 }
120108
0 commit comments