Spring boot Spring安全性:AuthenticationManager.authenticate()执行什么功能

Spring boot Spring安全性:AuthenticationManager.authenticate()执行什么功能,spring-boot,spring-security,Spring Boot,Spring Security,我用JWT研究Spring安全性已经有一段时间了,我注意到在我阅读的每一篇教程中,用户名和密码都会被提取出来,包装在UsernamePasswordAuthenticationToken中,并传递给AuthenticationManager。Authentication()类似这样的内容: @RequestMapping(value = "${jwt.route.authentication.path}", method = RequestMethod.POST) public Response

我用JWT研究Spring安全性已经有一段时间了,我注意到在我阅读的每一篇教程中,用户名和密码都会被提取出来,包装在UsernamePasswordAuthenticationToken中,并传递给AuthenticationManager。Authentication()类似这样的内容:

@RequestMapping(value = "${jwt.route.authentication.path}", method = RequestMethod.POST)
public ResponseEntity<?> createAuthenticationToken(@RequestBody JwtAuthenticationRequest authenticationRequest) throws AuthenticationException {

    authenticationManager.authenticate(new UsernamePasswordAuthenticationToken(authenticationRequest.getUsername(), authenticationRequest.getPassword()));

    // Reload password post-security so we can generate the token
    final UserDetails userDetails = userDetailsService.loadUserByUsername(authenticationRequest.getUsername());
    final String token = jwtTokenUtil.generateToken(userDetails);

    // Return the token
    return ResponseEntity.ok(new JwtAuthenticationResponse(token));
}
@RequestMapping(value=“${jwt.route.authentication.path}”,method=RequestMethod.POST)
public ResponseEntity createAuthenticationToken(@RequestBody JwtAuthenticationRequest authenticationRequest)引发AuthenticationException{
authenticationManager.authenticate(新用户名PasswordAuthenticationToken(authenticationRequest.getUsername(),authenticationRequest.getPassword());
//重新加载密码后安全性,以便生成令牌
final UserDetails UserDetails=userDetailsService.loadUserByUsername(authenticationRequest.getUsername());
最终字符串标记=jwtTokenUtil.generateToken(userDetails);
//归还代币
返回ResponseEntity.ok(新的JwtAuthenticationResponse(令牌));
}
我的问题是,身份验证方法是做什么的,为什么使用它?

来自:

AuthenticationManager只是一个接口,所以实现可以是我们选择的任何东西。(…)Spring Security中的默认实现称为ProviderManager,它不处理身份验证请求本身,而是委托给已配置的AuthenticationProviders列表,然后依次查询每个AuthenticationProviders以查看是否可以执行身份验证。每个提供程序将抛出异常或返回完全填充的身份验证对象