springboot 登陆实现源代码解析

springboot 能够使用springsecurity 做为安全框架,咱们能够使用springsecurity 实现安全登陆。spring

springsecurity 是使用一系列的过滤器来实现安全的。安全

实现用户登陆使用的是:springboot

UsernamePasswordAuthenticationFilter过滤器来实现。框架

他在过滤器链中的位置以下:spa

这个代码的实现逻辑是:3d

1.拦截地址为 /login的URL。code

2.若是地址栏的地址为login 则进行以后的逻辑处理,不然跳过。blog

3.验证用户接口

这个attemptAuthentication方法由 UsernamePasswordAuthenticationFilter 实现,在上下文中获取 用户名和密码。it

从上面的代码咱们能够看出,代码经过 AuthenticationManager 获取用户接口获取信息。

当成功时:

执行上面都代码:

1.设置上下文

2.处理记住密码登陆成功消息。

3.调用自定义成功处理器。

当失败时:

失败处理接口

public interface AuthenticationFailureHandler {
    void onAuthenticationFailure(HttpServletRequest var1, HttpServletResponse var2, AuthenticationException var3) throws IOException, ServletException;
}
相关文章
相关标签/搜索