Skip to content
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

[JEP-227][JENKINS-39324] Replace Acegi Security with Spring Security APIs #490

Merged
merged 13 commits into from
Oct 27, 2023
Prev Previous commit
Next Next commit
Rename methods appropriately
Vlatombe committed Oct 24, 2023

Verified

This commit was signed with the committer’s verified signature.
Vlatombe Vincent Latombe
commit 7bb95b2c1c04e7d3494a802cc73108ccce352dc3
Original file line number Diff line number Diff line change
@@ -101,12 +101,12 @@ public <C extends IdCredentials> C lookupCredentials(@NonNull Class<C> type, @No
final boolean isSystem = ACL.SYSTEM2.equals(authentication);
if (!isSystem && run.getParent().hasPermission(CredentialsProvider.USE_OWN)) {
candidates.addAll(CredentialsProvider
.lookupCredentials(type, run.getParent(), authentication, domainRequirements));
.lookupCredentials2(type, run.getParent(), authentication, domainRequirements));
}
if (run.getParent().hasPermission(CredentialsProvider.USE_ITEM) || isSystem
|| isDefaultValue) {
candidates.addAll(
CredentialsProvider.lookupCredentials(type, run.getParent(), ACL.SYSTEM2, domainRequirements));
CredentialsProvider.lookupCredentials2(type, run.getParent(), ACL.SYSTEM2, domainRequirements));
}
return CredentialsMatchers.firstOrNull(candidates, CredentialsMatchers.withId(value));
}
@@ -120,13 +120,13 @@ public String describe() {
throw new IllegalStateException("Should only be called from value.jelly");
}
StandardCredentials c = CredentialsMatchers.firstOrNull(
CredentialsProvider.lookupCredentials(StandardCredentials.class, run.getParent(), ACL.SYSTEM2,
CredentialsProvider.lookupCredentials2(StandardCredentials.class, run.getParent(), ACL.SYSTEM2,
Collections.emptyList()), CredentialsMatchers.withId(value));
if (c != null) {
return CredentialsNameProvider.name(c);
}
c = CredentialsMatchers.firstOrNull(
CredentialsProvider.lookupCredentials(StandardCredentials.class, run.getParent(),
CredentialsProvider.lookupCredentials2(StandardCredentials.class, run.getParent(),
Jenkins.getAuthentication2(),
Collections.emptyList()), CredentialsMatchers.withId(value));
if (c != null) {
@@ -144,13 +144,13 @@ public String iconClassName() {
throw new IllegalStateException("Should only be called from value.jelly");
}
StandardCredentials c = CredentialsMatchers.firstOrNull(
CredentialsProvider.lookupCredentials(StandardCredentials.class, run.getParent(), ACL.SYSTEM2,
CredentialsProvider.lookupCredentials2(StandardCredentials.class, run.getParent(), ACL.SYSTEM2,
Collections.emptyList()), CredentialsMatchers.withId(value));
if (c != null) {
return c.getDescriptor().getIconClassName();
}
c = CredentialsMatchers.firstOrNull(
CredentialsProvider.lookupCredentials(StandardCredentials.class, run.getParent(),
CredentialsProvider.lookupCredentials2(StandardCredentials.class, run.getParent(),
Jenkins.getAuthentication2(),
Collections.emptyList()), CredentialsMatchers.withId(value));
if (c != null) {

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -423,20 +423,20 @@ public CredentialsStore getStore(@CheckForNull ModelObject object) {
*/
@NonNull
@Override
public <C extends Credentials> List<C> getCredentials2ItemGroup(@NonNull Class<C> type,
@Nullable ItemGroup itemGroup,
@Nullable Authentication authentication) {
return getCredentials2ItemGroup(type, itemGroup, authentication, Collections.emptyList());
public <C extends Credentials> List<C> getCredentials2(@NonNull Class<C> type,
@Nullable ItemGroup itemGroup,
@Nullable Authentication authentication) {
return getCredentials2(type, itemGroup, authentication, Collections.emptyList());
}

/**
* {@inheritDoc}
*/
@NonNull
@Override
public <C extends Credentials> List<C> getCredentials2ItemGroup(@NonNull Class<C> type, @Nullable ItemGroup itemGroup,
@Nullable Authentication authentication,
@NonNull List<DomainRequirement> domainRequirements) {
public <C extends Credentials> List<C> getCredentials2(@NonNull Class<C> type, @Nullable ItemGroup itemGroup,
@Nullable Authentication authentication,
@NonNull List<DomainRequirement> domainRequirements) {
if (ACL.SYSTEM2.equals(authentication)) {
CredentialsMatcher matcher = Jenkins.get() == itemGroup ? always() : not(withScope(SYSTEM));
return DomainCredentials.getCredentials(SystemCredentialsProvider.getInstance()
@@ -450,19 +450,19 @@ public <C extends Credentials> List<C> getCredentials2ItemGroup(@NonNull Class<C
*/
@NonNull
@Override
public <C extends Credentials> List<C> getCredentials2Item(@NonNull Class<C> type, @NonNull Item item,
@Nullable Authentication authentication) {
return getCredentials2Item(type, item, authentication, Collections.emptyList());
public <C extends Credentials> List<C> getCredentials2(@NonNull Class<C> type, @NonNull Item item,
@Nullable Authentication authentication) {
return getCredentials2(type, item, authentication, Collections.emptyList());
}

/**
* {@inheritDoc}
*/
@NonNull
@Override
public <C extends Credentials> List<C> getCredentials2Item(@NonNull Class<C> type, @NonNull Item item,
@Nullable Authentication authentication,
@NonNull List<DomainRequirement> domainRequirements) {
public <C extends Credentials> List<C> getCredentials2(@NonNull Class<C> type, @NonNull Item item,
@Nullable Authentication authentication,
@NonNull List<DomainRequirement> domainRequirements) {
if (ACL.SYSTEM2.equals(authentication)) {
return DomainCredentials.getCredentials(SystemCredentialsProvider.getInstance()
.getDomainCredentialsMap(), type, domainRequirements, not(withScope(SYSTEM)));
Original file line number Diff line number Diff line change
@@ -118,20 +118,20 @@ public CredentialsStore getStore(@CheckForNull ModelObject object) {
*/
@NonNull
@Override
public <C extends Credentials> List<C> getCredentials2ItemGroup(@NonNull Class<C> type, @Nullable ItemGroup itemGroup,
@Nullable Authentication authentication) {
return getCredentials2ItemGroup(type, itemGroup, authentication, Collections.emptyList());
public <C extends Credentials> List<C> getCredentials2(@NonNull Class<C> type, @Nullable ItemGroup itemGroup,
@Nullable Authentication authentication) {
return getCredentials2(type, itemGroup, authentication, Collections.emptyList());
}

/**
* {@inheritDoc}
*/
@NonNull
@Override
public <C extends Credentials> List<C> getCredentials2ItemGroup(@NonNull Class<C> type,
@Nullable ItemGroup itemGroup,
@Nullable Authentication authentication,
@NonNull List<DomainRequirement> domainRequirements) {
public <C extends Credentials> List<C> getCredentials2(@NonNull Class<C> type,
@Nullable ItemGroup itemGroup,
@Nullable Authentication authentication,
@NonNull List<DomainRequirement> domainRequirements) {
// ignore itemGroup, as per-user credentials are available on any object
if (authentication == null) {
// assume ACL#SYSTEM
Original file line number Diff line number Diff line change
@@ -290,7 +290,7 @@ public AbstractIdCredentialsListBoxModel<T, C> withMatching(@NonNull Credentials
* @param context the context to add credentials from.
* @param type the base class of the credentials to add.
* @return {@code this} for method chaining.
* @see CredentialsProvider#listCredentials(Class, Item, Authentication, List, CredentialsMatcher)
* @see CredentialsProvider#listCredentials2(Class, Item, Authentication, List, CredentialsMatcher)
* @since 2.1.0
*/
public AbstractIdCredentialsListBoxModel<T, C> include(@Nullable Item context, @NonNull Class<? extends C> type) {
@@ -304,7 +304,7 @@ public AbstractIdCredentialsListBoxModel<T, C> include(@Nullable Item context, @
* @param context the context to add credentials from.
* @param type the base class of the credentials to add.
* @return {@code this} for method chaining.
* @see CredentialsProvider#listCredentials(Class, ItemGroup, Authentication, List, CredentialsMatcher)
* @see CredentialsProvider#listCredentials2(Class, ItemGroup, Authentication, List, CredentialsMatcher)
* @since 2.1.0
*/
public AbstractIdCredentialsListBoxModel<T, C> include(@NonNull ItemGroup context,
@@ -330,7 +330,7 @@ public AbstractIdCredentialsListBoxModel<T, C> includeAs(@NonNull org.acegisecur
* @param context the context to add credentials from.
* @param type the base class of the credentials to add.
* @return {@code this} for method chaining.
* @see CredentialsProvider#listCredentials(Class, Item, Authentication, List, CredentialsMatcher)
* @see CredentialsProvider#listCredentials2(Class, Item, Authentication, List, CredentialsMatcher)
* @since TODO
*/
public AbstractIdCredentialsListBoxModel<T, C> includeAs(@NonNull Authentication authentication,
@@ -357,7 +357,7 @@ public AbstractIdCredentialsListBoxModel<T, C> includeAs(@NonNull org.acegisecur
* @param context the context to add credentials from.
* @param type the base class of the credentials to add.
* @return {@code this} for method chaining.
* @see CredentialsProvider#listCredentials(Class, ItemGroup, Authentication, List, CredentialsMatcher)
* @see CredentialsProvider#listCredentials2(Class, ItemGroup, Authentication, List, CredentialsMatcher)
* @since TODO
*/
public AbstractIdCredentialsListBoxModel<T, C> includeAs(@NonNull Authentication authentication,
@@ -374,7 +374,7 @@ public AbstractIdCredentialsListBoxModel<T, C> includeAs(@NonNull Authentication
* @param type the base class of the credentials to add.
* @param domainRequirements the domain requirements.
* @return {@code this} for method chaining.
* @see CredentialsProvider#listCredentials(Class, Item, Authentication, List, CredentialsMatcher)
* @see CredentialsProvider#listCredentials2(Class, Item, Authentication, List, CredentialsMatcher)
* @since 2.1.0
*/
public AbstractIdCredentialsListBoxModel<T, C> include(@Nullable Item context, @NonNull Class<? extends C> type,
@@ -390,7 +390,7 @@ public AbstractIdCredentialsListBoxModel<T, C> include(@Nullable Item context, @
* @param type the base class of the credentials to add.
* @param domainRequirements the domain requirements.
* @return {@code this} for method chaining.
* @see CredentialsProvider#listCredentials(Class, ItemGroup, Authentication, List, CredentialsMatcher)
* @see CredentialsProvider#listCredentials2(Class, ItemGroup, Authentication, List, CredentialsMatcher)
* @since 2.1.0
*/
public AbstractIdCredentialsListBoxModel<T, C> include(@NonNull ItemGroup context, @NonNull Class<? extends C> type,
@@ -418,7 +418,7 @@ public AbstractIdCredentialsListBoxModel<T, C> includeAs(@NonNull org.acegisecur
* @param type the base class of the credentials to add.
* @param domainRequirements the domain requirements.
* @return {@code this} for method chaining.
* @see CredentialsProvider#listCredentials(Class, Item, Authentication, List, CredentialsMatcher)
* @see CredentialsProvider#listCredentials2(Class, Item, Authentication, List, CredentialsMatcher)
* @since TODO
*/
public AbstractIdCredentialsListBoxModel<T, C> includeAs(@NonNull Authentication authentication,
@@ -448,7 +448,7 @@ public AbstractIdCredentialsListBoxModel<T, C> includeAs(@NonNull org.acegisecur
* @param type the base class of the credentials to add.
* @param domainRequirements the domain requirements.
* @return {@code this} for method chaining.
* @see CredentialsProvider#listCredentials(Class, ItemGroup, Authentication, List, CredentialsMatcher)
* @see CredentialsProvider#listCredentials2(Class, ItemGroup, Authentication, List, CredentialsMatcher)
* @since TODO
*/
public AbstractIdCredentialsListBoxModel<T, C> includeAs(@NonNull Authentication authentication,
@@ -467,7 +467,7 @@ public AbstractIdCredentialsListBoxModel<T, C> includeAs(@NonNull Authentication
* @param domainRequirements the domain requirements.
* @param matcher the filter to apply to the credentials.
* @return {@code this} for method chaining.
* @see CredentialsProvider#listCredentials(Class, Item, Authentication, List, CredentialsMatcher)
* @see CredentialsProvider#listCredentials2(Class, Item, Authentication, List, CredentialsMatcher)
* @since 2.1.0
*/
public AbstractIdCredentialsListBoxModel<T, C> includeMatching(@Nullable Item context,
@@ -486,7 +486,7 @@ public AbstractIdCredentialsListBoxModel<T, C> includeMatching(@Nullable Item co
* @param domainRequirements the domain requirements.
* @param matcher the filter to apply to the credentials.
* @return {@code this} for method chaining.
* @see CredentialsProvider#listCredentials(Class, ItemGroup, Authentication, List, CredentialsMatcher)
* @see CredentialsProvider#listCredentials2(Class, ItemGroup, Authentication, List, CredentialsMatcher)
* @since 2.1.0
*/
public AbstractIdCredentialsListBoxModel<T, C> includeMatching(@NonNull ItemGroup context,
@@ -519,7 +519,7 @@ public AbstractIdCredentialsListBoxModel<T, C> includeMatchingAs(@NonNull org.ac
* @param domainRequirements the domain requirements.
* @param matcher the filter to apply to the credentials.
* @return {@code this} for method chaining.
* @see CredentialsProvider#listCredentials(Class, Item, Authentication, List, CredentialsMatcher)
* @see CredentialsProvider#listCredentials2(Class, Item, Authentication, List, CredentialsMatcher)
* @since TODO
*/
public AbstractIdCredentialsListBoxModel<T, C> includeMatchingAs(@NonNull Authentication authentication,
@@ -528,7 +528,7 @@ public AbstractIdCredentialsListBoxModel<T, C> includeMatchingAs(@NonNull Authen
@NonNull
List<DomainRequirement> domainRequirements,
@NonNull CredentialsMatcher matcher) {
addMissing(CredentialsProvider.listCredentials(type, context, authentication, domainRequirements, matcher));
addMissing(CredentialsProvider.listCredentials2(type, context, authentication, domainRequirements, matcher));
return this;
}

@@ -555,7 +555,7 @@ public AbstractIdCredentialsListBoxModel<T, C> includeMatchingAs(@NonNull org.ac
* @param domainRequirements the domain requirements.
* @param matcher the filter to apply to the credentials.
* @return {@code this} for method chaining.
* @see CredentialsProvider#listCredentials(Class, ItemGroup, Authentication, List, CredentialsMatcher)
* @see CredentialsProvider#listCredentials2(Class, ItemGroup, Authentication, List, CredentialsMatcher)
* @since TODO
*/
public AbstractIdCredentialsListBoxModel<T, C> includeMatchingAs(@NonNull Authentication authentication,
@@ -564,7 +564,7 @@ public AbstractIdCredentialsListBoxModel<T, C> includeMatchingAs(@NonNull Authen
@NonNull
List<DomainRequirement> domainRequirements,
@NonNull CredentialsMatcher matcher) {
addMissing(CredentialsProvider.listCredentials(type, context, authentication, domainRequirements, matcher));
addMissing(CredentialsProvider.listCredentials2(type, context, authentication, domainRequirements, matcher));
return this;
}

Original file line number Diff line number Diff line change
@@ -170,22 +170,22 @@ public void testManageUserCredentials() throws IOException {
userStore.addCredentials(Domain.global(), aliceCred1);
userStore.addCredentials(Domain.global(), aliceCred2);

assertEquals(2, CredentialsProvider.lookupCredentials(DummyCredentials.class, (Item) null, alice.impersonate2(), Collections.emptyList()).size());
assertTrue(CredentialsProvider.lookupCredentials(DummyCredentials.class, r.jenkins, ACL.SYSTEM2, Collections.emptyList()).isEmpty());
assertTrue(CredentialsProvider.lookupCredentials(DummyCredentials.class, r.jenkins, Jenkins.ANONYMOUS2, Collections.emptyList()).isEmpty());
assertEquals(2, CredentialsProvider.lookupCredentials2(DummyCredentials.class, (Item) null, alice.impersonate2(), Collections.emptyList()).size());
assertTrue(CredentialsProvider.lookupCredentials2(DummyCredentials.class, r.jenkins, ACL.SYSTEM2, Collections.emptyList()).isEmpty());
assertTrue(CredentialsProvider.lookupCredentials2(DummyCredentials.class, r.jenkins, Jenkins.ANONYMOUS2, Collections.emptyList()).isEmpty());

// Remove credentials
userStore.removeCredentials(Domain.global(), aliceCred2);

assertEquals(1, CredentialsProvider.lookupCredentials(DummyCredentials.class, (Item) null, alice.impersonate2(), Collections.emptyList()).size());
assertTrue(CredentialsProvider.lookupCredentials(DummyCredentials.class, r.jenkins, ACL.SYSTEM2, Collections.emptyList()).isEmpty());
assertTrue(CredentialsProvider.lookupCredentials(DummyCredentials.class, r.jenkins, Jenkins.ANONYMOUS2, Collections.emptyList()).isEmpty());
assertEquals(1, CredentialsProvider.lookupCredentials2(DummyCredentials.class, (Item) null, alice.impersonate2(), Collections.emptyList()).size());
assertTrue(CredentialsProvider.lookupCredentials2(DummyCredentials.class, r.jenkins, ACL.SYSTEM2, Collections.emptyList()).isEmpty());
assertTrue(CredentialsProvider.lookupCredentials2(DummyCredentials.class, r.jenkins, Jenkins.ANONYMOUS2, Collections.emptyList()).isEmpty());

// Update credentials
userStore.updateCredentials(Domain.global(), aliceCred1, aliceCred3);

assertEquals(1, CredentialsProvider.lookupCredentials(DummyCredentials.class, (Item) null, alice.impersonate2(), Collections.emptyList()).size());
assertEquals(aliceCred3.getUsername(), CredentialsProvider.lookupCredentials(DummyCredentials.class, (Item) null, alice.impersonate2(), Collections.emptyList()).get(0).getUsername());
assertEquals(1, CredentialsProvider.lookupCredentials2(DummyCredentials.class, (Item) null, alice.impersonate2(), Collections.emptyList()).size());
assertEquals(aliceCred3.getUsername(), CredentialsProvider.lookupCredentials2(DummyCredentials.class, (Item) null, alice.impersonate2(), Collections.emptyList()).get(0).getUsername());
}
}

@@ -204,22 +204,22 @@ public void testUpdateAndDeleteCredentials() throws IOException {
store.addCredentials(Domain.global(), systemCred2);
store.addCredentials(Domain.global(), globalCred);

assertEquals(3, CredentialsProvider.lookupCredentials(DummyCredentials.class, r.jenkins, ACL.SYSTEM2, Collections.emptyList()).size());
assertEquals(1, CredentialsProvider.lookupCredentials(DummyCredentials.class, project, ACL.SYSTEM2, Collections.emptyList()).size());
assertEquals(globalCred.getUsername(), CredentialsProvider.lookupCredentials(DummyCredentials.class, project, ACL.SYSTEM2, Collections.emptyList()).get(0).getUsername());
assertEquals(3, CredentialsProvider.lookupCredentials2(DummyCredentials.class, r.jenkins, ACL.SYSTEM2, Collections.emptyList()).size());
assertEquals(1, CredentialsProvider.lookupCredentials2(DummyCredentials.class, project, ACL.SYSTEM2, Collections.emptyList()).size());
assertEquals(globalCred.getUsername(), CredentialsProvider.lookupCredentials2(DummyCredentials.class, project, ACL.SYSTEM2, Collections.emptyList()).get(0).getUsername());

// Update credentials
store.updateCredentials(Domain.global(), globalCred, modCredential);

assertEquals(3, CredentialsProvider.lookupCredentials(DummyCredentials.class, r.jenkins, ACL.SYSTEM2, Collections.emptyList()).size());
assertEquals(1, CredentialsProvider.lookupCredentials(DummyCredentials.class, project, ACL.SYSTEM2, Collections.emptyList()).size());
assertEquals(modCredential.getUsername(), CredentialsProvider.lookupCredentials(DummyCredentials.class, project, ACL.SYSTEM2, Collections.emptyList()).get(0).getUsername());
assertEquals(3, CredentialsProvider.lookupCredentials2(DummyCredentials.class, r.jenkins, ACL.SYSTEM2, Collections.emptyList()).size());
assertEquals(1, CredentialsProvider.lookupCredentials2(DummyCredentials.class, project, ACL.SYSTEM2, Collections.emptyList()).size());
assertEquals(modCredential.getUsername(), CredentialsProvider.lookupCredentials2(DummyCredentials.class, project, ACL.SYSTEM2, Collections.emptyList()).get(0).getUsername());

// Remove credentials
store.removeCredentials(Domain.global(), systemCred2);

assertEquals(2, CredentialsProvider.lookupCredentials(DummyCredentials.class, r.jenkins, ACL.SYSTEM2, Collections.emptyList()).size());
assertEquals(1, CredentialsProvider.lookupCredentials(DummyCredentials.class, project, ACL.SYSTEM2, Collections.emptyList()).size());
assertEquals(2, CredentialsProvider.lookupCredentials2(DummyCredentials.class, r.jenkins, ACL.SYSTEM2, Collections.emptyList()).size());
assertEquals(1, CredentialsProvider.lookupCredentials2(DummyCredentials.class, project, ACL.SYSTEM2, Collections.emptyList()).size());
}

@Test
@@ -341,10 +341,10 @@ public void trackingOfFingerprintDependsOnConfiguration() throws Exception {
@Test
@Issue("JENKINS-65333")
public void insertionOrderLookupCredentials() {
assertThat(CredentialsProvider.lookupCredentials(Credentials.class, (Item) null, ACL.SYSTEM2, Collections.emptyList()), hasSize(0));
assertThat(CredentialsProvider.lookupCredentials2(Credentials.class, (Item) null, ACL.SYSTEM2, Collections.emptyList()), hasSize(0));
SystemCredentialsProvider.getInstance().getCredentials().add(new DummyIdCredentials("1", CredentialsScope.SYSTEM, "beta", "bar", "description 1"));
SystemCredentialsProvider.getInstance().getCredentials().add(new DummyIdCredentials("2", CredentialsScope.SYSTEM, "alpha", "bar", "description 2"));
List<DummyIdCredentials> credentials = CredentialsProvider.lookupCredentials(DummyIdCredentials.class, (Item) null, ACL.SYSTEM2, Collections.emptyList());
List<DummyIdCredentials> credentials = CredentialsProvider.lookupCredentials2(DummyIdCredentials.class, (Item) null, ACL.SYSTEM2, Collections.emptyList());
assertThat(credentials, hasSize(2));
// Insertion order
assertThat(credentials.get(0).getUsername(), is("beta"));
@@ -354,10 +354,10 @@ public void insertionOrderLookupCredentials() {
@Test
@Issue("JENKINS-65333")
public void credentialsSortedByNameInUI() {
assertThat(CredentialsProvider.lookupCredentials(Credentials.class, (Item) null, ACL.SYSTEM2, Collections.emptyList()), hasSize(0));
assertThat(CredentialsProvider.lookupCredentials2(Credentials.class, (Item) null, ACL.SYSTEM2, Collections.emptyList()), hasSize(0));
SystemCredentialsProvider.getInstance().getCredentials().add(new DummyIdCredentials("1", CredentialsScope.SYSTEM, "beta", "bar", "description 1"));
SystemCredentialsProvider.getInstance().getCredentials().add(new DummyIdCredentials("2", CredentialsScope.SYSTEM, "alpha", "bar", "description 2"));
ListBoxModel options = CredentialsProvider.listCredentials(DummyIdCredentials.class, (Item) null, ACL.SYSTEM2, Collections.emptyList(), CredentialsMatchers.always());
ListBoxModel options = CredentialsProvider.listCredentials2(DummyIdCredentials.class, (Item) null, ACL.SYSTEM2, Collections.emptyList(), CredentialsMatchers.always());
// Options are sorted by name
assertThat(options, hasSize(2));
assertThat(options.get(0).value, is("2"));
Original file line number Diff line number Diff line change
@@ -244,7 +244,7 @@ public PollingResult compareRemoteRevisionWith(@NonNull Job<?, ?> project, @Null
@NonNull SCMRevisionState baseline)
throws IOException {
StandardUsernamePasswordCredentials credentials = CredentialsMatchers.firstOrNull(
CredentialsProvider.lookupCredentials(StandardUsernamePasswordCredentials.class, project,
CredentialsProvider.lookupCredentials2(StandardUsernamePasswordCredentials.class, project,
CredentialsProvider.getDefaultAuthenticationOf2(project),
Collections.emptyList()), CredentialsMatchers.withId(id));
if (credentials == null) {
Original file line number Diff line number Diff line change
@@ -76,16 +76,16 @@ public Set<CredentialsScope> getScopes(ModelObject object) {

@NonNull
@Override
public <C extends Credentials> List<C> getCredentials2ItemGroup(@NonNull Class<C> type, @Nullable ItemGroup itemGroup,
@Nullable Authentication authentication) {
return getCredentials2ItemGroup(type, itemGroup, authentication, Collections.emptyList());
public <C extends Credentials> List<C> getCredentials2(@NonNull Class<C> type, @Nullable ItemGroup itemGroup,
@Nullable Authentication authentication) {
return getCredentials2(type, itemGroup, authentication, Collections.emptyList());
}

@NonNull
@Override
public <C extends Credentials> List<C> getCredentials2ItemGroup(@NonNull Class<C> type, @Nullable ItemGroup itemGroup,
@Nullable Authentication authentication,
@NonNull List<DomainRequirement> domainRequirements) {
public <C extends Credentials> List<C> getCredentials2(@NonNull Class<C> type, @Nullable ItemGroup itemGroup,
@Nullable Authentication authentication,
@NonNull List<DomainRequirement> domainRequirements) {
if (authentication == null) {
authentication = ACL.SYSTEM2;
}
Original file line number Diff line number Diff line change
@@ -45,15 +45,15 @@ public class CredentialsProviderTest {
@Test
@ConfiguredWithCode("CredentialsProviderExtension.yaml")
public void import_credentials_provider_extension_credentials() {
List<DummyCredentials> dummyCred = CredentialsProvider.lookupCredentials(
List<DummyCredentials> dummyCred = CredentialsProvider.lookupCredentials2(
DummyCredentials.class, j.jenkins, ACL.SYSTEM2,
Collections.emptyList()
);
assertThat(dummyCred, hasSize(1));
assertThat(dummyCred.get(0).getUsername(), equalTo("user1"));

// the system provider works fine too
List<UsernamePasswordCredentials> ups = CredentialsProvider.lookupCredentials(
List<UsernamePasswordCredentials> ups = CredentialsProvider.lookupCredentials2(
UsernamePasswordCredentials.class, j.jenkins, ACL.SYSTEM2,
Collections.singletonList(new HostnameRequirement("api.test.com"))
);
@@ -84,7 +84,7 @@ public TestCredentialsProvider() {

@NonNull
@Override
public <C extends Credentials> List<C> getCredentials2ItemGroup(@NonNull Class<C> type, @Nullable ItemGroup itemGroup, @Nullable Authentication authentication) {
public <C extends Credentials> List<C> getCredentials2(@NonNull Class<C> type, @Nullable ItemGroup itemGroup, @Nullable Authentication authentication) {
if (!type.equals(DummyCredentials.class)) {
return Collections.emptyList();
}
Original file line number Diff line number Diff line change
@@ -58,7 +58,7 @@ public class SystemCredentialsTest {

@Test
public void import_system_credentials() {
List<UsernamePasswordCredentials> ups = CredentialsProvider.lookupCredentials(
List<UsernamePasswordCredentials> ups = CredentialsProvider.lookupCredentials2(
UsernamePasswordCredentials.class, j.jenkins, ACL.SYSTEM2,
Collections.singletonList(new HostnameRequirement("api.test.com"))
);
Original file line number Diff line number Diff line change
@@ -71,7 +71,7 @@ public void testGetRestrictedCredentials() {
.add(falseCredentials);

Collection<Credentials> matchingCredentials =
CredentialsProvider.lookupCredentials(Credentials.class,
CredentialsProvider.lookupCredentials2(Credentials.class,
Jenkins.get(), ACL.SYSTEM2);

assertThat(matchingCredentials, hasItems(trueCredentials));
Original file line number Diff line number Diff line change
@@ -96,32 +96,32 @@ public void testCredentialsInCustomDomains() throws IOException {
List<DomainRequirement> reqFoo = Arrays.asList(new DomainRequirement[] { new HostnameRequirement("foo.com") });
List<DomainRequirement> reqBar = Arrays.asList(new DomainRequirement[] { new HostnameRequirement("bar.com") });

assertTrue(CredentialsProvider.lookupCredentials(DummyCredentials.class, r.jenkins, ACL.SYSTEM2, reqFoo).isEmpty());
assertTrue(CredentialsProvider.lookupCredentials(DummyCredentials.class, r.jenkins, ACL.SYSTEM2, reqBar).isEmpty());
assertTrue(CredentialsProvider.lookupCredentials2(DummyCredentials.class, r.jenkins, ACL.SYSTEM2, reqFoo).isEmpty());
assertTrue(CredentialsProvider.lookupCredentials2(DummyCredentials.class, r.jenkins, ACL.SYSTEM2, reqBar).isEmpty());

// Add credentials to domains
store.addCredentials(domainFoo, systemCred);
store.addCredentials(domainBar, systemCred1);

// Search credentials with specific domain restrictions
assertEquals(1, CredentialsProvider.lookupCredentials(DummyCredentials.class, r.jenkins, ACL.SYSTEM2, reqFoo).size());
assertEquals(systemCred.getUsername(), CredentialsProvider.lookupCredentials(DummyCredentials.class, r.jenkins, ACL.SYSTEM2, reqFoo).get(0).getUsername());
assertEquals(1, CredentialsProvider.lookupCredentials(DummyCredentials.class, r.jenkins, ACL.SYSTEM2, reqBar).size());
assertEquals(systemCred1.getUsername(), CredentialsProvider.lookupCredentials(DummyCredentials.class, r.jenkins, ACL.SYSTEM2, reqBar).get(0).getUsername());
assertEquals(1, CredentialsProvider.lookupCredentials2(DummyCredentials.class, r.jenkins, ACL.SYSTEM2, reqFoo).size());
assertEquals(systemCred.getUsername(), CredentialsProvider.lookupCredentials2(DummyCredentials.class, r.jenkins, ACL.SYSTEM2, reqFoo).get(0).getUsername());
assertEquals(1, CredentialsProvider.lookupCredentials2(DummyCredentials.class, r.jenkins, ACL.SYSTEM2, reqBar).size());
assertEquals(systemCred1.getUsername(), CredentialsProvider.lookupCredentials2(DummyCredentials.class, r.jenkins, ACL.SYSTEM2, reqBar).get(0).getUsername());

// Update credential from domain
store.updateCredentials(domainFoo, systemCred, systemCredMod);

assertEquals(1, CredentialsProvider.lookupCredentials(DummyCredentials.class, r.jenkins, ACL.SYSTEM2, reqFoo).size());
assertEquals(systemCredMod.getUsername(), CredentialsProvider.lookupCredentials(DummyCredentials.class, r.jenkins, ACL.SYSTEM2, reqFoo).get(0).getUsername());
assertEquals(1, CredentialsProvider.lookupCredentials(DummyCredentials.class, r.jenkins, ACL.SYSTEM2, reqBar).size());
assertEquals(systemCred1.getUsername(), CredentialsProvider.lookupCredentials(DummyCredentials.class, r.jenkins, ACL.SYSTEM2, reqBar).get(0).getUsername());
assertEquals(1, CredentialsProvider.lookupCredentials2(DummyCredentials.class, r.jenkins, ACL.SYSTEM2, reqFoo).size());
assertEquals(systemCredMod.getUsername(), CredentialsProvider.lookupCredentials2(DummyCredentials.class, r.jenkins, ACL.SYSTEM2, reqFoo).get(0).getUsername());
assertEquals(1, CredentialsProvider.lookupCredentials2(DummyCredentials.class, r.jenkins, ACL.SYSTEM2, reqBar).size());
assertEquals(systemCred1.getUsername(), CredentialsProvider.lookupCredentials2(DummyCredentials.class, r.jenkins, ACL.SYSTEM2, reqBar).get(0).getUsername());

// Remove credential from domain
store.removeCredentials(domainFoo, systemCredMod);

assertTrue(CredentialsProvider.lookupCredentials(DummyCredentials.class, r.jenkins, ACL.SYSTEM2, reqFoo).isEmpty());
assertEquals(1, CredentialsProvider.lookupCredentials(DummyCredentials.class, r.jenkins, ACL.SYSTEM2, reqBar).size());
assertEquals(systemCred1.getUsername(), CredentialsProvider.lookupCredentials(DummyCredentials.class, r.jenkins, ACL.SYSTEM2, reqBar).get(0).getUsername());
assertTrue(CredentialsProvider.lookupCredentials2(DummyCredentials.class, r.jenkins, ACL.SYSTEM2, reqFoo).isEmpty());
assertEquals(1, CredentialsProvider.lookupCredentials2(DummyCredentials.class, r.jenkins, ACL.SYSTEM2, reqBar).size());
assertEquals(systemCred1.getUsername(), CredentialsProvider.lookupCredentials2(DummyCredentials.class, r.jenkins, ACL.SYSTEM2, reqBar).get(0).getUsername());
}
}
Original file line number Diff line number Diff line change
@@ -340,12 +340,12 @@ public void fullSubmitOfUploadedKeystore() throws Exception {
newCredentialsForm.getInputsByName("_.password").forEach(input -> input.setValue(VALID_PASSWORD));
htmlPage.getDocumentElement().querySelector("input[type=file][name=uploadedCertFile]");

List<CertificateCredentials> certificateCredentials = CredentialsProvider.lookupCredentials(CertificateCredentials.class, (ItemGroup<?>) null, ACL.SYSTEM2);
List<CertificateCredentials> certificateCredentials = CredentialsProvider.lookupCredentials2(CertificateCredentials.class, (ItemGroup<?>) null, ACL.SYSTEM2);
assertThat(certificateCredentials, hasSize(0));

r.submit(newCredentialsForm);

certificateCredentials = CredentialsProvider.lookupCredentials(CertificateCredentials.class, (ItemGroup<?>) null, ACL.SYSTEM2);
certificateCredentials = CredentialsProvider.lookupCredentials2(CertificateCredentials.class, (ItemGroup<?>) null, ACL.SYSTEM2);
assertThat(certificateCredentials, hasSize(1));

CertificateCredentials certificate = certificateCredentials.get(0);