Skip to content

Commit

Permalink
Replace deprecated usage of CredentialsProvider#lookupCredentials
Browse files Browse the repository at this point in the history
`CredentialsProvider#lookupCredentials` was deprecated in favor of `CredentialsProvider.lookupCredentialsInItem` which uses `org.springframework.security.core.Authentication` instead of `org.acegisecurity.Authentication`.
  • Loading branch information
Thomas Salzinger authored and tsalzinger committed Mar 29, 2024
1 parent 5a94b19 commit 095e979
Showing 1 changed file with 12 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import edu.umd.cs.findbugs.annotations.NonNull;
import hudson.model.Item;
import hudson.model.Queue;
import hudson.model.queue.Tasks;
import hudson.security.ACL;
import hudson.security.AccessControlled;
import hudson.util.FormValidation;
Expand All @@ -46,6 +45,7 @@
import org.apache.commons.lang.StringUtils;
import org.kohsuke.stapler.AncestorInPath;
import org.kohsuke.stapler.QueryParameter;
import org.springframework.security.core.Authentication;

/**
* Utility class for common code accessing credentials
Expand All @@ -66,12 +66,10 @@ static <T extends StandardCredentials> T lookupCredentialsAndTrackUsage(@CheckFo
@NonNull Class<T> type) {
if (StringUtils.isNotBlank(id) && context != null) {
final T credentials = CredentialsMatchers.firstOrNull(
CredentialsProvider.lookupCredentials(
CredentialsProvider.lookupCredentialsInItem(
type,
context,
context instanceof Queue.Task
? Tasks.getDefaultAuthenticationOf((Queue.Task) context)
: ACL.SYSTEM,
getAuthenticationForContext(context),
URIRequirementBuilder.fromUri(serverUrl).build()
),
CredentialsMatchers.allOf(
Expand All @@ -97,9 +95,7 @@ static ListBoxModel fillCredentialsIdItems(
return result;
}
result.includeMatchingAs(
context instanceof Queue.Task
? Tasks.getDefaultAuthenticationOf((Queue.Task) context)
: ACL.SYSTEM,
getAuthenticationForContext(context),
context,
StandardCredentials.class,
URIRequirementBuilder.fromUri(serverUrl).build(),
Expand All @@ -116,10 +112,10 @@ static FormValidation checkCredentialsId(
AccessControlled contextToCheck = context == null ? Jenkins.get() : context;
contextToCheck.checkPermission(CredentialsProvider.VIEW);
if (CredentialsMatchers.firstOrNull(
CredentialsProvider.lookupCredentials(
CredentialsProvider.lookupCredentialsInItem(
StandardCertificateCredentials.class,
context,
context instanceof Queue.Task ? Tasks.getDefaultAuthenticationOf((Queue.Task) context) : ACL.SYSTEM,
getAuthenticationForContext(context),

Check warning on line 118 in src/main/java/com/cloudbees/jenkins/plugins/bitbucket/BitbucketCredentials.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 98-118 are not covered by tests
URIRequirementBuilder.fromUri(serverUrl).build()),
CredentialsMatchers.allOf(
CredentialsMatchers.withId(value),
Expand All @@ -133,4 +129,10 @@ static FormValidation checkCredentialsId(
return FormValidation.warning("Credentials are required for build notifications");
}
}

private static Authentication getAuthenticationForContext(SCMSourceOwner context) {
return context instanceof Queue.Task

Check warning on line 134 in src/main/java/com/cloudbees/jenkins/plugins/bitbucket/BitbucketCredentials.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 134 is only partially covered, one branch is missing
? ((Queue.Task) context).getDefaultAuthentication2()
: ACL.SYSTEM2;

Check warning on line 136 in src/main/java/com/cloudbees/jenkins/plugins/bitbucket/BitbucketCredentials.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 136 is not covered by tests
}
}

0 comments on commit 095e979

Please sign in to comment.