Skip to content

Commit 3be41dc

Browse files
committed
CQI Remove unused import. Define lengths as constants in OAuth2 credential matcher.
1 parent 326a147 commit 3be41dc

File tree

2 files changed

+18
-17
lines changed

2 files changed

+18
-17
lines changed

src/main/java/com/cloudbees/jenkins/plugins/bitbucket/hooks/PullRequestHookProcessor.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151
import java.util.logging.Logger;
5252
import jenkins.plugins.git.AbstractGitSCMSource;
5353
import jenkins.scm.api.SCMEvent;
54-
import jenkins.scm.api.SCMEvent.Type;
5554
import jenkins.scm.api.SCMHead;
5655
import jenkins.scm.api.SCMHeadEvent;
5756
import jenkins.scm.api.SCMHeadObserver;

src/main/java/com/cloudbees/jenkins/plugins/bitbucket/impl/credentials/BitbucketOAuthCredentialMatcher.java

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,22 @@
3030
import java.util.logging.Level;
3131
import java.util.logging.Logger;
3232

33-
// Although the CredentialsMatcher documentation says that the best practice
34-
// is to implement CredentialsMatcher.CQL too, this class does not implement
35-
// CredentialsMatcher.CQL, for the following reasons:
36-
//
37-
// * CQL supports neither method calls like username.contains(".")
38-
// nor any regular-expression matching that could be used instead.
39-
// * There don't seem to be any public credential-provider plugins that
40-
// would benefit from CQL.
33+
/*
34+
* Although the CredentialsMatcher documentation says that the best practice
35+
* is to implement CredentialsMatcher.CQL too, this class does not implement
36+
* CredentialsMatcher.CQL, for the following reasons:
37+
*
38+
* - CQL supports neither method calls like username.contains(".")
39+
* nor any regular-expression matching that could be used instead;
40+
* - there don't seem to be any public credential-provider plugins that
41+
* would benefit from CQL.
42+
*/
4143
public class BitbucketOAuthCredentialMatcher implements CredentialsMatcher {
42-
private static int keyLength = 18;
43-
private static int secretLength = 32;
44-
4544
private static final long serialVersionUID = 6458784517693211197L;
46-
private static final Logger LOGGER = Logger.getLogger(BitbucketOAuthCredentialMatcher.class.getName());
45+
private static final Logger logger = Logger.getLogger(BitbucketOAuthCredentialMatcher.class.getName());
46+
47+
private static final int CLIENT_KEY_LENGTH = 18;
48+
private static final int CLIENT_SECRET_LENGTH = 32;
4749

4850
/**
4951
* {@inheritDoc}
@@ -54,20 +56,20 @@ public boolean matches(Credentials item) {
5456
return false;
5557
}
5658

57-
if(item.getClass().getName().equals("com.cloudbees.jenkins.plugins.amazonecr.AmazonECSRegistryCredential")) {
59+
if (item.getClass().getName().equals("com.cloudbees.jenkins.plugins.amazonecr.AmazonECSRegistryCredential")) {
5860
return false;
5961
}
6062

6163
try {
6264
UsernamePasswordCredentials usernamePasswordCredential = ((UsernamePasswordCredentials) item);
6365
String username = usernamePasswordCredential.getUsername();
6466
boolean isEMail = username.contains(".") && username.contains("@");
65-
boolean validSecretLength = usernamePasswordCredential.getPassword().getPlainText().length() == secretLength;
66-
boolean validKeyLength = username.length() == keyLength;
67+
boolean validSecretLength = usernamePasswordCredential.getPassword().getPlainText().length() == CLIENT_SECRET_LENGTH;
68+
boolean validKeyLength = username.length() == CLIENT_KEY_LENGTH;
6769

6870
return !isEMail && validKeyLength && validSecretLength;
6971
} catch (RuntimeException e) {
70-
LOGGER.log(Level.FINE, "Caught exception validating credential", e);
72+
logger.log(Level.FINE, "Caught exception validating credential", e);
7173
return false;
7274
}
7375
}

0 commit comments

Comments
 (0)