Spring Security 6.4 引入了一项新的安全特性 —— 一次性令牌登录(One-Time Token Login)。这种登录方式允许用户通过邮件接收一个魔法链接(Magic Link)来完成身份验证,无需传统的用户名和密码组合。这种方式不仅提升了用户体验,还增强了系统的安全性。
比如笔者上篇文章提到的 mintlify 文档工具,默认提供的就是这种方式。
1.1 登录流程图
1 2 3 4 5 6 7 8 9 10 11 12 13 14
sequenceDiagram participant User participant System participant EmailService
User->>System: 提交邮箱 System->>EmailService: 生成并发送魔法链接 EmailService->>User: 发送含链接邮件 User->>System: 点击魔法链接 alt 验证成功 System->>User: 登录成功 else 验证失败 System->>User: 显示错误提示 end
1.2 技术架构图
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
graph TB A[用户界面] --> B[Spring Security过滤器链] B --> C[OneTimeTokenAuthenticationFilter] C --> D[OneTimeTokenRepository] C --> E[UserDetailsService] D --> F[(令牌存储)] E --> G[(用户数据库)]
style A fill:#f9f,stroke:#333,stroke-width:2px style B fill:#bbf,stroke:#333,stroke-width:2px style C fill:#dfd,stroke:#333,stroke-width:2px style D fill:#dfd,stroke:#333,stroke-width:2px style E fill:#dfd,stroke:#333,stroke-width:2px style F fill:#fdd,stroke:#333,stroke-width:2px style G fill:#fdd,stroke:#333,stroke-width:2px