44import com .cloudbees .plugins .credentials .CredentialsMatcher ;
55import com .cloudbees .plugins .credentials .common .UsernamePasswordCredentials ;
66import hudson .util .Secret ;
7+ import java .util .logging .Level ;
8+ import java .util .logging .Logger ;
79
810public class BitbucketOAuthCredentialMatcher implements CredentialsMatcher , CredentialsMatcher .CQL {
9- private static int keyLenght = 18 ;
10- private static int secretLenght = 32 ;
11+ private static int keyLength = 18 ;
12+ private static int secretLength = 32 ;
1113
1214 private static final long serialVersionUID = 6458784517693211197L ;
15+ private static final Logger LOGGER = Logger .getLogger (BitbucketOAuthCredentialMatcher .class .getName ());
1316
1417 /**
1518 * {@inheritDoc}
@@ -19,13 +22,18 @@ public boolean matches(Credentials item) {
1922 if (!(item instanceof UsernamePasswordCredentials ))
2023 return false ;
2124
22- UsernamePasswordCredentials usernamePasswordCredential = ((UsernamePasswordCredentials ) item );
23- String username = usernamePasswordCredential .getUsername ();
24- boolean isEMail = username .contains ("." ) && username .contains ("@" );
25- boolean validSecretLenght = Secret .toString (usernamePasswordCredential .getPassword ()).length () == secretLenght ;
26- boolean validKeyLenght = username .length () == keyLenght ;
25+ try {
26+ UsernamePasswordCredentials usernamePasswordCredential = ((UsernamePasswordCredentials ) item );
27+ String username = usernamePasswordCredential .getUsername ();
28+ boolean isEMail = username .contains ("." ) && username .contains ("@" );
29+ boolean validSecretLength = Secret .toString (usernamePasswordCredential .getPassword ()).length () == secretLength ;
30+ boolean validKeyLength = username .length () == keyLength ;
2731
28- return !isEMail && validKeyLenght && validSecretLenght ;
32+ return !isEMail && validKeyLength && validSecretLength ;
33+ } catch (RuntimeException e ) {
34+ LOGGER .log (Level .FINE , "Caught exception validating credential" , e );
35+ return false ;
36+ }
2937 }
3038
3139 /**
@@ -35,7 +43,7 @@ public boolean matches(Credentials item) {
3543 public String describe () {
3644 return String .format (
3745 "(username.lenght == %d && password.lenght == %d && !(username CONTAINS \" .\" && username CONTAINS \" @\" )" ,
38- keyLenght , secretLenght );
46+ keyLength , secretLength );
3947 }
4048
4149
0 commit comments