zoukankan      html  css  js  c++  java
  • springboot 登录实现源代码解析

    springboot 可以使用springsecurity 作为安全框架,我们可以使用springsecurity 实现安全登录。

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

    实现用户登录使用的是:

    UsernamePasswordAuthenticationFilter过滤器来实现。

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

    这个代码的实现逻辑是:

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

    2.如果地址栏的地址为login 则进行之后的逻辑处理,否则跳过。

    3.验证用户

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

    从上面的代码我们可以看出,代码通过 AuthenticationManager 获取用户接口获取信息。

    当成功时:

    执行上面都代码:

    1.设置上下文

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

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

    当失败时:

    失败处理接口

    public interface AuthenticationFailureHandler {
        void onAuthenticationFailure(HttpServletRequest var1, HttpServletResponse var2, AuthenticationException var3) throws IOException, ServletException;
    }
  • 相关阅读:
    代码走读 airflow 2
    sql 查询相关
    控制你的鼠标和键盘
    TODO
    二进制流的操作收集
    daterangepicker-双日历
    datetimepicker使用
    ADO执行事务
    动态添加表sql
    执行带返回值的存储过程
  • 原文地址:https://www.cnblogs.com/yg_zhang/p/10993375.html
Copyright © 2011-2022 走看看