Skip to content

Commit e6a885b

Browse files
authored
Mark all BitbucketAuthenticator implementations as non API classes (#935)
1 parent 7ac886d commit e6a885b

19 files changed

+115
-86
lines changed

src/main/java/com/cloudbees/jenkins/plugins/bitbucket/BitbucketSCMSource.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@
3636
import com.cloudbees.jenkins.plugins.bitbucket.api.BitbucketRepository;
3737
import com.cloudbees.jenkins.plugins.bitbucket.api.BitbucketRequestException;
3838
import com.cloudbees.jenkins.plugins.bitbucket.api.BitbucketTeam;
39-
import com.cloudbees.jenkins.plugins.bitbucket.api.credentials.BitbucketUsernamePasswordAuthenticator;
4039
import com.cloudbees.jenkins.plugins.bitbucket.client.BitbucketCloudApiClient;
4140
import com.cloudbees.jenkins.plugins.bitbucket.client.repository.UserRoleInRepository;
41+
import com.cloudbees.jenkins.plugins.bitbucket.credentials.BitbucketUsernamePasswordAuthenticator;
4242
import com.cloudbees.jenkins.plugins.bitbucket.endpoints.AbstractBitbucketEndpoint;
4343
import com.cloudbees.jenkins.plugins.bitbucket.endpoints.BitbucketCloudEndpoint;
4444
import com.cloudbees.jenkins.plugins.bitbucket.endpoints.BitbucketEndpointConfiguration;

src/main/java/com/cloudbees/jenkins/plugins/bitbucket/api/BitbucketApiFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.cloudbees.jenkins.plugins.bitbucket.api;
22

3-
import com.cloudbees.jenkins.plugins.bitbucket.api.credentials.BitbucketUsernamePasswordAuthenticator;
3+
import com.cloudbees.jenkins.plugins.bitbucket.credentials.BitbucketUsernamePasswordAuthenticator;
44
import com.cloudbees.plugins.credentials.common.StandardUsernamePasswordCredentials;
55
import edu.umd.cs.findbugs.annotations.CheckForNull;
66
import edu.umd.cs.findbugs.annotations.NonNull;

src/main/java/com/cloudbees/jenkins/plugins/bitbucket/api/BitbucketAuthenticator.java

Lines changed: 19 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
package com.cloudbees.jenkins.plugins.bitbucket.api;
2626

2727
import com.cloudbees.jenkins.plugins.bitbucket.endpoints.BitbucketCloudEndpoint;
28-
import com.cloudbees.plugins.credentials.common.StandardCredentials;
2928
import com.cloudbees.plugins.credentials.common.StandardUsernameCredentials;
29+
import hudson.plugins.git.GitSCM;
3030
import jenkins.authentication.tokens.api.AuthenticationTokenContext;
3131
import org.apache.http.HttpHost;
3232
import org.apache.http.HttpRequest;
@@ -36,66 +36,51 @@
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

src/main/java/com/cloudbees/jenkins/plugins/bitbucket/client/BitbucketCloudApiClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
import com.cloudbees.jenkins.plugins.bitbucket.api.BitbucketRequestException;
3737
import com.cloudbees.jenkins.plugins.bitbucket.api.BitbucketTeam;
3838
import com.cloudbees.jenkins.plugins.bitbucket.api.BitbucketWebHook;
39-
import com.cloudbees.jenkins.plugins.bitbucket.api.credentials.BitbucketUsernamePasswordAuthenticator;
4039
import com.cloudbees.jenkins.plugins.bitbucket.avatars.AvatarCacheSource.AvatarImage;
4140
import com.cloudbees.jenkins.plugins.bitbucket.client.branch.BitbucketCloudBranch;
4241
import com.cloudbees.jenkins.plugins.bitbucket.client.branch.BitbucketCloudCommit;
@@ -49,6 +48,7 @@
4948
import com.cloudbees.jenkins.plugins.bitbucket.client.repository.BitbucketRepositorySource;
5049
import com.cloudbees.jenkins.plugins.bitbucket.client.repository.PaginatedBitbucketRepository;
5150
import com.cloudbees.jenkins.plugins.bitbucket.client.repository.UserRoleInRepository;
51+
import com.cloudbees.jenkins.plugins.bitbucket.credentials.BitbucketUsernamePasswordAuthenticator;
5252
import com.cloudbees.jenkins.plugins.bitbucket.filesystem.BitbucketSCMFile;
5353
import com.cloudbees.jenkins.plugins.bitbucket.internal.api.AbstractBitbucketApi;
5454
import com.cloudbees.plugins.credentials.common.StandardUsernamePasswordCredentials;
Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.cloudbees.jenkins.plugins.bitbucket.api.credentials;
1+
package com.cloudbees.jenkins.plugins.bitbucket.credentials;
22

33
import com.cloudbees.jenkins.plugins.bitbucket.api.BitbucketAuthenticator;
44
import com.cloudbees.plugins.credentials.CredentialsScope;
@@ -14,8 +14,9 @@
1414
/**
1515
* Authenticator that uses an access token.
1616
*/
17-
public class BitbucketAccessTokenAuthenticator extends BitbucketAuthenticator {
17+
public class BitbucketAccessTokenAuthenticator implements BitbucketAuthenticator {
1818

19+
private final String credentialsId;
1920
private final Secret token;
2021

2122
/**
@@ -24,7 +25,7 @@ public class BitbucketAccessTokenAuthenticator extends BitbucketAuthenticator {
2425
* @param credentials the access token that will be used
2526
*/
2627
public BitbucketAccessTokenAuthenticator(StringCredentials credentials) {
27-
super(credentials);
28+
this.credentialsId = credentials.getId();
2829
token = credentials.getSecret();
2930
}
3031

@@ -46,4 +47,9 @@ public StandardUsernameCredentials getCredentialsForSCM() {
4647
throw new RuntimeException(e);
4748
}
4849
}
50+
51+
@Override
52+
public String getId() {
53+
return credentialsId;
54+
}
4955
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.cloudbees.jenkins.plugins.bitbucket.api.credentials;
1+
package com.cloudbees.jenkins.plugins.bitbucket.credentials;
22

33
import com.cloudbees.jenkins.plugins.bitbucket.api.BitbucketAuthenticator;
44
import edu.umd.cs.findbugs.annotations.NonNull;
Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
* THE SOFTWARE.
2323
*/
2424

25-
package com.cloudbees.jenkins.plugins.bitbucket.api.credentials;
25+
package com.cloudbees.jenkins.plugins.bitbucket.credentials;
2626

2727
import com.cloudbees.jenkins.plugins.bitbucket.api.BitbucketAuthenticator;
2828
import com.cloudbees.plugins.credentials.common.StandardCertificateCredentials;
@@ -42,8 +42,9 @@
4242
/**
4343
* Authenticates against Bitbucket using a TLS client certificate
4444
*/
45-
public class BitbucketClientCertificateAuthenticator extends BitbucketAuthenticator {
45+
public class BitbucketClientCertificateAuthenticator implements BitbucketAuthenticator {
4646

47+
private final String credentialsId;
4748
private final KeyStore keyStore;
4849
private final Secret password;
4950

@@ -53,7 +54,7 @@ public class BitbucketClientCertificateAuthenticator extends BitbucketAuthentica
5354
* {@inheritDoc}
5455
*/
5556
public BitbucketClientCertificateAuthenticator(StandardCertificateCredentials credentials) {
56-
super(credentials);
57+
this.credentialsId = credentials.getId();
5758
keyStore = credentials.getKeyStore();
5859
password = credentials.getPassword();
5960
}
@@ -77,4 +78,9 @@ private SSLContext buildSSLContext() throws NoSuchAlgorithmException, KeyStoreEx
7778
contextBuilder.loadKeyMaterial(keyStore, password.getPlainText().toCharArray());
7879
return contextBuilder.build();
7980
}
81+
82+
@Override
83+
public String getId() {
84+
return credentialsId;
85+
}
8086
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
* THE SOFTWARE.
2323
*/
2424

25-
package com.cloudbees.jenkins.plugins.bitbucket.api.credentials;
25+
package com.cloudbees.jenkins.plugins.bitbucket.credentials;
2626

2727
import com.cloudbees.jenkins.plugins.bitbucket.api.BitbucketAuthenticator;
2828
import com.cloudbees.plugins.credentials.common.StandardCertificateCredentials;

src/main/java/com/cloudbees/jenkins/plugins/bitbucket/api/credentials/BitbucketOAuth.java renamed to src/main/java/com/cloudbees/jenkins/plugins/bitbucket/credentials/BitbucketOAuth.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.cloudbees.jenkins.plugins.bitbucket.api.credentials;
1+
package com.cloudbees.jenkins.plugins.bitbucket.credentials;
22

33
import com.github.scribejava.core.builder.api.DefaultApi20;
44

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.cloudbees.jenkins.plugins.bitbucket.api.credentials;
1+
package com.cloudbees.jenkins.plugins.bitbucket.credentials;
22

33
import com.cloudbees.jenkins.plugins.bitbucket.api.BitbucketAuthenticator;
44
import com.cloudbees.plugins.credentials.CredentialsScope;
@@ -17,8 +17,9 @@
1717
import jenkins.util.SetContextClassLoader;
1818
import org.apache.http.HttpRequest;
1919

20-
public class BitbucketOAuthAuthenticator extends BitbucketAuthenticator {
20+
public class BitbucketOAuthAuthenticator implements BitbucketAuthenticator {
2121

22+
private final String credentialsId;
2223
private OAuth2AccessToken token;
2324

2425
/**
@@ -28,7 +29,7 @@ public class BitbucketOAuthAuthenticator extends BitbucketAuthenticator {
2829
* @throws AuthenticationTokenException
2930
*/
3031
public BitbucketOAuthAuthenticator(StandardUsernamePasswordCredentials credentials) throws AuthenticationTokenException {
31-
super(credentials);
32+
this.credentialsId = credentials.getId();
3233

3334
try (SetContextClassLoader cl = new SetContextClassLoader(this.getClass());
3435
OAuth20Service service = new ServiceBuilder(credentials.getUsername())
@@ -58,4 +59,9 @@ public StandardUsernameCredentials getCredentialsForSCM() {
5859
throw new RuntimeException(e);
5960
}
6061
}
62+
63+
@Override
64+
public String getId() {
65+
return credentialsId;
66+
}
6167
}

0 commit comments

Comments
 (0)