Skip to content

Commit 5ce6002

Browse files
ThomasVitalejzheaux
authored andcommitted
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
1 parent df8feb8 commit 5ce6002

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

core/src/main/java/org/springframework/security/authentication/ProviderManager.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package org.springframework.security.authentication;
1717

18+
import java.util.Arrays;
1819
import java.util.Collections;
1920
import java.util.List;
2021

@@ -104,6 +105,10 @@ public ProviderManager(List<AuthenticationProvider> providers) {
104105
this(providers, null);
105106
}
106107

108+
public ProviderManager(AuthenticationProvider... providers) {
109+
this(Arrays.asList(providers), null);
110+
}
111+
107112
public ProviderManager(List<AuthenticationProvider> providers,
108113
AuthenticationManager parent) {
109114
Assert.notNull(providers, "providers list cannot be null");
@@ -124,6 +129,9 @@ private void checkState() {
124129
throw new IllegalArgumentException(
125130
"A parent AuthenticationManager or a list "
126131
+ "of AuthenticationProviders is required");
132+
} else if (providers.contains(null)) {
133+
throw new IllegalArgumentException(
134+
"providers list cannot contain null values");
127135
}
128136
}
129137

core/src/test/java/org/springframework/security/authentication/ProviderManagerTests.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,13 @@ public void authenticationSucceedsWhenFirstProviderReturnsNullButSecondAuthentic
9595
}
9696

9797
@Test(expected = IllegalArgumentException.class)
98-
public void testStartupFailsIfProvidersNotSet() {
99-
new ProviderManager(null);
98+
public void testStartupFailsIfProvidersNotSetAsList() {
99+
new ProviderManager((List<AuthenticationProvider>) null);
100+
}
101+
102+
@Test(expected = IllegalArgumentException.class)
103+
public void testStartupFailsIfProvidersNotSetAsVarargs() {
104+
new ProviderManager((AuthenticationProvider) null);
100105
}
101106

102107
@Test

0 commit comments

Comments
 (0)