18
18
19
19
import java .util .ArrayList ;
20
20
import java .util .Arrays ;
21
- import java .util .Collections ;
22
21
import java .util .List ;
23
22
24
23
import org .junit .jupiter .api .Test ;
47
46
public class ProviderManagerTests {
48
47
49
48
@ Test
50
- public void authenticationFailsWithUnsupportedToken () {
49
+ void authenticationFailsWithUnsupportedToken () {
51
50
Authentication token = new AbstractAuthenticationToken (null ) {
52
51
@ Override
53
52
public Object getCredentials () {
@@ -65,7 +64,7 @@ public Object getPrincipal() {
65
64
}
66
65
67
66
@ Test
68
- public void credentialsAreClearedByDefault () {
67
+ void credentialsAreClearedByDefault () {
69
68
UsernamePasswordAuthenticationToken token = UsernamePasswordAuthenticationToken .unauthenticated ("Test" ,
70
69
"Password" );
71
70
ProviderManager mgr = makeProviderManager ();
@@ -78,8 +77,8 @@ public void credentialsAreClearedByDefault() {
78
77
}
79
78
80
79
@ Test
81
- public void authenticationSucceedsWithSupportedTokenAndReturnsExpectedObject () {
82
- final Authentication a = mock (Authentication .class );
80
+ void authenticationSucceedsWithSupportedTokenAndReturnsExpectedObject () {
81
+ Authentication a = mock (Authentication .class );
83
82
ProviderManager mgr = new ProviderManager (createProviderWhichReturns (a ));
84
83
AuthenticationEventPublisher publisher = mock (AuthenticationEventPublisher .class );
85
84
mgr .setAuthenticationEventPublisher (publisher );
@@ -89,8 +88,8 @@ public void authenticationSucceedsWithSupportedTokenAndReturnsExpectedObject() {
89
88
}
90
89
91
90
@ Test
92
- public void authenticationSucceedsWhenFirstProviderReturnsNullButSecondAuthenticates () {
93
- final Authentication a = mock (Authentication .class );
91
+ void authenticationSucceedsWhenFirstProviderReturnsNullButSecondAuthenticates () {
92
+ Authentication a = mock (Authentication .class );
94
93
ProviderManager mgr = new ProviderManager (
95
94
Arrays .asList (createProviderWhichReturns (null ), createProviderWhichReturns (a )));
96
95
AuthenticationEventPublisher publisher = mock (AuthenticationEventPublisher .class );
@@ -101,24 +100,24 @@ public void authenticationSucceedsWhenFirstProviderReturnsNullButSecondAuthentic
101
100
}
102
101
103
102
@ Test
104
- public void testStartupFailsIfProvidersNotSetAsList () {
103
+ void testStartupFailsIfProvidersNotSetAsList () {
105
104
assertThatIllegalArgumentException ().isThrownBy (() -> new ProviderManager ((List <AuthenticationProvider >) null ));
106
105
}
107
106
108
107
@ Test
109
- public void testStartupFailsIfProvidersNotSetAsVarargs () {
108
+ void testStartupFailsIfProvidersNotSetAsVarargs () {
110
109
assertThatIllegalArgumentException ().isThrownBy (() -> new ProviderManager ((AuthenticationProvider ) null ));
111
110
}
112
111
113
112
@ Test
114
- public void testStartupFailsIfProvidersContainNullElement () {
113
+ void testStartupFailsIfProvidersContainNullElement () {
115
114
assertThatIllegalArgumentException ()
116
115
.isThrownBy (() -> new ProviderManager (Arrays .asList (mock (AuthenticationProvider .class ), null )));
117
116
}
118
117
119
118
// gh-8689
120
119
@ Test
121
- public void constructorWhenUsingListOfThenNoException () {
120
+ void constructorWhenUsingListOfThenNoException () {
122
121
List <AuthenticationProvider > providers = spy (ArrayList .class );
123
122
// List.of(null) in JDK 9 throws a NullPointerException
124
123
given (providers .contains (eq (null ))).willThrow (NullPointerException .class );
@@ -127,7 +126,7 @@ public void constructorWhenUsingListOfThenNoException() {
127
126
}
128
127
129
128
@ Test
130
- public void detailsAreNotSetOnAuthenticationTokenIfAlreadySetByProvider () {
129
+ void detailsAreNotSetOnAuthenticationTokenIfAlreadySetByProvider () {
131
130
Object requestDetails = "(Request Details)" ;
132
131
final Object resultDetails = "(Result Details)" ;
133
132
// A provider which sets the details object
@@ -151,7 +150,7 @@ public boolean supports(Class<?> authentication) {
151
150
}
152
151
153
152
@ Test
154
- public void detailsAreSetOnAuthenticationTokenIfNotAlreadySetByProvider () {
153
+ void detailsAreSetOnAuthenticationTokenIfNotAlreadySetByProvider () {
155
154
Object details = new Object ();
156
155
ProviderManager authMgr = makeProviderManager ();
157
156
TestingAuthenticationToken request = createAuthenticationToken ();
@@ -162,16 +161,16 @@ public void detailsAreSetOnAuthenticationTokenIfNotAlreadySetByProvider() {
162
161
}
163
162
164
163
@ Test
165
- public void authenticationExceptionIsIgnoredIfLaterProviderAuthenticates () {
166
- final Authentication authReq = mock (Authentication .class );
164
+ void authenticationExceptionIsIgnoredIfLaterProviderAuthenticates () {
165
+ Authentication authReq = mock (Authentication .class );
167
166
ProviderManager mgr = new ProviderManager (
168
167
createProviderWhichThrows (new BadCredentialsException ("" , new Throwable ())),
169
168
createProviderWhichReturns (authReq ));
170
169
assertThat (mgr .authenticate (mock (Authentication .class ))).isSameAs (authReq );
171
170
}
172
171
173
172
@ Test
174
- public void authenticationExceptionIsRethrownIfNoLaterProviderAuthenticates () {
173
+ void authenticationExceptionIsRethrownIfNoLaterProviderAuthenticates () {
175
174
ProviderManager mgr = new ProviderManager (Arrays
176
175
.asList (createProviderWhichThrows (new BadCredentialsException ("" )), createProviderWhichReturns (null )));
177
176
assertThatExceptionOfType (BadCredentialsException .class )
@@ -180,7 +179,7 @@ public void authenticationExceptionIsRethrownIfNoLaterProviderAuthenticates() {
180
179
181
180
// SEC-546
182
181
@ Test
183
- public void accountStatusExceptionPreventsCallsToSubsequentProviders () {
182
+ void accountStatusExceptionPreventsCallsToSubsequentProviders () {
184
183
AuthenticationProvider iThrowAccountStatusException = createProviderWhichThrows (new AccountStatusException ("" ) {
185
184
});
186
185
AuthenticationProvider otherProvider = mock (AuthenticationProvider .class );
@@ -191,48 +190,47 @@ public void accountStatusExceptionPreventsCallsToSubsequentProviders() {
191
190
}
192
191
193
192
@ Test
194
- public void parentAuthenticationIsUsedIfProvidersDontAuthenticate () {
193
+ void parentAuthenticationIsUsedIfProvidersDontAuthenticate () {
195
194
AuthenticationManager parent = mock (AuthenticationManager .class );
196
195
Authentication authReq = mock (Authentication .class );
197
196
given (parent .authenticate (authReq )).willReturn (authReq );
198
- ProviderManager mgr = new ProviderManager (Collections .singletonList (mock (AuthenticationProvider .class )),
199
- parent );
197
+ ProviderManager mgr = new ProviderManager (List .of (mock (AuthenticationProvider .class )), parent );
200
198
assertThat (mgr .authenticate (authReq )).isSameAs (authReq );
201
199
}
202
200
203
201
@ Test
204
- public void parentIsNotCalledIfAccountStatusExceptionIsThrown () {
202
+ void parentIsNotCalledIfAccountStatusExceptionIsThrown () {
205
203
AuthenticationProvider iThrowAccountStatusException = createProviderWhichThrows (
206
204
new AccountStatusException ("" , new Throwable ()) {
207
205
});
208
206
AuthenticationManager parent = mock (AuthenticationManager .class );
209
- ProviderManager mgr = new ProviderManager (Collections . singletonList (iThrowAccountStatusException ), parent );
207
+ ProviderManager mgr = new ProviderManager (List . of (iThrowAccountStatusException ), parent );
210
208
assertThatExceptionOfType (AccountStatusException .class )
211
209
.isThrownBy (() -> mgr .authenticate (mock (Authentication .class )));
212
210
verifyNoInteractions (parent );
213
211
}
214
212
215
213
@ Test
216
- public void providerNotFoundFromParentIsIgnored () {
214
+ void providerNotFoundFromParentIsIgnored () {
217
215
final Authentication authReq = mock (Authentication .class );
218
216
AuthenticationEventPublisher publisher = mock (AuthenticationEventPublisher .class );
219
217
AuthenticationManager parent = mock (AuthenticationManager .class );
220
218
given (parent .authenticate (authReq )).willThrow (new ProviderNotFoundException ("" ));
221
219
// Set a provider that throws an exception - this is the exception we expect to be
222
220
// propagated
223
- ProviderManager mgr = new ProviderManager (
224
- Collections . singletonList ( createProviderWhichThrows ( new BadCredentialsException ( "" ))), parent );
221
+ ProviderManager mgr = new ProviderManager (List . of ( createProviderWhichThrows ( new BadCredentialsException ( "" ))),
222
+ parent );
225
223
mgr .setAuthenticationEventPublisher (publisher );
226
224
assertThatExceptionOfType (BadCredentialsException .class ).isThrownBy (() -> mgr .authenticate (authReq ))
227
225
.satisfies ((ex ) -> verify (publisher ).publishAuthenticationFailure (ex , authReq ));
228
226
}
229
227
230
228
@ Test
231
- public void authenticationExceptionFromParentOverridesPreviousOnes () {
229
+ void authenticationExceptionFromParentOverridesPreviousOnes () {
232
230
AuthenticationManager parent = mock (AuthenticationManager .class );
233
- ProviderManager mgr = new ProviderManager (
234
- Collections . singletonList ( createProviderWhichThrows ( new BadCredentialsException ( "" ))), parent );
235
- final Authentication authReq = mock (Authentication .class );
231
+ ProviderManager mgr = new ProviderManager (List . of ( createProviderWhichThrows ( new BadCredentialsException ( "" ))),
232
+ parent );
233
+ Authentication authReq = mock (Authentication .class );
236
234
AuthenticationEventPublisher publisher = mock (AuthenticationEventPublisher .class );
237
235
mgr .setAuthenticationEventPublisher (publisher );
238
236
// Set a provider that throws an exception - this is the exception we expect to be
@@ -244,12 +242,11 @@ public void authenticationExceptionFromParentOverridesPreviousOnes() {
244
242
}
245
243
246
244
@ Test
247
- public void statusExceptionIsPublished () {
245
+ void statusExceptionIsPublished () {
248
246
AuthenticationManager parent = mock (AuthenticationManager .class );
249
- final LockedException expected = new LockedException ("" );
250
- ProviderManager mgr = new ProviderManager (Collections .singletonList (createProviderWhichThrows (expected )),
251
- parent );
252
- final Authentication authReq = mock (Authentication .class );
247
+ LockedException expected = new LockedException ("" );
248
+ ProviderManager mgr = new ProviderManager (List .of (createProviderWhichThrows (expected )), parent );
249
+ Authentication authReq = mock (Authentication .class );
253
250
AuthenticationEventPublisher publisher = mock (AuthenticationEventPublisher .class );
254
251
mgr .setAuthenticationEventPublisher (publisher );
255
252
assertThatExceptionOfType (LockedException .class ).isThrownBy (() -> mgr .authenticate (authReq ));
@@ -258,7 +255,7 @@ public void statusExceptionIsPublished() {
258
255
259
256
// SEC-2367
260
257
@ Test
261
- public void providerThrowsInternalAuthenticationServiceException () {
258
+ void providerThrowsInternalAuthenticationServiceException () {
262
259
InternalAuthenticationServiceException expected = new InternalAuthenticationServiceException ("Expected" );
263
260
ProviderManager mgr = new ProviderManager (Arrays .asList (createProviderWhichThrows (expected ),
264
261
createProviderWhichThrows (new BadCredentialsException ("Oops" ))), null );
@@ -269,15 +266,15 @@ public void providerThrowsInternalAuthenticationServiceException() {
269
266
270
267
// gh-6281
271
268
@ Test
272
- public void authenticateWhenFailsInParentAndPublishesThenChildDoesNotPublish () {
269
+ void authenticateWhenFailsInParentAndPublishesThenChildDoesNotPublish () {
273
270
BadCredentialsException badCredentialsExParent = new BadCredentialsException ("Bad Credentials in parent" );
274
271
ProviderManager parentMgr = new ProviderManager (createProviderWhichThrows (badCredentialsExParent ));
275
- ProviderManager childMgr = new ProviderManager (Collections . singletonList (
276
- createProviderWhichThrows (new BadCredentialsException ("Bad Credentials in child" ))), parentMgr );
272
+ ProviderManager childMgr = new ProviderManager (
273
+ List . of ( createProviderWhichThrows (new BadCredentialsException ("Bad Credentials in child" ))), parentMgr );
277
274
AuthenticationEventPublisher publisher = mock (AuthenticationEventPublisher .class );
278
275
parentMgr .setAuthenticationEventPublisher (publisher );
279
276
childMgr .setAuthenticationEventPublisher (publisher );
280
- final Authentication authReq = mock (Authentication .class );
277
+ Authentication authReq = mock (Authentication .class );
281
278
assertThatExceptionOfType (BadCredentialsException .class ).isThrownBy (() -> childMgr .authenticate (authReq ))
282
279
.isSameAs (badCredentialsExParent );
283
280
verify (publisher ).publishAuthenticationFailure (badCredentialsExParent , authReq ); // Parent
0 commit comments