You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/modules/ROOT/pages/servlet/authentication/passwords/index.adoc
+81-91
Original file line number
Diff line number
Diff line change
@@ -326,10 +326,74 @@ Normally, Spring Security builds an `AuthenticationManager` internally composed
326
326
In certain cases, it may still be desired to customize the instance of `AuthenticationManager` used by Spring Security.
327
327
For example, you may need to simply disable xref:servlet/authentication/architecture.adoc#servlet-authentication-providermanager-erasing-credentials[credential erasure] for cached users.
328
328
329
-
The recommended way to do this is to simply publish your own `AuthenticationManager` bean, and Spring Security will use it.
330
-
You can publish an `AuthenticationManager` using the following configuration:
329
+
To do this, you can take advantage of the fact that the `AuthenticationManagerBuilder` used to build Spring Security's global `AuthenticationManager` is published as a bean.
330
+
You can configure the builder as follows:
331
+
332
+
.Configure global `AuthenticationManagerBuilder`
333
+
[tabs]
334
+
=====
335
+
Java::
336
+
+
337
+
[source,java,role="primary"]
338
+
----
339
+
@Configuration
340
+
@EnableWebSecurity
341
+
public class SecurityConfig {
342
+
343
+
@Bean
344
+
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
345
+
// ...
346
+
return http.build();
347
+
}
348
+
349
+
@Bean
350
+
public UserDetailsService userDetailsService() {
351
+
// Return a UserDetailsService that caches users
352
+
// ...
353
+
}
354
+
355
+
@Autowired
356
+
public void configure(AuthenticationManagerBuilder builder) {
Alternatively, you can take advantage of the fact that the `AuthenticationManagerBuilder` used to build Spring Security's global `AuthenticationManager` is published as a bean.
479
-
You can configure the builder as follows:
480
-
481
-
.Configure global `AuthenticationManagerBuilder`
482
-
[tabs]
483
-
=====
484
-
Java::
485
-
+
486
-
[source,java,role="primary"]
487
-
----
488
-
@Configuration
489
-
@EnableWebSecurity
490
-
public class SecurityConfig {
491
-
492
-
@Bean
493
-
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
494
-
// ...
495
-
return http.build();
496
-
}
497
-
498
-
@Bean
499
-
public UserDetailsService userDetailsService() {
500
-
// Return a UserDetailsService that caches users
501
-
// ...
502
-
}
503
-
504
-
@Autowired
505
-
public void configure(AuthenticationManagerBuilder builder) {
0 commit comments