第十三章 Basic Authentication
Basic 认证和 Digest 认证是 web 应用中常用的两种认证机制。
一、Basic Authentication
Basic Authentication 通常用于无状态客户机,无状态客户机在每个请求上,传递其凭据。它与基于表单的身份验证结合使用是非常常见的。
Basic Authentication 会将密码使用纯文本的形式传输,因此只能在加密的传输层(如HTTPS)上使用密码。
1. BasicAuthenticationFilter
BasicAuthenticationFilter 负责处理 HTTP 头中提供的基本身份验证凭据。基本身份验证被广泛部署在用户代理中,并且实现非常简单。认证格式类似于:https://zhangsan:123456@www.luokaiii.cn/login
2. Configuration
配置的 AuthenticationManager 处理每个身份验证请去,如果身份验证失败,将使用 AuthenticationEntryPoint 重试身份验证过程。通常需要结合使用过滤器和 BasicAuthenticationEntryPoint,返回一个带有401 Header的响应来重试 HTTP Basic 身份验证。
如果身份验证成功,则生成 Authentication 对象并放入 SecurityContextHolder 中。
二、Digest Authentication
Digest Authentication 试图解决 Basic Authentication 中存在的许多缺陷和弱点,特别是以明文形式发送凭据。
You should not use Digest in modern applications because it is not considered secure.
翻译:你不应该在现代应用中使用 Digest,因为它是不安全的。
so,这里就不写了。详见 digest-processing-filter。