35
35
import edu .umd .cs .findbugs .annotations .NonNull ;
36
36
import hudson .model .Item ;
37
37
import hudson .model .Queue ;
38
- import hudson .model .queue .Tasks ;
39
38
import hudson .security .ACL ;
40
39
import hudson .security .AccessControlled ;
41
40
import hudson .util .FormValidation ;
46
45
import org .apache .commons .lang .StringUtils ;
47
46
import org .kohsuke .stapler .AncestorInPath ;
48
47
import org .kohsuke .stapler .QueryParameter ;
48
+ import org .springframework .security .core .Authentication ;
49
49
50
50
/**
51
51
* Utility class for common code accessing credentials
@@ -66,12 +66,10 @@ static <T extends StandardCredentials> T lookupCredentialsAndTrackUsage(@CheckFo
66
66
@ NonNull Class <T > type ) {
67
67
if (StringUtils .isNotBlank (id ) && context != null ) {
68
68
final T credentials = CredentialsMatchers .firstOrNull (
69
- CredentialsProvider .lookupCredentials (
69
+ CredentialsProvider .lookupCredentialsInItem (
70
70
type ,
71
71
context ,
72
- context instanceof Queue .Task
73
- ? Tasks .getDefaultAuthenticationOf ((Queue .Task ) context )
74
- : ACL .SYSTEM ,
72
+ getAuthenticationForContext (context ),
75
73
URIRequirementBuilder .fromUri (serverUrl ).build ()
76
74
),
77
75
CredentialsMatchers .allOf (
@@ -97,9 +95,7 @@ static ListBoxModel fillCredentialsIdItems(
97
95
return result ;
98
96
}
99
97
result .includeMatchingAs (
100
- context instanceof Queue .Task
101
- ? Tasks .getDefaultAuthenticationOf ((Queue .Task ) context )
102
- : ACL .SYSTEM ,
98
+ getAuthenticationForContext (context ),
103
99
context ,
104
100
StandardCredentials .class ,
105
101
URIRequirementBuilder .fromUri (serverUrl ).build (),
@@ -116,10 +112,10 @@ static FormValidation checkCredentialsId(
116
112
AccessControlled contextToCheck = context == null ? Jenkins .get () : context ;
117
113
contextToCheck .checkPermission (CredentialsProvider .VIEW );
118
114
if (CredentialsMatchers .firstOrNull (
119
- CredentialsProvider .lookupCredentials (
115
+ CredentialsProvider .lookupCredentialsInItem (
120
116
StandardCertificateCredentials .class ,
121
117
context ,
122
- context instanceof Queue . Task ? Tasks . getDefaultAuthenticationOf (( Queue . Task ) context ) : ACL . SYSTEM ,
118
+ getAuthenticationForContext ( context ),
123
119
URIRequirementBuilder .fromUri (serverUrl ).build ()),
124
120
CredentialsMatchers .allOf (
125
121
CredentialsMatchers .withId (value ),
@@ -133,4 +129,10 @@ static FormValidation checkCredentialsId(
133
129
return FormValidation .warning ("Credentials are required for build notifications" );
134
130
}
135
131
}
132
+
133
+ private static Authentication getAuthenticationForContext (SCMSourceOwner context ) {
134
+ return context instanceof Queue .Task
135
+ ? ((Queue .Task ) context ).getDefaultAuthentication2 ()
136
+ : ACL .SYSTEM2 ;
137
+ }
136
138
}
0 commit comments