Spring Security 学习(一)认证与授权源码分析——一次痛苦的爬坑经历

一点感悟:

一个疏忽,花了 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 its authenticate() method:

  1. return an Authentication (normally with authenticated=true) if it can verify that the input represents a valid principal.

  2. throw an AuthenticationException if it believes that the input represents an invalid principal.

  3. return null if it can’t decide.

  • 身份认证的主要接口为 Authentication,其中只有一个方法 authenticate,用来验证。
  • 主要干三件事:

             1. 如果能验证是正确的,就返回一个 Authentication 对象,并把 authenticated=true。

             2. 如果没通过验证,则抛出一个异常。

             3. 如果无法判断,则返回 null。


ProviderManager :

The most commonly used implementation of AuthenticationManager is ProviderManager, which delegates to a chain of AuthenticationProvider instances. An AuthenticationProvider is a bit like an AuthenticationManager but it has an extra method to allow the caller to query if it supports

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值