title: Provider order using AuthenticationManagerBuilder
body: <p>I'm using Spring Security 4.0.1 and want to use multiple authentication providers for authentication using Java-based configuration. How do I specify the provider order?</p>
  
  <p>I was hoping to use <a href="http://docs.spring.io/autorepo/docs/spring-security/current/apidocs/org/springframework/security/config/annotation/authentication/builders/AuthenticationManagerBuilder.html" rel="noreferrer">AuthenticationManagerBuilder</a>, since that's what <code>WebSecurityConfigurerAdapter.configureGlobal()</code> exposes, but I don't see any way to specify the order. Do I need to create a <a href="http://docs.spring.io/spring-security/site/docs/current/apidocs/org/springframework/security/authentication/ProviderManager.html" rel="noreferrer">ProviderManager</a> manually?</p>
  
  <p><strong>Update:</strong> Here's a problem clarification based on Arun's answer. The specific providers I want to use are <code>ActiveDirectoryLdapAuthenticationProvider</code> and <code>DaoAuthenticationProvider</code> for a custom <code>UserService</code>.</p>
  
  <p>Ultimately I'd like to authenticate against the <code>DaoAuthenticationProvider</code> first and the <code>ActiveDirectoryLdapAuthenticationProvider</code> second.</p>
  
  <p>The AD provider involves a call to <code>AuthenticationManagerBuilder.authenticationProvider()</code> but the DAO provider involves calling <code>AuthenticationManagerBuilder.userService()</code>, which creates a <code>DaoAuthenticationProvider</code> around the user service behind the scenes. Looking at the source code, it doesn't directly place a provider in the provider list (it creates a configurer), so Arun's answer isn't working for me here.</p>
  
  <p>I tried creating the <code>DaoAuthenticationProvider</code> manually and passing it to <code>authenticationProvider()</code>. It didn't impact the order.</p>