一点感悟:
一个疏忽,花了 5h 解决了,哎。用一首歌来表达一下现在的心情:点击。
不过也算摸清了Spring Security 一点基本原理,没有白费的时间......
学习新知识的时候,遇到解决不了的问题一定不能心急,越是这个时候越要静下心来一步一步的去分析原理。静心、沉淀。
一、认证过程 :
废话不多说,在学习之前最好先把用到的英语单词熟悉一下。 AuthenticationManager(认证管理器接口),authenticate(认证的方法),ProviderManager,AuthenticationManager
官方文档:https://spring.io/guides/topicals/spring-security-architecture/
先来了解一下以下几个接口,方便后面的学习。
AuthenticationManager :
Authentication
The main strategy interface for authentication is
AuthenticationManager
which only has one method:public interface AuthenticationManager { Authentication authenticate(Authentication authentication) throws AuthenticationException; }
An
AuthenticationManager
can do one of 3 things in itsauthenticate()
method:
return an
Authentication
(normally withauthenticated=true
) if it can verify that the input represents a valid principal.throw an
AuthenticationException
if it believes that the input represents an invalid principal.return
null
if it can’t decide.
- 身份认证的主要接口为 Authentication,其中只有一个方法 authenticate,用来验证。
- 主要干三件事:
1. 如果能验证是正确的,就返回一个 Authentication 对象,并把 authenticated=true。
2. 如果没通过验证,则抛出一个异常。
3. 如果无法判断,则返回 null。
ProviderManager :
The most commonly used implementation of
AuthenticationManager
isProviderManager
, which delegates to a chain ofAuthenticationProvider
instances. AnAuthenticationProvider
is a bit like anAuthenticationManager
but it has an extra method to allow the caller to query if it supports