Spring Security 学习笔记-securityContext过滤器

位于过滤器顶端,第一个起作用的过滤器。SecurityContextPersistenceFilter

在执行其他过滤器之前,率先判断用户的session中是否已经存在一个SecurityContext了。如果存在,就把SecurityContext拿出来,放到SecurityContextHolder中,供Spring Security的其他部分使用。如果不存在,就创建一个SecurityContext出来,还是放到SecurityContextHolder中,供Spring Security的其他部分使用。

过滤链执行完成后如果session尚未保存SecurityContext,则repo.saveContext(contextAfterChainExecution, holder.getRequest(), holder.getResponse());方法调用SaveContextOnUpdateOrErrorResponseWrapper类中的responseWrapper.saveContext(context)进行保存。这个保存可能是response没有提交前。

原文地址:https://www.cnblogs.com/mingluosunshan/p/5329037.html