What are AuthenticationManager and ProviderManager in Spring Security?

AuthenticationManager is the core interface Spring Security calls to authenticate a request, and ProviderManager is its default implementation, which delegates the actual credential check to one or more AuthenticationProvider instances until one succeeds.

Key Points

Example

An application configures both a DaoAuthenticationProvider (checking a database) and an LdapAuthenticationProvider; ProviderManager tries each in turn until one successfully authenticates the user.

@Bean
AuthenticationManager authenticationManager(UserDetailsService users,
                                            PasswordEncoder encoder,
                                            LdapAuthenticator ldapAuthenticator) {
    DaoAuthenticationProvider database = new DaoAuthenticationProvider();
    database.setUserDetailsService(users);
    database.setPasswordEncoder(encoder);

    LdapAuthenticationProvider ldap = new LdapAuthenticationProvider(ldapAuthenticator);

    // ProviderManager asks each provider in turn until one authenticates the user
    return new ProviderManager(List.of(database, ldap));
}

// Using it directly, e.g. in a custom login endpoint
Authentication result = authenticationManager.authenticate(
        UsernamePasswordAuthenticationToken.unauthenticated(username, password));

Interview Tip

A concise interview answer is

AuthenticationManager is the interface Spring Security calls to authenticate a request, and ProviderManager is its standard implementation that delegates to a chain of AuthenticationProviders, trying each one until it finds one that can handle and validate the credentials. This lets you plug in multiple authentication sources like database and LDAP side by side.

Last updated: 11 November 2026

Previous question: How can you use Spring Expression Language (SpEL) for fine-grained access control?

Next question: When a user tries to access a resource without the necessary permissions, you want to redirect them to a custom "access denied" page instead of displaying the default Spring Security error message. How would you achieve this in your Spring Security configuration?

More Spring Security - Level I interview questions

All Spring Security - Level I questions