发布于 2021-10-10 16:20:17
@PreAuthorize
的值是SpEL,根据文档,它将根据根对象SecurityExpressionRoot
进行计算。
isAuthenticated()
是在SecurityExpressionRoot
实例上调用isAuthenticated()
的语法(参见这)。
而authenticated
是访问SecurityExpressionRoot
实例属性的语法(参见这)。它将尝试调用以下公共属性或方法来计算值:
authenticated
性质getAuthenticated()
isAuthenticated()
(仅当计算值为布尔值时)authenticated()
您可以在这里的代码中找到这样的逻辑。
发布于 2021-10-10 11:58:20
我已经检查了org.springframework.security.web.servletapi.Servlet3SecurityContextHolderAwareRequestWrapper
中的源代码
private boolean isAuthenticated() {
return getUserPrincipal() != null;
}
然后查看getUserPrincipal()
@Override
public Principal getUserPrincipal() {
Authentication auth = getAuthentication();
if ((auth == null) || (auth.getPrincipal() == null)) {
return null;
}
return auth;
}
然后是getAuthentication()
。这是重点:
private Authentication getAuthentication() {
Authentication auth = SecurityContextHolder.getContext().getAuthentication();//!!!
return (!this.trustResolver.isAnonymous(auth)) ? auth : null;
}
如其所示,authentication
对象由SecurityContextHolder
管理。
至于authenticated
,我认为它可能是spring容器中的单例Java。它的价值与以下内容相同:
authentication.isAuthenticated();
在org.springframework.security.core.Authentication
中
https://stackoverflow.com/questions/69514798
复制相似问题