Skip to content

Commit 7ec1f98

Browse files
committed
fix: AccessControlled can be ItemGroup and Item
1 parent 873d221 commit 7ec1f98

File tree

1 file changed

+22
-11
lines changed

1 file changed

+22
-11
lines changed

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

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import hudson.model.AbstractDescribableImpl;
1313
import hudson.model.Descriptor;
1414
import hudson.model.Item;
15+
import hudson.model.ItemGroup;
1516
import hudson.security.ACL;
1617
import hudson.security.AccessControlled;
1718
import hudson.util.FormValidation;
@@ -228,22 +229,32 @@ public String getCredentialsId() {
228229
*/
229230
public PersonalAccessToken getCredentials(AccessControlled context) {
230231
Jenkins jenkins = Jenkins.get();
231-
AccessControlled item;
232232
if (context == null) {
233233
jenkins.checkPermission(CredentialsProvider.USE_OWN);
234-
item = jenkins;
234+
return StringUtils.isBlank(credentialsId) ? null : CredentialsMatchers.firstOrNull( lookupCredentials(
235+
PersonalAccessToken.class,
236+
jenkins,
237+
ACL.SYSTEM,
238+
fromUri(defaultIfBlank(serverUrl, GITLAB_SERVER_URL)).build()
239+
), withId(credentialsId));
235240
} else {
236241
context.checkPermission(CredentialsProvider.USE_OWN);
237-
item = context;
242+
if (context instanceof ItemGroup) {
243+
return StringUtils.isBlank(credentialsId) ? null : CredentialsMatchers.firstOrNull( lookupCredentials(
244+
PersonalAccessToken.class,
245+
(ItemGroup) context,
246+
ACL.SYSTEM,
247+
fromUri(defaultIfBlank(serverUrl, GITLAB_SERVER_URL)).build()
248+
), withId(credentialsId));
249+
} else {
250+
return StringUtils.isBlank(credentialsId) ? null : CredentialsMatchers.firstOrNull( lookupCredentials(
251+
PersonalAccessToken.class,
252+
(Item) context,
253+
ACL.SYSTEM,
254+
fromUri(defaultIfBlank(serverUrl, GITLAB_SERVER_URL)).build()
255+
), withId(credentialsId));
256+
}
238257
}
239-
return StringUtils.isBlank(credentialsId) ? null : CredentialsMatchers.firstOrNull(
240-
lookupCredentials(
241-
PersonalAccessToken.class,
242-
(Item) item,
243-
ACL.SYSTEM,
244-
fromUri(defaultIfBlank(serverUrl, GITLAB_SERVER_URL)).build()
245-
), withId(credentialsId));
246-
247258
}
248259

249260
/**

0 commit comments

Comments
 (0)