Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
if (authentication != null)
return (T) authentication.getPrincipal();
SecurityContextHolder.getContext()中获取上下文,有三种策略
默认使用ThreadLocalSecurityContextHolderStrategy方式
ThreadLocalSecurityContextHolderStrategy中
使用SecurityContext类型的threadlocl保存SecurityContext上下文。
ThreadLocal具有线程隔离的效果,只有在线程内才能获取到对应的SecurityContext。