首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >我能用Spring Security管理多个浏览器标签吗?

我能用Spring Security管理多个浏览器标签吗?
EN

Stack Overflow用户
提问于 2011-05-26 01:01:33
回答 3查看 13K关注 0票数 7

我想知道,如果使用Spring Security,我是否可以验证用户会话,只允许打开一个浏览器选项卡。有可能吗?

我还想知道,如果我可以做到这一点,当用户关闭标签,并再次打开它之前,他的会话结束SessionFilter直接应用程序,而不是去登录屏幕。

我使用的是JSF1.2、RichFaces 3.3.3、Hibernate和...

细节:我知道spring的安全机制,我正在研究它。

现在,谢谢并原谅我糟糕的英语。

再见!

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2011-05-26 01:14:03

不是的。来自http://static.springsource.org/spring-security/site/faq.html

2.1。

我使用Spring Security的并发会话控制来防止用户一次登录一次以上。当我在登录后打开另一个浏览器窗口时,并没有阻止我再次登录。为什么我可以多次登录?

浏览器通常为每个浏览器实例维护一个会话。您不能同时有两个单独的会话。服务器对选项卡、窗口或浏览器实例一无所知。它只看到HTTP请求,并根据它们包含的JSESSIONID cookie的值将这些请求绑定到特定的会话。

票数 5
EN

Stack Overflow用户

发布于 2012-07-06 15:59:08

我最近使用Spring Security实现了多个选项卡/窗口的解决方案。为了成功登录,我使用了` `LoginSucessHandler并在会话中设置了一个唯一的窗口名称。在主模板页面上,我设置了一个窗口名称,并在每个页面上加载验证窗口名称与会话的窗口名称,如果它不相同,则重定向到错误页面。

以下是配置和代码:

代码语言:javascript
复制
@Service
public class LoginSucessHandler extends
        SavedRequestAwareAuthenticationSuccessHandler {

    @Override
    public void onAuthenticationSuccess(HttpServletRequest request,
            HttpServletResponse response, Authentication authentication)
            throws ServletException, IOException {
        User user = (User) authentication.getPrincipal();
        String windowName = user.getUsername() + new Date().getTime();
        HttpSession session = request.getSession();
        session.setAttribute("windowName", windowName);
        session.setAttribute("windowNameToSet", windowName);
        super.onAuthenticationSuccess(request, response, authentication);
    }

}

主模板或标题页:

代码语言:javascript
复制
<script>
  <%if (session.getAttribute("windowNameToSet") != null) {
        out.write("window.name = '"
            + session.getAttribute("windowNameToSet") + "';");
        session.removeAttribute("windowNameToSet");
  }%>
  if (window.name != "<%=session.getAttribute("windowName")%>") {
        window.location = "<%=request.getContextPath()%>/forms/multiwindowerror.jsp";
  }
</script>

对于安全上下文:

代码语言:javascript
复制
<http auto-config="true" use-expressions="true">
    <intercept-url pattern="/login.hst**" access="anonymous or authenticated" />
    <intercept-url pattern="/**/*.hst" access="authenticated" />
    <form-login login-page="/login.hst"
        authentication-failure-url="/login.hst?error=true"
        authentication-success-handler-ref="loginSucessHandler" />
    <logout invalidate-session="true" logout-success-url="/home.hst"
        logout-url="/logout.hst" />
    <remember-me key="jbcp" authentication-success-handler-ref="loginSucessHandler"/>
</http>

只要确保上面的login.jsp中没有包含JavaScript即可。

票数 3
EN

Stack Overflow用户

发布于 2013-03-09 05:58:52

我想出了一种更简单的方法来完成同样的事情。如果您已经在扩展SimpleUrlAuthenticationSuccessHandler,就像@Jagar一样,创建一个已登录用户的数组列表,将用户添加到其中,并将其添加到会话中。然后,每次登录时,检查会话是否存在,以及该用户是否在session arraylist属性中。如果是,则失败,如果不是,则允许登录。

这样,您就可以让多个用户使用同一个浏览器登录,而不是同一个用户。这还可以防止错误地覆盖windowName属性的可能性。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6128134

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档