Skip to content

ProviderManager Should Use CollectionUtils#contains #8695

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

Closed
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 @@ -30,6 +30,7 @@
import org.springframework.security.core.CredentialsContainer;
import org.springframework.security.core.SpringSecurityMessageSource;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;

/**
* Iterates an {@link Authentication} request through a list of
Expand Down Expand Up @@ -145,7 +146,7 @@ private void checkState() {
throw new IllegalArgumentException(
"A parent AuthenticationManager or a list "
+ "of AuthenticationProviders is required");
} else if (providers.contains(null)) {
} else if (CollectionUtils.contains(providers.iterator(), null)) {
throw new IllegalArgumentException(
"providers list cannot contain null values");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,31 @@ public void testStartupFailsIfProvidersNotSetAsVarargs() {
new ProviderManager((AuthenticationProvider) null);
}

@Test(expected = IllegalArgumentException.class)
public void testStartupFailsIfProvidersContainNullElement() {
new ProviderManager(Arrays.asList(mock(AuthenticationProvider.class), null));
}

@Test
public void testUsingNullNotPermittedList() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this test has the right idea. It seems like the list ought to have a null element, though, to fully describe the use case.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assumed it already existed.
I've created additional test case.

// imitated Java9 List.of(e) object, which disallows null elements and
// throws NPE when contains(null) called
List<AuthenticationProvider> providers = new ArrayList<AuthenticationProvider>() {
private static final long serialVersionUID = 1L;

@Override
public boolean contains(Object o) {
if (o == null) {
throw new NullPointerException();
}
return super.contains(o);
}
};

providers.add(mock(AuthenticationProvider.class));
new ProviderManager(providers);
}

@Test
public void detailsAreNotSetOnAuthenticationTokenIfAlreadySetByProvider() {
Object requestDetails = "(Request Details)";
Expand Down