AuthenticationManager和AuthenticationProvider的区别在Spring Security中验证方法

Cor*_*chi 5 spring-security spring-boot

是否有任何区别?

Authentication auth= authenticationManager.authenticate(authentication);
Run Code Online (Sandbox Code Playgroud)

 Authentication auth= authenticationProvider.authenticate(authentication);
Run Code Online (Sandbox Code Playgroud)

Sea*_*uit 13

AuthenticationManager保存AuthenticationProvider实例列表.

当你执行 authenticationManager.authenticate()

实际上这是迭代所有实例AuthenticationProvider并尝试用每个实例验证用户.

默认的spring实现AuthenticationManagerorg.springframework.security.authentication.ProviderManager

实际身份验证在AuthenticationProvider中执行.每个AuthenticationProvider实例都包含UserDetailsService负责从数据库或LDAP中获取用户信息(包括散列密码)的实例.UserDetails成功从数据库中检索 实例后,AuthenticationProvider将使用实例PasswordEncoder来检查密码用户是否提供了与您从数据库中检索的哈希密码.

更多信息,请访问http://docs.spring.io/spring-security/site/docs/2.0.8.RELEASE/apidocs/org/springframework/security/providers/ProviderManager.html

在这里https://docs.spring.io/spring-security/site/docs/current/apidocs/org/springframework/security/authentication/dao/DaoAuthenticationProvider.html