简述
Spring Security为身份验证提供了全面的支持。身份验证是我们验证试图访问特定资源用户身份的方式。认证用户的一种常用方法是要求用户输入用户名和密码。一旦执行了身份验证,我们就知道了访问者并可以执行授权。
体系结构组件
- SecurityContextHolder - 存储身份验证的详细信息的地方。
- SecurityContext - 从SecurityContextHolder获取,并包含当前已验证用户的
Authentication
对象。 - Authentication - 可以从
AuthenticationManager
接口进行身份验证并获取凭证或者从SecurityContext
获取当前用户的凭证。 - GrantedAuthority - 在身份验证中授予主体的权限(即角色、范围等)。
- AuthenticationManager - 定义Spring Security过滤器如何执行身份验证的API。
- ProviderManager - 最常见的
AuthenticationManager
实现。 - AuthenticationProvider -
ProviderManager
用于执行特定类型的身份验证。可以存在多个。 - AuthenticationEntryPoint - 用于发送由客户端请求凭据的HTTP响应(例如,重定向到登录页面,发送WWW-Authenticate响应,等等)。
- AbstractAuthenticationProcessingFilter - 用作对用户凭据进行身份验证的基本过滤器。这也为身份验证的高级流程以及各部分如何协同工作提供了良好的思路。在对凭据进行身份验证之前,Spring Security通常使用AuthenticationEntryPoint请求凭据。
支持的用户认证机制
- Username and Password
- OAuth2
- SAML2
- CAS
- Remember-Me
- JAAS
- OpenID
- X.509
- Pre-Authentication(外部机制验证)