From 40112c546d7b7b86e7a0ff10a18fb48728b48501 Mon Sep 17 00:00:00 2001 From: Basil Crow Date: Fri, 20 Dec 2024 16:12:20 -0800 Subject: [PATCH] Migrate from Acegi compatibility layer to Spring Security (#1026) --- src/main/java/hudson/plugins/ec2/EC2Cloud.java | 15 +++++++-------- .../hudson/plugins/ec2/EC2RetentionStrategy.java | 2 +- .../plugins/ec2/EC2RetentionStrategyTest.java | 4 ++-- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/main/java/hudson/plugins/ec2/EC2Cloud.java b/src/main/java/hudson/plugins/ec2/EC2Cloud.java index 28302e62a..b929a6637 100644 --- a/src/main/java/hudson/plugins/ec2/EC2Cloud.java +++ b/src/main/java/hudson/plugins/ec2/EC2Cloud.java @@ -58,7 +58,6 @@ import com.cloudbees.plugins.credentials.common.AbstractIdCredentialsListBoxModel; import com.cloudbees.plugins.credentials.common.StandardListBoxModel; import com.cloudbees.plugins.credentials.domains.Domain; -import com.cloudbees.plugins.credentials.domains.DomainRequirement; import com.google.common.annotations.VisibleForTesting; import edu.umd.cs.findbugs.annotations.CheckForNull; import edu.umd.cs.findbugs.annotations.NonNull; @@ -1127,8 +1126,8 @@ private static AmazonWebServicesCredentials getCredentials(@CheckForNull String return null; } return CredentialsMatchers.firstOrNull( - CredentialsProvider.lookupCredentials( - AmazonWebServicesCredentials.class, Jenkins.get(), ACL.SYSTEM, Collections.emptyList()), + CredentialsProvider.lookupCredentialsInItemGroup( + AmazonWebServicesCredentials.class, Jenkins.get(), ACL.SYSTEM2, Collections.emptyList()), CredentialsMatchers.withId(credentialsId)); } @@ -1281,16 +1280,16 @@ public ListBoxModel doFillSshKeysCredentialsIdItems( if (Jenkins.get().hasPermission(Jenkins.ADMINISTER)) { result = result.includeEmptyValue() .includeMatchingAs( - Jenkins.getAuthentication(), + Jenkins.getAuthentication2(), context, SSHUserPrivateKey.class, - Collections.emptyList(), + Collections.emptyList(), CredentialsMatchers.always()) .includeMatchingAs( - ACL.SYSTEM, + ACL.SYSTEM2, context, SSHUserPrivateKey.class, - Collections.emptyList(), + Collections.emptyList(), CredentialsMatchers.always()) .includeCurrentValue(sshKeysCredentialsId); } @@ -1479,7 +1478,7 @@ public ListBoxModel doFillCredentialsIdItems(@AncestorInPath ItemGroup context) return new StandardListBoxModel() .includeEmptyValue() .includeMatchingAs( - ACL.SYSTEM, + ACL.SYSTEM2, context, AmazonWebServicesCredentials.class, Collections.emptyList(), diff --git a/src/main/java/hudson/plugins/ec2/EC2RetentionStrategy.java b/src/main/java/hudson/plugins/ec2/EC2RetentionStrategy.java index f38b95755..0ec4b4a80 100644 --- a/src/main/java/hudson/plugins/ec2/EC2RetentionStrategy.java +++ b/src/main/java/hudson/plugins/ec2/EC2RetentionStrategy.java @@ -264,7 +264,7 @@ private boolean itemsInQueueForThisSlave(EC2Computer c) { return false; } final Label selfLabel = selfNode.getSelfLabel(); - Queue.Item[] items = Jenkins.getInstance().getQueue().getItems(); + Queue.Item[] items = Jenkins.get().getQueue().getItems(); for (Queue.Item item : items) { final Label assignedLabel = item.getAssignedLabel(); if (assignedLabel == selfLabel) { diff --git a/src/test/java/hudson/plugins/ec2/EC2RetentionStrategyTest.java b/src/test/java/hudson/plugins/ec2/EC2RetentionStrategyTest.java index 0ba04ce41..e885d148e 100644 --- a/src/test/java/hudson/plugins/ec2/EC2RetentionStrategyTest.java +++ b/src/test/java/hudson/plugins/ec2/EC2RetentionStrategyTest.java @@ -44,11 +44,11 @@ import java.util.stream.Collectors; import jenkins.model.Jenkins; import jenkins.util.NonLocalizable; -import org.acegisecurity.Authentication; import org.junit.Rule; import org.junit.Test; import org.jvnet.hudson.test.JenkinsRule; import org.jvnet.hudson.test.LoggerRule; +import org.springframework.security.core.Authentication; public class EC2RetentionStrategyTest { @@ -140,7 +140,7 @@ public String getShortDescription() { public ACL getACL() { return new ACL() { @Override - public boolean hasPermission(@NonNull Authentication a, @NonNull Permission permission) { + public boolean hasPermission2(@NonNull Authentication a, @NonNull Permission permission) { return true; } };