【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>>
注:下面分析的版本是spring-security-4.2.x,源码的github地址是: https://github.com/spring-projects/spring-security/tree/4.2.x
先上一张图:
图1 SecurityContextHolderStrategy的三个实现类
1. ThreadLocalSecurityContextHolderStrategy
它里面使用的是ThreadLocal,如下List-1所示:
List-1
private static final ThreadLocal<SecurityContext> contextHolder = new ThreadLocal<SecurityContext>();
2.InheritableThreadLocalSecurityContextHolderStrategy
它里面使用的是InheritableThreadLocal,如下List-2所示:
List-2
private static final ThreadLocal<SecurityContext> contextHolder = new InheritableThreadLocal<SecurityContext>();
ThreadLocal和InheritableThreadLocal之间是有区别的,InheritableThreadLocal的作用更广,这里就不再深入。
3.GlobalSecurityContextHolderStrategy
它里面使用的是静态属性,如下List-3所示:
List-3
private static SecurityContext contextHolder;
来源:oschina
链接:https://my.oschina.net/u/2518341/blog/1930186