|
11 | 11 | import hudson.Util; |
12 | 12 | import hudson.model.AbstractDescribableImpl; |
13 | 13 | import hudson.model.Descriptor; |
14 | | -import hudson.model.Item; |
15 | | -import hudson.model.ItemGroup; |
16 | 14 | import hudson.security.ACL; |
17 | 15 | import hudson.security.AccessControlled; |
18 | 16 | import hudson.util.FormValidation; |
@@ -243,30 +241,15 @@ public PersonalAccessToken getCredentials(AccessControlled context) { |
243 | 241 | Jenkins jenkins = Jenkins.get(); |
244 | 242 | if (context == null) { |
245 | 243 | jenkins.checkPermission(CredentialsProvider.USE_OWN); |
246 | | - return StringUtils.isBlank(credentialsId) ? null : CredentialsMatchers.firstOrNull( lookupCredentials( |
| 244 | + } else { |
| 245 | + context.checkPermission(CredentialsProvider.USE_OWN); |
| 246 | + } |
| 247 | + return StringUtils.isBlank(credentialsId) ? null : CredentialsMatchers.firstOrNull( lookupCredentials( |
247 | 248 | PersonalAccessToken.class, |
248 | 249 | jenkins, |
249 | 250 | ACL.SYSTEM, |
250 | 251 | fromUri(defaultIfBlank(serverUrl, GITLAB_SERVER_URL)).build() |
251 | 252 | ), withId(credentialsId)); |
252 | | - } else { |
253 | | - context.checkPermission(CredentialsProvider.USE_OWN); |
254 | | - if (context instanceof ItemGroup) { |
255 | | - return StringUtils.isBlank(credentialsId) ? null : CredentialsMatchers.firstOrNull( lookupCredentials( |
256 | | - PersonalAccessToken.class, |
257 | | - (ItemGroup) context, |
258 | | - ACL.SYSTEM, |
259 | | - fromUri(defaultIfBlank(serverUrl, GITLAB_SERVER_URL)).build() |
260 | | - ), withId(credentialsId)); |
261 | | - } else { |
262 | | - return StringUtils.isBlank(credentialsId) ? null : CredentialsMatchers.firstOrNull( lookupCredentials( |
263 | | - PersonalAccessToken.class, |
264 | | - (Item) context, |
265 | | - ACL.SYSTEM, |
266 | | - fromUri(defaultIfBlank(serverUrl, GITLAB_SERVER_URL)).build() |
267 | | - ), withId(credentialsId)); |
268 | | - } |
269 | | - } |
270 | 253 | } |
271 | 254 |
|
272 | 255 | /** |
|
0 commit comments