1
1
/*
2
- * Copyright 2002-2019 the original author or authors.
2
+ * Copyright 2002-2022 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
33
33
import org .springframework .ldap .core .support .BaseLdapPathContextSource ;
34
34
import org .springframework .security .authentication .AuthenticationManager ;
35
35
import org .springframework .security .config .annotation .authentication .builders .AuthenticationManagerBuilder ;
36
+ import org .springframework .security .config .annotation .authentication .configuration .AuthenticationConfiguration ;
36
37
import org .springframework .security .config .annotation .authentication .configuration .EnableGlobalAuthentication ;
37
38
import org .springframework .security .config .annotation .configuration .ObjectPostProcessorConfiguration ;
38
39
import org .springframework .security .config .annotation .web .configuration .EnableWebSecurity ;
39
- import org .springframework .security .config .annotation .web .configuration .WebSecurityConfigurerAdapter ;
40
40
import org .springframework .security .config .test .SpringTestContext ;
41
41
import org .springframework .security .config .test .SpringTestContextExtension ;
42
42
import org .springframework .security .core .authority .SimpleGrantedAuthority ;
@@ -70,7 +70,6 @@ public class LdapAuthenticationProviderBuilderSecurityBuilderTests {
70
70
public void defaultConfiguration () {
71
71
this .spring .register (DefaultLdapConfig .class ).autowire ();
72
72
LdapAuthenticationProvider provider = ldapProvider ();
73
-
74
73
LdapAuthoritiesPopulator authoritiesPopulator = getAuthoritiesPopulator (provider );
75
74
assertThat (authoritiesPopulator ).hasFieldOrPropertyWithValue ("groupRoleAttribute" , "cn" );
76
75
assertThat (authoritiesPopulator ).hasFieldOrPropertyWithValue ("groupSearchBase" , "" );
@@ -160,8 +159,8 @@ static int getPort() throws IOException {
160
159
@ EnableWebSecurity
161
160
static class DefaultLdapConfig extends BaseLdapProviderConfig {
162
161
163
- @ Override
164
- protected void configure (AuthenticationManagerBuilder auth ) throws Exception {
162
+ @ Autowired
163
+ void configure (AuthenticationManagerBuilder auth ) throws Exception {
165
164
// @formatter:off
166
165
auth
167
166
.ldapAuthentication ()
@@ -170,14 +169,20 @@ protected void configure(AuthenticationManagerBuilder auth) throws Exception {
170
169
// @formatter:on
171
170
}
172
171
172
+ @ Bean
173
+ AuthenticationManager authenticationManager (AuthenticationConfiguration authenticationConfiguration )
174
+ throws Exception {
175
+ return authenticationConfiguration .getAuthenticationManager ();
176
+ }
177
+
173
178
}
174
179
175
180
@ Configuration
176
181
@ EnableWebSecurity
177
182
static class GroupRolesConfig extends BaseLdapProviderConfig {
178
183
179
- @ Override
180
- protected void configure (AuthenticationManagerBuilder auth ) throws Exception {
184
+ @ Autowired
185
+ void configure (AuthenticationManagerBuilder auth ) throws Exception {
181
186
// @formatter:off
182
187
auth
183
188
.ldapAuthentication ()
@@ -187,14 +192,20 @@ protected void configure(AuthenticationManagerBuilder auth) throws Exception {
187
192
// @formatter:on
188
193
}
189
194
195
+ @ Bean
196
+ AuthenticationManager authenticationManager (AuthenticationConfiguration authenticationConfiguration )
197
+ throws Exception {
198
+ return authenticationConfiguration .getAuthenticationManager ();
199
+ }
200
+
190
201
}
191
202
192
203
@ Configuration
193
204
@ EnableWebSecurity
194
205
static class GroupSearchConfig extends BaseLdapProviderConfig {
195
206
196
- @ Override
197
- protected void configure (AuthenticationManagerBuilder auth ) throws Exception {
207
+ @ Autowired
208
+ void configure (AuthenticationManagerBuilder auth ) throws Exception {
198
209
// @formatter:off
199
210
auth
200
211
.ldapAuthentication ()
@@ -204,14 +215,20 @@ protected void configure(AuthenticationManagerBuilder auth) throws Exception {
204
215
// @formatter:on
205
216
}
206
217
218
+ @ Bean
219
+ AuthenticationManager authenticationManager (AuthenticationConfiguration authenticationConfiguration )
220
+ throws Exception {
221
+ return authenticationConfiguration .getAuthenticationManager ();
222
+ }
223
+
207
224
}
208
225
209
226
@ Configuration
210
227
@ EnableWebSecurity
211
228
static class GroupSubtreeSearchConfig extends BaseLdapProviderConfig {
212
229
213
- @ Override
214
- protected void configure (AuthenticationManagerBuilder auth ) throws Exception {
230
+ @ Autowired
231
+ void configure (AuthenticationManagerBuilder auth ) throws Exception {
215
232
// @formatter:off
216
233
auth
217
234
.ldapAuthentication ()
@@ -222,14 +239,20 @@ protected void configure(AuthenticationManagerBuilder auth) throws Exception {
222
239
// @formatter:on
223
240
}
224
241
242
+ @ Bean
243
+ AuthenticationManager authenticationManager (AuthenticationConfiguration authenticationConfiguration )
244
+ throws Exception {
245
+ return authenticationConfiguration .getAuthenticationManager ();
246
+ }
247
+
225
248
}
226
249
227
250
@ Configuration
228
251
@ EnableWebSecurity
229
252
static class RolePrefixConfig extends BaseLdapProviderConfig {
230
253
231
- @ Override
232
- protected void configure (AuthenticationManagerBuilder auth ) throws Exception {
254
+ @ Autowired
255
+ void configure (AuthenticationManagerBuilder auth ) throws Exception {
233
256
// @formatter:off
234
257
auth
235
258
.ldapAuthentication ()
@@ -239,14 +262,20 @@ protected void configure(AuthenticationManagerBuilder auth) throws Exception {
239
262
// @formatter:on
240
263
}
241
264
265
+ @ Bean
266
+ AuthenticationManager authenticationManager (AuthenticationConfiguration authenticationConfiguration )
267
+ throws Exception {
268
+ return authenticationConfiguration .getAuthenticationManager ();
269
+ }
270
+
242
271
}
243
272
244
273
@ Configuration
245
274
@ EnableWebSecurity
246
275
static class BindAuthenticationConfig extends BaseLdapServerConfig {
247
276
248
- @ Override
249
- protected void configure (AuthenticationManagerBuilder auth ) throws Exception {
277
+ @ Autowired
278
+ void configure (AuthenticationManagerBuilder auth ) throws Exception {
250
279
// @formatter:off
251
280
auth
252
281
.ldapAuthentication ()
@@ -257,14 +286,20 @@ protected void configure(AuthenticationManagerBuilder auth) throws Exception {
257
286
// @formatter:on
258
287
}
259
288
289
+ @ Bean
290
+ AuthenticationManager authenticationManager (AuthenticationConfiguration authenticationConfiguration )
291
+ throws Exception {
292
+ return authenticationConfiguration .getAuthenticationManager ();
293
+ }
294
+
260
295
}
261
296
262
297
@ Configuration
263
298
@ EnableWebSecurity
264
299
static class PasswordEncoderConfig extends BaseLdapServerConfig {
265
300
266
- @ Override
267
- protected void configure (AuthenticationManagerBuilder auth ) throws Exception {
301
+ @ Autowired
302
+ void configure (AuthenticationManagerBuilder auth ) throws Exception {
268
303
// @formatter:off
269
304
auth
270
305
.ldapAuthentication ()
@@ -276,6 +311,12 @@ protected void configure(AuthenticationManagerBuilder auth) throws Exception {
276
311
// @formatter:on
277
312
}
278
313
314
+ @ Bean
315
+ AuthenticationManager authenticationManager (AuthenticationConfiguration authenticationConfiguration )
316
+ throws Exception {
317
+ return authenticationConfiguration .getAuthenticationManager ();
318
+ }
319
+
279
320
}
280
321
281
322
@ Configuration
@@ -296,7 +337,7 @@ ApacheDSContainer ldapServer() throws Exception {
296
337
@ EnableWebSecurity
297
338
@ EnableGlobalAuthentication
298
339
@ Import (ObjectPostProcessorConfiguration .class )
299
- abstract static class BaseLdapProviderConfig extends WebSecurityConfigurerAdapter {
340
+ abstract static class BaseLdapProviderConfig {
300
341
301
342
@ Bean
302
343
BaseLdapPathContextSource contextSource () throws Exception {
@@ -308,15 +349,6 @@ BaseLdapPathContextSource contextSource() throws Exception {
308
349
return contextSource ;
309
350
}
310
351
311
- @ Bean
312
- AuthenticationManager authenticationManager (AuthenticationManagerBuilder auth ) throws Exception {
313
- configure (auth );
314
- return auth .build ();
315
- }
316
-
317
- @ Override
318
- protected abstract void configure (AuthenticationManagerBuilder auth ) throws Exception ;
319
-
320
352
}
321
353
322
354
}
0 commit comments