Skip to content

Commit 05b9d2a

Browse files
committed
CQI Prevent NPE in authenticators if password is null
1 parent 7119e94 commit 05b9d2a

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

src/main/java/com/cloudbees/jenkins/plugins/bitbucket/credentials/BitbucketAccessTokenAuthenticator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public BitbucketAccessTokenAuthenticator(StringCredentials credentials) {
5858
* @param request to configure with the access token
5959
*/
6060
public void configureRequest(HttpRequest request) {
61-
request.setHeader(HttpHeaders.AUTHORIZATION, "Bearer " + token.getPlainText());
61+
request.setHeader(HttpHeaders.AUTHORIZATION, "Bearer " + Secret.toString(token));
6262
}
6363

6464
/**
@@ -73,7 +73,7 @@ public void configureRequest(HttpRequest request) {
7373
@Override
7474
public StandardUsernameCredentials getCredentialsForSCM() {
7575
try {
76-
return new UsernamePasswordCredentialsImpl(CredentialsScope.GLOBAL, getId(), null, "x-token-auth", token.getPlainText());
76+
return new UsernamePasswordCredentialsImpl(CredentialsScope.GLOBAL, getId(), null, "x-token-auth", Secret.toString(token));
7777
} catch (FormException e) {
7878
throw new RuntimeException(e);
7979
}

src/main/java/com/cloudbees/jenkins/plugins/bitbucket/credentials/BitbucketClientCertificateAuthenticator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public void configureBuilder(HttpClientBuilder builder) {
7272

7373
private SSLContext buildSSLContext() throws NoSuchAlgorithmException, KeyStoreException, UnrecoverableKeyException, KeyManagementException {
7474
SSLContextBuilder contextBuilder = SSLContexts.custom();
75-
contextBuilder.loadKeyMaterial(keyStore, password.getPlainText().toCharArray());
75+
contextBuilder.loadKeyMaterial(keyStore, Secret.toString(password).toCharArray());
7676
return contextBuilder.build();
7777
}
7878

src/main/java/com/cloudbees/jenkins/plugins/bitbucket/credentials/BitbucketUsernamePasswordAuthenticator.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
import com.cloudbees.jenkins.plugins.bitbucket.api.BitbucketAuthenticator;
2929
import com.cloudbees.plugins.credentials.common.StandardUsernamePasswordCredentials;
30+
import hudson.util.Secret;
3031
import java.util.logging.Level;
3132
import java.util.logging.Logger;
3233
import org.apache.http.HttpHost;
@@ -55,8 +56,8 @@ public class BitbucketUsernamePasswordAuthenticator implements BitbucketAuthenti
5556
*/
5657
public BitbucketUsernamePasswordAuthenticator(StandardUsernamePasswordCredentials credentials) {
5758
credentialsId = credentials.getId();
58-
httpCredentials = new UsernamePasswordCredentials(credentials.getUsername(),
59-
credentials.getPassword().getPlainText());
59+
String password = Secret.toString(credentials.getPassword());
60+
httpCredentials = new UsernamePasswordCredentials(credentials.getUsername(), password);
6061
}
6162

6263
/**

0 commit comments

Comments
 (0)