Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #77 from stephenc/jenkins-41004
[JENKINS-41004] When duplicate credentials have the same ID, the first one wins
  • Loading branch information
stephenc committed Jan 26, 2017
2 parents 92db855 + d163e79 commit e0a5416
Showing 1 changed file with 33 additions and 5 deletions.
Expand Up @@ -74,6 +74,7 @@
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
Expand Down Expand Up @@ -406,10 +407,17 @@ public static <C extends Credentials> List<C> lookupCredentials(@NonNull Class<C
return resolver.resolve(originals);
}
List<C> result = new ArrayList<C>();
Set<String> ids = new HashSet<String>();
for (CredentialsProvider provider : all()) {
if (provider.isEnabled(itemGroup) && provider.isApplicable(type)) {
try {
result.addAll(provider.getCredentials(type, itemGroup, authentication, domainRequirements));
for (C c : provider.getCredentials(type, itemGroup, authentication, domainRequirements)) {
if (!(c instanceof IdCredentials) || ids.add(((IdCredentials) c).getId())) {
// if IdCredentials, only add if we havent added already
// if not IdCredentials, always add
result.add(c);
}
}
} catch (NoClassDefFoundError e) {
LOGGER.log(Level.FINE, "Could not retrieve provider credentials from " + provider
+ " likely due to missing optional dependency", e);
Expand Down Expand Up @@ -456,11 +464,17 @@ public static <C extends IdCredentials> ListBoxModel listCredentials(@NonNull Cl
matcher);
}
ListBoxModel result = new ListBoxModel();
Set<String> ids = new HashSet<String>();
for (CredentialsProvider provider : all()) {
if (provider.isEnabled(itemGroup) && provider.isApplicable(type)) {
try {
result.addAll(
provider.getCredentialIds(type, itemGroup, authentication, domainRequirements, matcher));
for (ListBoxModel.Option option : provider.getCredentialIds(
type, itemGroup, authentication, domainRequirements, matcher)
) {
if (ids.add(option.value)) {
result.add(option);
}
}
} catch (NoClassDefFoundError e) {
LOGGER.log(Level.FINE, "Could not retrieve provider credentials from " + provider
+ " likely due to missing optional dependency", e);
Expand Down Expand Up @@ -531,10 +545,17 @@ public static <C extends Credentials> List<C> lookupCredentials(@NonNull Class<C
return resolver.resolve(originals);
}
List<C> result = new ArrayList<C>();
Set<String> ids = new HashSet<String>();
for (CredentialsProvider provider : all()) {
if (provider.isEnabled(item) && provider.isApplicable(type)) {
try {
result.addAll(provider.getCredentials(type, item, authentication, domainRequirements));
for (C c: provider.getCredentials(type, item, authentication, domainRequirements)) {
if (!(c instanceof IdCredentials) || ids.add(((IdCredentials) c).getId())) {
// if IdCredentials, only add if we havent added already
// if not IdCredentials, always add
result.add(c);
}
}
} catch (NoClassDefFoundError e) {
LOGGER.log(Level.FINE, "Could not retrieve provider credentials from " + provider
+ " likely due to missing optional dependency", e);
Expand Down Expand Up @@ -585,10 +606,17 @@ public static <C extends IdCredentials> ListBoxModel listCredentials(@NonNull Cl
domainRequirements, matcher);
}
ListBoxModel result = new ListBoxModel();
Set<String> ids = new HashSet<String>();
for (CredentialsProvider provider : all()) {
if (provider.isEnabled(item) && provider.isApplicable(type)) {
try {
result.addAll(provider.getCredentialIds(type, item, authentication, domainRequirements, matcher));
for (ListBoxModel.Option option : provider.getCredentialIds(
type, item, authentication, domainRequirements, matcher)
) {
if (ids.add(option.value)) {
result.add(option);
}
}
} catch (NoClassDefFoundError e) {
LOGGER.log(Level.FINE, "Could not retrieve provider credentials from " + provider
+ " likely due to missing optional dependency", e);
Expand Down

0 comments on commit e0a5416

Please sign in to comment.