springsecurity 源码解读之 AnonymousAuthenticationFilter
我们知道springsecutity 是通过一系列的 过滤器实现的,我们可以看看这系列的过滤器到底长成什么样子呢?

一堆过滤器,这个过滤器的设计设计上是 责任链设计模式。
这里我们可以看到有一个 AnonymousAuthenticationFilter 过滤器。
顾名思义我们知道这个是一个叫 匿名登录人过滤器,他的作用是什么呢?
我们看看代码 ,他做了什么?
if (applyAnonymousForThisRequest((HttpServletRequest) req)) {
if (SecurityContextHolder.getContext().getAuthentication() == null) {
SecurityContextHolder.getContext().setAuthentication(createAuthentication((HttpServletRequest) req));
if (logger.isDebugEnabled()) {
logger.debug("Populated SecurityContextHolder with anonymous token: '"
+ SecurityContextHolder.getContext().getAuthentication() + "'");
}
} else {
if (logger.isDebugEnabled()) {
logger.debug("SecurityContextHolder not populated with anonymous token, as it already contained: '"
+ SecurityContextHolder.getContext().getAuthentication() + "'");
}
}
}
很简单,当他发现没有登录的时候,手工设置了一个匿名的登录人Authentication。
我们可以在其后的过滤器中,如果没有登录时,我们可以知道当前访问的是匿名用户。
我们可以通过如下代码获取当前人是匿名用户。
Authentication auth= SecurityContextHolder.getContext().getAuthentication();
if (auth==null || "anonymousUser".equals(auth.getPrincipal().toString())) {
springsecurity 源码解读之 AnonymousAuthenticationFilter的更多相关文章
- springsecurity 源码解读之 SecurityContext
在springsecurity 中,我们一般可以通过代码: SecurityContext securityContext = SecurityContextHolder.getContext(); ...
- springsecurity 源码解读 之 RememberMeAuthenticationFilter
RememberMeAuthenticationFilter 的作用很简单,就是用于当session 过期后,系统自动通过读取cookie 让系统自动登录. 我们来看看Springsecurity的过 ...
- SDWebImage源码解读之SDWebImageDownloaderOperation
第七篇 前言 本篇文章主要讲解下载操作的相关知识,SDWebImageDownloaderOperation的主要任务是把一张图片从服务器下载到内存中.下载数据并不难,如何对下载这一系列的任务进行设计 ...
- SDWebImage源码解读 之 NSData+ImageContentType
第一篇 前言 从今天开始,我将开启一段源码解读的旅途了.在这里先暂时不透露具体解读的源码到底是哪些?因为也可能随着解读的进行会更改计划.但能够肯定的是,这一系列之中肯定会有Swift版本的代码. 说说 ...
- SDWebImage源码解读 之 UIImage+GIF
第二篇 前言 本篇是和GIF相关的一个UIImage的分类.主要提供了三个方法: + (UIImage *)sd_animatedGIFNamed:(NSString *)name ----- 根据名 ...
- SDWebImage源码解读 之 SDWebImageCompat
第三篇 前言 本篇主要解读SDWebImage的配置文件.正如compat的定义,该配置文件主要是兼容Apple的其他设备.也许我们真实的开发平台只有一个,但考虑各个平台的兼容性,对于框架有着很重要的 ...
- SDWebImage源码解读_之SDWebImageDecoder
第四篇 前言 首先,我们要弄明白一个问题? 为什么要对UIImage进行解码呢?难道不能直接使用吗? 其实不解码也是可以使用的,假如说我们通过imageNamed:来加载image,系统默认会在主线程 ...
- SDWebImage源码解读之SDWebImageCache(上)
第五篇 前言 本篇主要讲解图片缓存类的知识,虽然只涉及了图片方面的缓存的设计,但思想同样适用于别的方面的设计.在架构上来说,缓存算是存储设计的一部分.我们把各种不同的存储内容按照功能进行切割后,图片缓 ...
- SDWebImage源码解读之SDWebImageCache(下)
第六篇 前言 我们在SDWebImageCache(上)中了解了这个缓存类大概的功能是什么?那么接下来就要看看这些功能是如何实现的? 再次强调,不管是图片的缓存还是其他各种不同形式的缓存,在原理上都极 ...
随机推荐
- VirtualBox虚拟机网络设置说明
1. 网络接入模式简介 VirtualBox的提供了四种网络接入模式,它们分别是: 1.NAT 网络地址转换模式(NAT,Network Address Translation) ...
- 一千行ABAP代码实现Windows传统游戏扫雷
*&---------------------------------------------------------------------* *& Report ZCHENH087 ...
- kdtree HDU5992
STL里面的nth_element()函数 用法:nth_element(first,nth,last) int a[maxn]; nth_element(a,a+k,a+f); 作用:在a到a+f区 ...
- Spring <mvc:default-servlet-handler/>
优雅REST风格的资源URL不希望带 .html 或 .do 等后缀.由于早期的Spring MVC不能很好地处理静态资源,所以在web.xml中配置DispatcherServlet的请求映射,往往 ...
- Flipping an Image
Given a binary matrix A, we want to flip the image horizontally, then invert it, and return the resu ...
- k8s环境清理
每一种方法 #!/bin/shdocker rm -f $(docker ps -qa)docker volume rm $(docker volume ls -q)cleanupdirs=" ...
- centos7修改系统语言
编辑文件:vim /etc/locale.conf LANG="en_US.UTF-8" ##表示为英文 LANG="zh_CN.UTF-8" ## ...
- 提交一个变量或数组到另一个jsp页面
注意一:提交一个变量到另一个jsp页面,用hidden的input 另一个页面用request.getParameter();获取 注意二:提交一个数组到另一个页面,可以用相同的input的n ...
- 解决time_wait过多
需要真正找出问题或瓶颈,但调整单机参数能临时解决:(收集自:https://www.cnblogs.com/dadonggg/p/8778318.html) 编辑内核文件/etc/sysctl.con ...
- 一些matlab命令
expand: R = exprnd(MU) returns an array of random numbers chosen from the exponential distribution w ...