gpt4 book ai didi

java - SecurityContextHolder 可以跨用户共享吗

转载 作者:行者123 更新时间:2023-11-30 07:39:24 24 4
gpt4 key购买 nike

回答这个问题securitycontextholder-session-or-request-bound 。我正在使用此示例 how-to-customAuthenticationManager 实现 CustomAuthenticationManager 。事实证明,我的用户体验得到了Accross Session。

例如,用户 A 与 Web 应用程序交互,有时在访问配置文件时,用户 A 可以获得用户 B 的配置文件(这是因为应用程序正在从 SecurityContextHolder 的主体检索 UserProfileLoggedIn 并访问数据库),同时用户 B 已登录,但可能无法访问个人资料。

我想知道这是 SecurityContextHolder 泄漏吗?我知道SecurityContextHolder只是将HttpSession实现为容器以包含userDetails等的一种方法。

现在,遇到问题后,我将 customAuthenticationManager 更改为 customAuthenticationProvider。有关更多信息,中午的并发用户数约为 100-500。

有关其他信息,我正在我的 @Service 类中实现 SecurityContextHolder,以便其他团队成员可以轻松获取

@Service
public MyServiceImpl implement MyServiceInterface{
public UserDetail findUser(){
return (UserDetail) SecurityContextHolder.getContext().
getAuthentication().getPrincipal();
}
}

最佳答案

默认情况下,执行SecurityContextHolder绑定(bind)到 ThreadLocal 的实例:

  • 它是可扩展的,只要您的容器向 Spring Security 提供同步线程即可。
  • 抽象不是 HttpSession 的实现;但是,它提供了与底层 HTTP Servlet 提供程序的集成,以将 HTTP 安全信息传输到 Spring 管理的应用程序层。
  • 基于ThreadLocal的组合使API的用户能够利用不同线程中的多个数据 View 。这也是为什么如果您的 HTTP 容器中具有正确的线程配置,则在用户数量方面就不应该出现可扩展性问题。

关于java - SecurityContextHolder 可以跨用户共享吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34903476/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com