ソースを参照

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
Thomas Vitale 5 年 前
コミット
5ce60022d3

+ 8 - 0
core/src/main/java/org/springframework/security/authentication/ProviderManager.java

@@ -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");
 		}
 	}
 

+ 7 - 2
core/src/test/java/org/springframework/security/authentication/ProviderManagerTests.java

@@ -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