File tree 2 files changed +27
-1
lines changed
main/java/org/springframework/security/authentication
test/java/org/springframework/security/authentication
2 files changed +27
-1
lines changed Original file line number Diff line number Diff line change 30
30
import org .springframework .security .core .CredentialsContainer ;
31
31
import org .springframework .security .core .SpringSecurityMessageSource ;
32
32
import org .springframework .util .Assert ;
33
+ import org .springframework .util .CollectionUtils ;
33
34
34
35
/**
35
36
* Iterates an {@link Authentication} request through a list of
@@ -145,7 +146,7 @@ private void checkState() {
145
146
throw new IllegalArgumentException (
146
147
"A parent AuthenticationManager or a list "
147
148
+ "of AuthenticationProviders is required" );
148
- } else if (providers .contains (null )) {
149
+ } else if (CollectionUtils .contains (providers . iterator (), null )) {
149
150
throw new IllegalArgumentException (
150
151
"providers list cannot contain null values" );
151
152
}
Original file line number Diff line number Diff line change @@ -102,6 +102,31 @@ public void testStartupFailsIfProvidersNotSetAsVarargs() {
102
102
new ProviderManager ((AuthenticationProvider ) null );
103
103
}
104
104
105
+ @ Test (expected = IllegalArgumentException .class )
106
+ public void testStartupFailsIfProvidersContainNullElement () {
107
+ new ProviderManager (Arrays .asList (mock (AuthenticationProvider .class ), null ));
108
+ }
109
+
110
+ @ Test
111
+ public void testUsingNullNotPermittedList () {
112
+ // imitated Java9 List.of(e) object, which disallows null elements and
113
+ // throws NPE when contains(null) called
114
+ List <AuthenticationProvider > providers = new ArrayList <AuthenticationProvider >() {
115
+ private static final long serialVersionUID = 1L ;
116
+
117
+ @ Override
118
+ public boolean contains (Object o ) {
119
+ if (o == null ) {
120
+ throw new NullPointerException ();
121
+ }
122
+ return super .contains (o );
123
+ }
124
+ };
125
+
126
+ providers .add (mock (AuthenticationProvider .class ));
127
+ new ProviderManager (providers );
128
+ }
129
+
105
130
@ Test
106
131
public void detailsAreNotSetOnAuthenticationTokenIfAlreadySetByProvider () {
107
132
Object requestDetails = "(Request Details)" ;
You can’t perform that action at this time.
0 commit comments