Spring security 使用JWT时在SecurityContext中设置身份验证

Spring security 使用JWT时在SecurityContext中设置身份验证,spring-security,Spring Security,我对我的服务器使用Spring引导安全性。 在将jwt save Authentication对象验证到SecurityContext中之后,我添加了新的过滤器,该过滤器从OncePerRequestFilter扩展而来,并根据web上的许多教程进行了扩展。 我不明白的是,为什么我需要在SecurityContext中保存身份验证?毕竟,我在每个请求中都从客户机验证jwt,不需要spring在身份验证对象上调用isAuthenticated。 我错过什么了吗 Spring安全认证基本上是通过将其

我对我的服务器使用Spring引导安全性。 在将jwt save Authentication对象验证到SecurityContext中之后,我添加了新的过滤器,该过滤器从OncePerRequestFilter扩展而来,并根据web上的许多教程进行了扩展。 我不明白的是,为什么我需要在SecurityContext中保存身份验证?毕竟,我在每个请求中都从客户机验证jwt,不需要spring在身份验证对象上调用isAuthenticated。
我错过什么了吗

Spring安全认证基本上是通过将其存储在SecurityContext中来工作的。有一个SecurityContextHolder类存储SecurityContext,用于许多需要通过检索身份验证来做出身份验证/授权决策的地方。即使您已经验证了JWT以检查身份验证是否成功,Spring Security仍然需要身份验证对象来做出其他决定,例如评估hasRole、hasAnyRole等。

在验证JWT后,是否还需要通过setAuthenticated on Authentication object将其设置为true?