ProviderManager should have a varargs constructor

- Added varargs constructor to ProviderManager.
- Added check for null values in AuthenticationProvider list.
- Updated ProviderManagerTests to test for null values using both constructors.

Fixes gh-7713
This commit is contained in:
Thomas Vitale 2020-01-30 19:26:13 +01:00 committed by Josh Cummings
parent df8feb8919
commit 5ce60022d3
2 changed files with 15 additions and 2 deletions

View File

@ -15,6 +15,7 @@
*/
package org.springframework.security.authentication;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
@ -104,6 +105,10 @@ public class ProviderManager implements AuthenticationManager, MessageSourceAwar
this(providers, null);
}
public ProviderManager(AuthenticationProvider... providers) {
this(Arrays.asList(providers), null);
}
public ProviderManager(List<AuthenticationProvider> providers,
AuthenticationManager parent) {
Assert.notNull(providers, "providers list cannot be null");
@ -124,6 +129,9 @@ public class ProviderManager implements AuthenticationManager, MessageSourceAwar
throw new IllegalArgumentException(
"A parent AuthenticationManager or a list "
+ "of AuthenticationProviders is required");
} else if (providers.contains(null)) {
throw new IllegalArgumentException(
"providers list cannot contain null values");
}
}

View File

@ -95,8 +95,13 @@ public class ProviderManagerTests {
}
@Test(expected = IllegalArgumentException.class)
public void testStartupFailsIfProvidersNotSet() {
new ProviderManager(null);
public void testStartupFailsIfProvidersNotSetAsList() {
new ProviderManager((List<AuthenticationProvider>) null);
}
@Test(expected = IllegalArgumentException.class)
public void testStartupFailsIfProvidersNotSetAsVarargs() {
new ProviderManager((AuthenticationProvider) null);
}
@Test