在没有弹簧的情况下,使用java,hibernate web应用程序一次限制用户登录到单个会话 [英] Restrict a user login to single session at a time using java, hibernate web application without spring

查看:141
本文介绍了在没有弹簧的情况下,使用java,hibernate web应用程序一次限制用户登录到单个会话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个使用Java,Hibernate和JSF的Web应用程序。
我希望用户限制只能登录一个会话,如果用户已经登录,我不想在没有注销第一个会话的情况下从其他位置登录。



任何人都可以帮助了解如何实现。要提及的是,根据我的要求,我不能使用spring或其任何功能。

你必须维护一个应用程序范围 Set ,它包含所有登录的用户逻辑标识符(如果您期望太多的用户可能会将其写入数据库)

在登录时,通过在 Set


$ b $中检查他/她的标识符来检查用户是否已经登录b

注销时,将用户从集合



中删除,在会话过期后将用户从 Set



使用 HttpSessionListener 从Set sessionDestroyed()



如果您在内存中持久存储数据,则在应用程序关闭时清除该外部数据源


I am developing a web application using Java , Hibernate and JSF. I want a user to restrict to login to a single session only, that I if user is already logged in I don't want to login it back from other location without logging out the first session.

Can anyone help in letting know how that can be achieved. To mention that as per my requirements I can't use spring or its any feature.

解决方案

You would have to maintain a application scoped Set<Long> that contains all the logged in user logical identifier (if you expect too many user may be write it to DB)

Upon login attempt check if the user is already logged in by checking his/her identifier in that Set

Upon logout remove user from that Set

Upon session expiration remove user from that Set

Use HttpSessionListener to remove user identifier from Set sessionDestroyed()

If you persist that data out of memory, upon app shutdown clear that external data source

这篇关于在没有弹簧的情况下,使用java,hibernate web应用程序一次限制用户登录到单个会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆