|
@@ -1,7 +1,7 @@
|
|
|
## JWT登录流程
|
|
|
|
|
|
后端jwt目录
|
|
|
-
|
|
|
+
|
|
|
|
|
|
### 1.首先进入 JwtLoginFilter 类中
|
|
|
|
|
@@ -16,16 +16,16 @@
|
|
|
#### 1.1 UsernamePasswordAuthenticationFilter [源码](https://blog.csdn.net/m0_51945027/article/details/119608165)
|
|
|
|
|
|
该类继承抽象认证处理器类,作用是处理身份验证的表单提交,并在这个类的构造函数指定了拦截路径,可以给他指定登陆路径。
|
|
|
-
|
|
|
+
|
|
|
|
|
|
#### 1.2 attemptAuthentication
|
|
|
|
|
|
-
|
|
|
+
|
|
|
在 JwtLoginFilter 中,通过 attemptAuthentication() 方法来获取表单中的用户名和密码,封装进 ArrayList 数组中,并通过 authentication() 方法(即authenticationManager.authenticate())来认证。
|
|
|
|
|
|
#### 1.3 attemptAuthentication() 工作流程
|
|
|
|
|
|
-
|
|
|
+
|
|
|
过程:所有的认证请求(比如login)都会通过提交一个 token 给 AuthenticationManager 的 authenticate() 方法来实现。当然事情肯定不是它来做,具体校验动作会由 AuthenticationManager 将请求转发给具体的实现类来做。
|
|
|
|
|
|
+ 先通过 req.getContentType() 方法获取获取请求头信息中 Content-Type 字段的值,判空
|
|
@@ -38,7 +38,7 @@
|
|
|
#### 1.5 [Authentication核心组件](https://zhuanlan.zhihu.com/p/85489737)
|
|
|
|
|
|
createAuthentication,token打印后:
|
|
|
-
|
|
|
+
|
|
|
|
|
|
createToken()方法使用了构建器模式(Jwt.builder().build())
|
|
|
|