views:

816

answers:

1

Can someone tell me different between an AuthenticationManager and an AuthenticationProvider in spring security?

How are they used and how are they called. It is my understanding that a SecurityFilter will call the AuthenticationManager to authentication an Authentication object? But then where does the AuthenticationProvider come into play?

Thanks!

+1  A: 

I think the AuthenticationManager delegates the fetching of persistent user information to one or more AuthenticationProviders. The authentication-providers (DaoAuthenticationProvider, JaasAuthenticationProvider, LdapAuthenticationProvider, OpenIDAuthenticationProvider for example) specialize in accessing specific user-info repositories. Something else is mentioned in this part of the reference manual. It says:

You may want to register additional AuthenticationProvider beans with the ProviderManager and you can do this using the element with the ref attribute, where the value of the attribute is the name of the provider bean you want to add.

In other words, you can specify multiple AuthenticationProviders, for example one that looks for users in an LDAP database and another that looks in an SQL database.

Hans Westerbeek
So, you would very rarely need to implement a AuthenticationManager, but rather you would just implement AuthenticationProviders to fetch the user details from wherever you want to obtain them from?
jr
Most of the AuthenticationProviders that you could need have already been written by the guys that write Spring Security, and are right there in the API documentation so you can configure them. If the one you need is not in the framework yet, it's probably trivial to implement the AuthenticationProvider interface for your purposes.
Hans Westerbeek