4
4
import com .cloudbees .plugins .credentials .CredentialsMatcher ;
5
5
import com .cloudbees .plugins .credentials .common .UsernamePasswordCredentials ;
6
6
import hudson .util .Secret ;
7
+ import java .util .logging .Level ;
8
+ import java .util .logging .Logger ;
7
9
8
10
public 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 ;
11
13
12
14
private static final long serialVersionUID = 6458784517693211197L ;
15
+ private static final Logger LOGGER = Logger .getLogger (BitbucketOAuthCredentialMatcher .class .getName ());
13
16
14
17
/**
15
18
* {@inheritDoc}
@@ -19,13 +22,18 @@ public boolean matches(Credentials item) {
19
22
if (!(item instanceof UsernamePasswordCredentials ))
20
23
return false ;
21
24
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 ;
27
31
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
+ }
29
37
}
30
38
31
39
/**
@@ -35,7 +43,7 @@ public boolean matches(Credentials item) {
35
43
public String describe () {
36
44
return String .format (
37
45
"(username.lenght == %d && password.lenght == %d && !(username CONTAINS \" .\" && username CONTAINS \" @\" )" ,
38
- keyLenght , secretLenght );
46
+ keyLength , secretLength );
39
47
}
40
48
41
49
0 commit comments