UsernamePasswordAuthenticationFilter
当我们发起登录请求,首先会进入该过滤器, 主要是用来获取表单提交信息,默认参数名是username和password,这些是可以修改的。
当我们在自定义页面时,会继承WebSecurityConfigurerAdapter来通过重写方法来进行security的配置,其中formLogin可以配置。
进入formLogin,可以看到该方法返回了一个FormLoginConfigurer,接着进入
这时可以看到我们的一些配置在该类又有对应的方法来处理,其中usernameParameter,passwordParameter和方法返回的是UsernamePasswordAuthenticationFilter过滤器,也就是说在这一步我们将自己配置的表单参数名传递给了UsernamePasswordAuthenticationFilter过滤器。
接着看源码
public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response) throws AuthenticationException {
if (this.postOnly && !request.getMethod().equals("POST")) {
throw new AuthenticationServiceException("Authentication method not supported: " + request.getMethod());
} else {
String username = this.obtainUsername(request);
username = username != null ? username : "";
username = username.trim();
String password = this.obtainPassword(request);
password = password != null