【发布时间】:2014-06-21 23:03:24
【问题描述】:
在我的应用程序中,登录时我正在创建一个 cookie(AAA)。在注销时,我可以删除 cookie。在自动会话超时时,将用户重定向到登录页面,但无法删除(过期)cookie(AAA)。我在我的应用程序中使用 Jboss AS 7.1、spring-3.1 和 spring-security。
以下是我的security.xml中的http标签配置
<http auto-config="true" use-expressions="true" entry-point-ref="customLoginUrlAuthenticationEntryPoint" disable-url-rewriting="true">
<request-cache ref="httpSessionRequestCache"/>
<session-management invalid-session-url="/ctx/login?invalid-session=true" session-authentication-error-url="/ctx/login?session-auth-error=true">
<concurrency-control max-sessions="1" expired-url="/ctx/login?expired=true" error-if-maximum-exceeded="true" />
</session-management>
<form-login authentication-success-handler-ref="customAuthenticationSuccessHandler"
authentication-failure-handler-ref="customPageHandler"
login-processing-url="/j_spring_security_check"/>
<custom-filter before="ANONYMOUS_FILTER" ref="anonymousFilter"/>
<custom-filter before="FORM_LOGIN_FILTER" ref="customFilter"/>
<custom-filter before="LOGOUT_FILTER" ref="logoutFilter" />
</http>
我尝试了以下选项
选项 1- 创建一个 HttpFilter 来刷新 cookie 并同步 session 和 cookie 之间的时间。
选项 2- 为登录页面 url(/login) 创建一个 HttpFilter,为登录页面调用过滤器并删除 cookie。
选项 1 似乎不起作用,因为我可以在会话超时后看到 cookie。 选项 2 的问题是,如果登录用户尝试从具有不同选项卡的同一浏览器再次请求登录页面,则会调用过滤器并删除 cookie。哪个不好。因为进一步通信需要 cookie。
您能否帮助我了解删除 cookie 的正确方法。
我还想提一下,过滤器在 HttPSessionListene#sessionDestroyed 方法之前被调用。
【问题讨论】:
-
你的 cookie 是干什么用的?当您使用 spring-security 时,我认为它不是用于会话识别,因为它已经由 spring-sec 管理。如果您有会话,为什么要尝试将另一个 cookie 与您的会话同步?您将在 this post 中找到有关 cookie 类型的参考资料
-
我们正在其他子系统中进行基于cookie的身份验证
-
好的,但是你确定你真的需要在两个系统上保持会话同步吗?我不确定您是否可以,但您也可以查看CAS protocol 作为在中心点对用户进行身份验证以使多个系统受益的实现。请注意,此协议使用会话 cookie 而不是永久的(请参阅我之前的评论以获取参考)。
-
没错。但此时我无法改变任何事情。如果您可以提供一些方向并留下选项会很好
-
您应该提供更多关于您想做什么和可以做什么的信息。如果没有更多信息,我只能问你是否在会话中保留 cookie 的值。它可以帮助查看 cookie 是否有效(不在当前会话中意味着无效...)
标签: java spring cookies spring-security session-timeout