diff --git a/src/main/java/io/jenkins/plugins/gitlabserverconfig/servers/GitLabServer.java b/src/main/java/io/jenkins/plugins/gitlabserverconfig/servers/GitLabServer.java index 55bcb1ff..70b98852 100644 --- a/src/main/java/io/jenkins/plugins/gitlabserverconfig/servers/GitLabServer.java +++ b/src/main/java/io/jenkins/plugins/gitlabserverconfig/servers/GitLabServer.java @@ -11,8 +11,6 @@ import hudson.Util; import hudson.model.AbstractDescribableImpl; import hudson.model.Descriptor; -import hudson.model.Item; -import hudson.model.ItemGroup; import hudson.security.ACL; import hudson.security.AccessControlled; import hudson.util.FormValidation; @@ -243,30 +241,15 @@ public PersonalAccessToken getCredentials(AccessControlled context) { Jenkins jenkins = Jenkins.get(); if (context == null) { jenkins.checkPermission(CredentialsProvider.USE_OWN); - return StringUtils.isBlank(credentialsId) ? null : CredentialsMatchers.firstOrNull( lookupCredentials( + } else { + context.checkPermission(CredentialsProvider.USE_OWN); + } + return StringUtils.isBlank(credentialsId) ? null : CredentialsMatchers.firstOrNull( lookupCredentials( PersonalAccessToken.class, jenkins, ACL.SYSTEM, fromUri(defaultIfBlank(serverUrl, GITLAB_SERVER_URL)).build() ), withId(credentialsId)); - } else { - context.checkPermission(CredentialsProvider.USE_OWN); - if (context instanceof ItemGroup) { - return StringUtils.isBlank(credentialsId) ? null : CredentialsMatchers.firstOrNull( lookupCredentials( - PersonalAccessToken.class, - (ItemGroup) context, - ACL.SYSTEM, - fromUri(defaultIfBlank(serverUrl, GITLAB_SERVER_URL)).build() - ), withId(credentialsId)); - } else { - return StringUtils.isBlank(credentialsId) ? null : CredentialsMatchers.firstOrNull( lookupCredentials( - PersonalAccessToken.class, - (Item) context, - ACL.SYSTEM, - fromUri(defaultIfBlank(serverUrl, GITLAB_SERVER_URL)).build() - ), withId(credentialsId)); - } - } } /**