【问题标题】:Handling different user sessions in same browser in spring mvc在spring mvc中处理同一浏览器中的不同用户会话
【发布时间】:2019-10-21 06:45:42
【问题描述】:

我有一个 spring mvc 应用程序,管理员可以在其中创建和更新用户信息,并在同一个浏览器中打开他们各自的用户窗口。但是,当管理员在一个选项卡中打开一个用户会话,然后尝试在另一个选项卡中打开另一个用户会话时,它会给出错误,指出一个活动会话已经存在。我们如何使管理员能够在同一个浏览器和不同的选项卡中与不同的用户一起玩他们各自的会话?有什么方法可以处理这些会话

【问题讨论】:

  • 只要您将身份验证令牌(即SESSIONID)保存在来自同一域的 cookie 中,这是不可能的。
  • 谢谢,有什么办法可以解决这个问题吗?
  • 这更多的是客户端问题。它可以在一个用户会话中处理吗?你能提供更多细节吗?
  • 基本上管理员有权更新不同国家/地区的用户详细信息,因此如果他为一个国家/地区打开用户会话/选项卡,同时他想打开另一个国家/地区的用户会话/选项卡
  • 客户端如何处理?

标签: spring spring-boot model-view-controller spring-security session-cookies


【解决方案1】:

我认为当用户打开会话网络应用程序时,为窗口对象提供一些 id 活动浏览器选项卡,例如 $window.name = "cliendId"

当用户登录时你的 spring 应用程序通过 web 发送这个窗口 id 并使用 spring security 处理

public class CustomWebAuthenticationDetails extends WebAuthenticationDetails {

    private final Logger log = LoggerFactory.getLogger(CustomWebAuthenticationDetails.class);

    private final String clientid;

    CustomWebAuthenticationDetails(final HttpServletRequest request) {
        super(request);
        clientid = request.getHeader("clientid");

        log.debug("User Agent {}", request.getHeader("User-Agent"));
    }

    public String getClientid() {
        return clientid;
    }

}

并配置

@Component
public class CustomWebAuthenticationDetailsSource implements AuthenticationDetailsSource<HttpServletRequest, WebAuthenticationDetails> {
    @Override
    public WebAuthenticationDetails buildDetails(final HttpServletRequest context) {
        return new CustomWebAuthenticationDetails(context);
    }
}

现在按用户管理或列出此会话 ID,当用户打开新会话相同选项卡时发出警报或终止会话,并编写自己的安全过滤器并实施安全过滤器链管理每个请求

【讨论】:

    猜你喜欢
    • 2012-08-12
    • 2019-05-02
    • 1970-01-01
    • 1970-01-01
    • 2017-09-30
    • 2014-05-19
    • 1970-01-01
    • 1970-01-01
    • 2012-07-31
    相关资源
    最近更新 更多