强制所有会话注销
我正在使用 spring+tapestry 来验证网络用户。我想知道是否有任何技术可以强制当前登录的所有用户注销假设我处于网站“处于维护模式”的情况下
:它是否能够强制所有用户的运行进程结束并仅强制注销
i'm using spring+tapestry for authenticate webuser. I wonder is there any technique i can force all users that currently login in to logout let say i'm on scenario where the site is 'under maintenance mode'
p/s: will it able to force all users' running process to finish and only force log out
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我想到了两件事:
使用
HttpSessionListener
来跟踪所有会话并在时机成熟时使它们无效。要使用它,您需要在ServletContext
中包含Session
对象的Set
(或者不太好 - 作为静态字段)。每当创建或销毁会话时更新该Set
,并在需要失效时迭代该集合。使用
过滤器
(映射到/*
),如果满足某些条件(maintenance == true
),则使当前会议。因此,所有用户在执行下一步操作时都将被注销。当“维护模式”并不意味着“停止整个服务器”,而是意味着“用户不应该执行任何操作,我正在后台做一些不应该被干扰的重要事情”时,这将起作用Two things come to my mind:
use
HttpSessionListener
to keep track of all sessions and invalidate them when the time comes. To use this you will need aSet
ofSession
objects in yourServletContext
(or less preferably - as a static field). Update thatSet
whenever a session is created or destroyed, and iterate the set when invalidation is needed.use a
Filter
(mapped to/*
) where, if certain conditions (maintenance == true
) are met, invalidate the current session. Thus all users will be logged out on their next action. This would work in cases when "maintenance mode" doesn't mean "stop the whole server", but rather means "no operations should be performed by users, I'm doing something important in the background that should not be interfered"问题是试图让他们完成请求然后才将他们注销。我假设如果他们在表单上点击“保存”,您希望保存数据,但随后应将它们重定向到维护页面。对于 GET 请求,如果设置了维护标志,您只需注销用户即可。 POST 有点困难,因为您想要完成请求,然后将其注销并将其重定向到维护页面。我会尝试请求过滤器。像平常一样处理请求,但如果设置了维护标志,则使会话无效并使用response.sendRedirect。
另一种选择是在布局中使用 JavaScript 计时器 - 定期点击页面以查看是否应该注销。但这可能不会让他们完成当前的请求。
The problem is trying to let them finish the request and only then log them out. I assume if they hit save on a form, you want the data to be saved but then they should be redirected to the maintenance page. For GET requests, you can just log the user out if the maintenance flag is set. POSTs are a litle harder because you want to complete the request but then sign them out and redirect them to the maintenance page. I would try a request filter. Handle the request like normal, but then invalidate the session and use response.sendRedirect if the maintenance flag is set.
Another option would be to use a JavaScript timer in the layout - hit a page periodically to see if they should be logged out. That probably wouldn't let them finish their current request though.