Skip to content

Commit 7101b1c

Browse files
authored
Correction of issue using gitlab credential with system scope (#234)
1 parent 1bf2633 commit 7101b1c

File tree

1 file changed

+4
-21
lines changed

1 file changed

+4
-21
lines changed

src/main/java/io/jenkins/plugins/gitlabserverconfig/servers/GitLabServer.java

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
import hudson.Util;
1212
import hudson.model.AbstractDescribableImpl;
1313
import hudson.model.Descriptor;
14-
import hudson.model.Item;
15-
import hudson.model.ItemGroup;
1614
import hudson.security.ACL;
1715
import hudson.security.AccessControlled;
1816
import hudson.util.FormValidation;
@@ -243,30 +241,15 @@ public PersonalAccessToken getCredentials(AccessControlled context) {
243241
Jenkins jenkins = Jenkins.get();
244242
if (context == null) {
245243
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(
247248
PersonalAccessToken.class,
248249
jenkins,
249250
ACL.SYSTEM,
250251
fromUri(defaultIfBlank(serverUrl, GITLAB_SERVER_URL)).build()
251252
), 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-
}
270253
}
271254

272255
/**

0 commit comments

Comments
 (0)