diff --git a/config/src/main/java/org/springframework/security/config/annotation/web/configuration/WebSecurityConfigurerAdapter.java b/config/src/main/java/org/springframework/security/config/annotation/web/configuration/WebSecurityConfigurerAdapter.java index a6cfc7e8a1..69745801cb 100644 --- a/config/src/main/java/org/springframework/security/config/annotation/web/configuration/WebSecurityConfigurerAdapter.java +++ b/config/src/main/java/org/springframework/security/config/annotation/web/configuration/WebSecurityConfigurerAdapter.java @@ -104,29 +104,50 @@ public abstract class WebSecurityConfigurerAdapter implements SecurityConfigurer } /** - * Used by the default implementation of {@link #authenticationManager()} to attempt to obtain an - * {@link AuthenticationManager}. If overridden, the {@link AuthenticationManagerBuilder} should be used to specify - * the {@link AuthenticationManager}. The resulting {@link AuthenticationManager} - * will be exposed as a Bean as will the last populated {@link UserDetailsService} that is created with the - * {@link AuthenticationManagerBuilder}. The {@link UserDetailsService} will also automatically be populated on - * {@link HttpSecurity#getSharedObject(Class)} for use with other {@link SecurityContextConfigurer} - * (i.e. RememberMeConfigurer ) + * Used by the default implementation of {@link #authenticationManager()} to + * attempt to obtain an {@link AuthenticationManager}. If overridden, the + * {@link AuthenticationManagerBuilder} should be used to specify the + * {@link AuthenticationManager}. * - *
For example, the following configuration could be used to register - * in memory authentication that exposes an in memory {@link UserDetailsService}:
+ *+ * The {@link #authenticationManagerBean()} method can be used to expose the + * resulting {@link AuthenticationManager} as a Bean. The + * {@link #userDetailsServiceBean()} can be used to expose the last + * populated {@link UserDetailsService} that is created with the + * {@link AuthenticationManagerBuilder} as a Bean. The + * {@link UserDetailsService} will also automatically be populated on + * {@link HttpSecurity#getSharedObject(Class)} for use with other + * {@link SecurityContextConfigurer} (i.e. RememberMeConfigurer ) + *
+ * + *+ * For example, the following configuration could be used to register in + * memory authentication that exposes an in memory + * {@link UserDetailsService}: + *
* ** @Override * protected void registerAuthentication(AuthenticationManagerBuilder auth) { * auth - * // enable in memory based authentication with a user named "user" and "admin" + * // enable in memory based authentication with a user named + * // "user" and "admin" * .inMemoryAuthentication() - * .withUser("user").password("password").roles("USER").and() - * .withUser("admin").password("password").roles("USER", "ADMIN"); + * .withUser("user").password("password").roles("USER").and() + * .withUser("admin").password("password").roles("USER", "ADMIN"); * } + * + * // Expose the UserDetailsService as a Bean + * @Bean + * @Override + * public UserDetailsService userDetailsServiceBean() throws Exception { + * return super.userDetailsServiceBean(); + * } + * ** - * @param auth the {@link AuthenticationManagerBuilder} to use + * @param auth + * the {@link AuthenticationManagerBuilder} to use * @throws Exception */ protected void registerAuthentication(AuthenticationManagerBuilder auth) throws Exception {