title: How Spring Security add/configure AuthenticationManagerBuilder?
body: <p>I am working on Spring Security Java-based configuration.</p>
  
  <p>I have created my own <code>MyAuthenticationProvider</code> which I want to register in the <code>ProviderManager</code> (single instance of <code>AuthenticationManager</code>).</p>
  
  <p>I have found that <code>ProviderManager</code> has a list of providers to which I can register my single 
  <code>MyAuthenticationProvider</code>.</p>
  
  <p>Here is the part of my Configuration:</p>
  
  <pre><code>@Configuration
  @EnableWebSecurity
  public class SecurityConfig extends WebSecurityConfigurerAdapter {
  
      @Autowired
      public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
          auth.authenticationProvider(MyAuthenticationProvider);
      }
  }
  </code></pre>
  
  <p>I found out that <code>AuthenticationManagerBuilder</code> has <code>parentAuthenticationManager</code>, <code>defaultUserDetailsService</code> and many other fields.</p>
  
  <p>My questions are:</p>
  
  <ol>
  <li>Where is this <code>@Autowired</code> annotation adding <code>AuthenticationManagerBuilder</code> auth from? 
  Is the <code>AuthenticationManagerBuilder</code> already created in the application context?</li>
  <li>What would be the default state of <code>AuthenticationManagerBuilder</code> which is being        injected? By default state I mean will there be some <code>parentAuthenticationManager</code>, <code>authenticationProvider</code>s already registered in the <code>AuthenticationManagerBuilder</code>?</li>
  <li>If I am adding <code>auth.authenticationProvider(MyAuthenticationProvider)</code>, does this mean that I am adding one more provider in the <code>AuthenticationManagerBuilder</code>?</li>
  <li><p>What does this mean? Taken from Spring Documentation</p>
  
  <blockquote>
    <p>The name of the configureGlobal method is not important. However, it
    is important to only configure AuthenticationManagerBuilder in a class
    annotated with either @EnableWebSecurity, @EnableWebMvcSecurity,
    @EnableGlobalMethodSecurity, or @EnableGlobalAuthentication. Doing
    otherwise has unpredictable results.</p>
  </blockquote></li>
  </ol>