title: Spring Security: Can other beans access the global AuthenticationManagerBuilder?
body: <p>I have set up the boilerplate spring security Configurer:</p>
  
  <pre><code>public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
  
  
  @Autowired
  private DataSource datasource;
  
  @Override
  protected void configure(HttpSecurity http) throws Exception {
     // ...setting up security for routes, etc.
  }
  
  @Override
  protected void configure(AuthenticationManagerBuilder auth) throws Exception { 
        // here I have access to the AuthenticationManagerBuilder
        // I can associate it with my datasource, set the password encoder, etc.
   JdbcUserDetailsManager userDetailsService = new   JdbcUserDetailsManager();
      userDetailsService.setDataSource(datasource);
      PasswordEncoder encoder = new BCryptPasswordEncoder();
  auth.userDetailsService(userDetailsService).passwordEncoder(encoder);
      auth.jdbcAuthentication().dataSource(datasource);
  
  }
  </code></pre>
  
  <p>But what I want is to be able to access that AuthenticationManagerBuilder from another bean like this: </p>
  
  <pre><code>@Service
  public class MyUserService {
  
  @Autowired
  AuthenticationManagerBuilder builder; 
  
  public void createUser(...) {
  //use builder here...
      JdbcUserDetailsManager userDetailsService = new JdbcUserDetailsManager();
      userDetailsService.setDataSource(datasource);
      PasswordEncoder encoder = new BCryptPasswordEncoder();
      builder.userDetailsService(userDetailsService)
        .passwordEncoder(encoder);
      builder.jdbcAuthentication().dataSource(datasource);
      userDetailsService.createUser(new User(...));
  }
  </code></pre>
  
  <p>Is there any way to access from other beans the same <code>AuthenticationManagerBuilder</code> instance that is automatically passed to the <code>configure()</code> method?</p>