The difference is one way of authentication (DaoAuthenticationProvider) vs opening to more choices (AuthenticationManagerBuilder).
By configuring DaoAuthenticationProvider, means you choose the "Dao"/"userDetailService" to authenticate your users.
Spring Security uses Authentication Manager for Authentication, and ProviderManager is the default authentication manager, which iterates an Authentication request through a list of AuthenticationProviders. And DaoAuthenticationProvider is one of them.
By configuring the authentication manger with method: configure(AuthenticationManagerBuilder Auth)
You have more flexibility, you can configure the authentication manager to use your customized Authentication Provider. (and you CustomAuthenticationProvider implements AuthenticationProvider interface)
@Autowired
private CustomAuthenticationProvider customAuthProvider;
@Override
public void configure(AuthenticationManagerBuilder auth) {
auth.authenticationProvider(customAuthProvider);
}
And you can also configure the DaoAuthenticationProvider by simply provide a userdetailservice, as the AuthenticationManagerBuilder will wire it up.
@Autowired
private CustomUserDetailsService userDetailsService;
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.userDetailsService(userDetailsService).passwordEncoder(passwordEncoder());
}
with that said, using AuthenticationManagerBuilder is much more common, as it can be used for configuring different kinds of authentication providers.