Skip to content

Migrate from Acegi to Spring Security #158

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -395,11 +395,11 @@ public ListBoxModel doFillCredentialsIdItems(@AncestorInPath Item item) {
return new StandardListBoxModel()
.withEmptySelection()
.withMatching(AuthenticationTokens.matcher(DockerRegistryToken.class),
CredentialsProvider.lookupCredentials(
CredentialsProvider.lookupCredentialsInItem(
StandardCredentials.class,
item,
null,
Collections.<DomainRequirement>emptyList()
Collections.emptyList()
)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ public ListBoxModel doFillCredentialsIdItems(@AncestorInPath Item item, @QueryPa
.withMatching(
AuthenticationTokens.matcher(KeyMaterialFactory.class),
CredentialsProvider
.lookupCredentials(BASE_CREDENTIAL_TYPE, item, null, domainRequirements)
.lookupCredentialsInItem(BASE_CREDENTIAL_TYPE, item, null, domainRequirements)
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import org.junit.runners.Parameterized;
import org.jvnet.hudson.test.RestartableJenkinsRule;

import java.util.Collections;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.beans.HasPropertyWithValue.hasProperty;
import static org.hamcrest.collection.ArrayMatching.arrayContaining;
Expand Down Expand Up @@ -48,8 +50,8 @@ public static Object[][] params() {
protected void assertConfiguredAsExpected(final RestartableJenkinsRule j, final String s) {

//The credentials
final IdCredentials cred = CredentialsMatchers.firstOrNull(CredentialsProvider.lookupCredentials(IdCredentials.class, j.j.jenkins,
ACL.SYSTEM, new DockerServerDomainRequirement()), CredentialsMatchers.withId("dockerx509"));
final IdCredentials cred = CredentialsMatchers.firstOrNull(CredentialsProvider.lookupCredentialsInItemGroup(IdCredentials.class, j.j.jenkins,
ACL.SYSTEM2, Collections.singletonList(new DockerServerDomainRequirement())), CredentialsMatchers.withId("dockerx509"));
assertNotNull(cred);
assertThat(cred, instanceOf(DockerServerCredentials.class));
DockerServerCredentials dCreds = (DockerServerCredentials) cred;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,8 @@
import hudson.model.User;
import hudson.security.ACL;
import hudson.security.ACLContext;
import java.util.HashMap;
import java.util.Map;
import jenkins.model.Jenkins;
import jenkins.security.QueueItemAuthenticatorConfiguration;
import org.acegisecurity.Authentication;
import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;
Expand Down Expand Up @@ -138,10 +135,13 @@ public void testGetTokenForRun() throws Exception {
FreeStyleProject p1 = j.createFreeStyleProject();
FreeStyleProject p2 = j.createFreeStyleProject();

Map<String, Authentication> jobsToAuths = new HashMap<>();
jobsToAuths.put(p1.getFullName(), User.getById("alice", true).impersonate());
jobsToAuths.put(p2.getFullName(), User.getById("bob", true).impersonate());
QueueItemAuthenticatorConfiguration.get().getAuthenticators().replace(new MockQueueItemAuthenticator(jobsToAuths));
QueueItemAuthenticatorConfiguration.get()
.getAuthenticators()
.replace(new MockQueueItemAuthenticator()
.authenticate(
p1.getFullName(), User.getById("alice", true).impersonate2())
.authenticate(
p2.getFullName(), User.getById("bob", true).impersonate2()));

FreeStyleBuild r1 = j.buildAndAssertSuccess(p1);
try (ACLContext as = ACL.as(User.getById("alice", false))) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ public void configRoundTripEmpty() throws Exception {
j.submit(j.createWebClient().goTo("credentials/store/system/domain/" + domain.getName() + "/credential/"+credentials.getId()+"/update")
.getFormByName("update"));

j.assertEqualDataBoundBeans(credentials, CredentialsMatchers.firstOrNull(CredentialsProvider.lookupCredentials(IdCredentials.class, j.getInstance(),
ACL.SYSTEM, new DockerServerDomainRequirement()), CredentialsMatchers.withId(credentials.getId())));
j.assertEqualDataBoundBeans(credentials, CredentialsMatchers.firstOrNull(CredentialsProvider.lookupCredentialsInItemGroup(IdCredentials.class, j.getInstance(),
ACL.SYSTEM2, Collections.singletonList(new DockerServerDomainRequirement())), CredentialsMatchers.withId(credentials.getId())));
}

@Test
Expand All @@ -81,8 +81,8 @@ public void configRoundTripData() throws Exception {
j.submit(j.createWebClient().goTo("credentials/store/system/domain/" + domain.getName() + "/credential/"+credentials.getId()+"/update")
.getFormByName("update"));

j.assertEqualDataBoundBeans(credentials, CredentialsMatchers.firstOrNull(CredentialsProvider.lookupCredentials(IdCredentials.class, j.getInstance(),
ACL.SYSTEM, new DockerServerDomainRequirement()), CredentialsMatchers.withId(credentials.getId())));
j.assertEqualDataBoundBeans(credentials, CredentialsMatchers.firstOrNull(CredentialsProvider.lookupCredentialsInItemGroup(IdCredentials.class, j.getInstance(),
ACL.SYSTEM2, Collections.singletonList(new DockerServerDomainRequirement())), CredentialsMatchers.withId(credentials.getId())));
}

@Test
Expand Down Expand Up @@ -114,7 +114,7 @@ private HtmlForm getUpdateForm(Domain domain, DockerServerCredentials credential

private IdCredentials findFirstWithId(String credentialsId) {
return CredentialsMatchers.firstOrNull(
CredentialsProvider.lookupCredentials(IdCredentials.class, j.getInstance(), ACL.SYSTEM, new DockerServerDomainRequirement()),
CredentialsProvider.lookupCredentialsInItemGroup(IdCredentials.class, j.getInstance(), ACL.SYSTEM2, Collections.singletonList(new DockerServerDomainRequirement())),
CredentialsMatchers.withId(credentialsId));
}
}