spring security AuthenticationManager vs AuthenticationProvider?

前端 未结 3 1690
鱼传尺愫
鱼传尺愫 2021-01-30 10:03

Can someone tell me the difference between an AuthenticationManager and an AuthenticationProvider in Spring Security?

How are they used and how

3条回答
  •  無奈伤痛
    2021-01-30 10:46

    From spring reference

    The AuthenticationManager is just an interface, so the implementation can be anything we choose

    The default implementation in Spring Security is called ProviderManager and rather than handling the authentication request itself, it delegates to a list of configured AuthenticationProvider s, each of which is queried in turn to see if it can perform the authentication. Each provider will either throw an exception or return a fully populated Authentication object.

    Also if you check the source code for AuthenticationManager, ProviderManager and AuthenticationProvider you can see this clearly.

    ProviderManager implements the AuthenticationManager interface and it has list of AuthenticationProviders. So if you want to have custom authentication mechanism, you'll need to implement new AuthenticationProvider.

提交回复
热议问题