【问题标题】:spring security - how to make another user log outspring security - 如何让另一个用户注销
【发布时间】:2012-07-31 14:25:54
【问题描述】:

当我想从我的应用程序中删除一个用户时,我也想将他注销(只要他点击任何链接)。我可以通过以下方式清除我自己的安全上下文:

SecurityContextHolder.getContext().setAuthentication(null);

但我应该如何清除他的安全上下文?

【问题讨论】:

标签: spring spring-security


【解决方案1】:

SecurityContextHolder.getContext().setAuthentication(null); 将使当前会话无效。

SecurityContextHolder.getContext() 返回一个会话范围的 bean。因此调用 setAuthentication(null) 将使 当前用户的会话无效。

因此,当用户单击链接时,您可以从控制器中调用它,并且他的会话将失效。

当然,您可能不想通过所有控制器分散代码来执行此操作。因此,您可以使用 过滤器 来代替。

在您的过滤器中,您可以保留一个单例 bean,其中包含您要使其无效的所有用户名的列表。然后根据列表检查当前会话并决定是否无效。

【讨论】:

    猜你喜欢
    • 2013-04-29
    • 1970-01-01
    • 2017-12-12
    • 2012-11-10
    • 2014-12-11
    • 2014-04-16
    • 2020-04-02
    • 2017-05-20
    • 2019-05-09
    相关资源
    最近更新 更多