Skip to content

Commit 96f4fe7

Browse files
authored
Migrate from Acegi to Spring Security (#158)
1 parent c22bcaf commit 96f4fe7

File tree

5 files changed

+19
-17
lines changed

5 files changed

+19
-17
lines changed

src/main/java/org/jenkinsci/plugins/docker/commons/credentials/DockerRegistryEndpoint.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -395,11 +395,11 @@ public ListBoxModel doFillCredentialsIdItems(@AncestorInPath Item item) {
395395
return new StandardListBoxModel()
396396
.withEmptySelection()
397397
.withMatching(AuthenticationTokens.matcher(DockerRegistryToken.class),
398-
CredentialsProvider.lookupCredentials(
398+
CredentialsProvider.lookupCredentialsInItem(
399399
StandardCredentials.class,
400400
item,
401401
null,
402-
Collections.<DomainRequirement>emptyList()
402+
Collections.emptyList()
403403
)
404404
);
405405
}

src/main/java/org/jenkinsci/plugins/docker/commons/credentials/DockerServerEndpoint.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ public ListBoxModel doFillCredentialsIdItems(@AncestorInPath Item item, @QueryPa
220220
.withMatching(
221221
AuthenticationTokens.matcher(KeyMaterialFactory.class),
222222
CredentialsProvider
223-
.lookupCredentials(BASE_CREDENTIAL_TYPE, item, null, domainRequirements)
223+
.lookupCredentialsInItem(BASE_CREDENTIAL_TYPE, item, null, domainRequirements)
224224
);
225225
}
226226

src/test/java/org/jenkinsci/plugins/docker/commons/CasCTest.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
import org.junit.runners.Parameterized;
1919
import org.jvnet.hudson.test.RestartableJenkinsRule;
2020

21+
import java.util.Collections;
22+
2123
import static org.hamcrest.MatcherAssert.assertThat;
2224
import static org.hamcrest.beans.HasPropertyWithValue.hasProperty;
2325
import static org.hamcrest.collection.ArrayMatching.arrayContaining;
@@ -48,8 +50,8 @@ public static Object[][] params() {
4850
protected void assertConfiguredAsExpected(final RestartableJenkinsRule j, final String s) {
4951

5052
//The credentials
51-
final IdCredentials cred = CredentialsMatchers.firstOrNull(CredentialsProvider.lookupCredentials(IdCredentials.class, j.j.jenkins,
52-
ACL.SYSTEM, new DockerServerDomainRequirement()), CredentialsMatchers.withId("dockerx509"));
53+
final IdCredentials cred = CredentialsMatchers.firstOrNull(CredentialsProvider.lookupCredentialsInItemGroup(IdCredentials.class, j.j.jenkins,
54+
ACL.SYSTEM2, Collections.singletonList(new DockerServerDomainRequirement())), CredentialsMatchers.withId("dockerx509"));
5355
assertNotNull(cred);
5456
assertThat(cred, instanceOf(DockerServerCredentials.class));
5557
DockerServerCredentials dCreds = (DockerServerCredentials) cred;

src/test/java/org/jenkinsci/plugins/docker/commons/credentials/DockerRegistryEndpointTest.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,8 @@
4141
import hudson.model.User;
4242
import hudson.security.ACL;
4343
import hudson.security.ACLContext;
44-
import java.util.HashMap;
45-
import java.util.Map;
4644
import jenkins.model.Jenkins;
4745
import jenkins.security.QueueItemAuthenticatorConfiguration;
48-
import org.acegisecurity.Authentication;
4946
import org.junit.Assert;
5047
import org.junit.Rule;
5148
import org.junit.Test;
@@ -138,10 +135,13 @@ public void testGetTokenForRun() throws Exception {
138135
FreeStyleProject p1 = j.createFreeStyleProject();
139136
FreeStyleProject p2 = j.createFreeStyleProject();
140137

141-
Map<String, Authentication> jobsToAuths = new HashMap<>();
142-
jobsToAuths.put(p1.getFullName(), User.getById("alice", true).impersonate());
143-
jobsToAuths.put(p2.getFullName(), User.getById("bob", true).impersonate());
144-
QueueItemAuthenticatorConfiguration.get().getAuthenticators().replace(new MockQueueItemAuthenticator(jobsToAuths));
138+
QueueItemAuthenticatorConfiguration.get()
139+
.getAuthenticators()
140+
.replace(new MockQueueItemAuthenticator()
141+
.authenticate(
142+
p1.getFullName(), User.getById("alice", true).impersonate2())
143+
.authenticate(
144+
p2.getFullName(), User.getById("bob", true).impersonate2()));
145145

146146
FreeStyleBuild r1 = j.buildAndAssertSuccess(p1);
147147
try (ACLContext as = ACL.as(User.getById("alice", false))) {

src/test/java/org/jenkinsci/plugins/docker/commons/credentials/DockerServerCredentialsTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ public void configRoundTripEmpty() throws Exception {
6565
j.submit(j.createWebClient().goTo("credentials/store/system/domain/" + domain.getName() + "/credential/"+credentials.getId()+"/update")
6666
.getFormByName("update"));
6767

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

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

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

8888
@Test
@@ -114,7 +114,7 @@ private HtmlForm getUpdateForm(Domain domain, DockerServerCredentials credential
114114

115115
private IdCredentials findFirstWithId(String credentialsId) {
116116
return CredentialsMatchers.firstOrNull(
117-
CredentialsProvider.lookupCredentials(IdCredentials.class, j.getInstance(), ACL.SYSTEM, new DockerServerDomainRequirement()),
117+
CredentialsProvider.lookupCredentialsInItemGroup(IdCredentials.class, j.getInstance(), ACL.SYSTEM2, Collections.singletonList(new DockerServerDomainRequirement())),
118118
CredentialsMatchers.withId(credentialsId));
119119
}
120120
}

0 commit comments

Comments
 (0)