SSH版最大会话连接数
在登录方法中加入如下两行语句,作为程序的入口:
SessionListener.isAlreadyEnter(getHttpRequest().getSession(),this.getUserCode(),loginUser)
getHttpRequest().getSession().setAttribute("isLoginIn", "LoginIn");
在SessionListener类中做相关的踢出处理:
- import java.util.HashMap;
- import java.util.Iterator;
- import java.util.Map;
- import javax.servlet.ServletRequestEvent;
- import javax.servlet.ServletRequestListener;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpSession;
- import javax.servlet.http.HttpSessionAttributeListener;
- import javax.servlet.http.HttpSessionBindingEvent;
- import javax.servlet.http.HttpSessionEvent;
- import javax.servlet.http.HttpSessionListener;
- import org.apache.struts2.ServletActionContext;
- import com.hhwy.iepip.framework.message.Message;
- import com.opensymphony.xwork2.ActionContext;
- public class SessionListener implements HttpSessionListener,ServletRequestListener,HttpSessionAttributeListener{
- public static Map<String, HttpSession> sessionMap = new HashMap<String, HttpSession>();
- public static Map<String, HttpSession> sessionMap1 = new HashMap<String, HttpSession>();
- private static Boolean onlyOne = Boolean.valueOf(Message.getMessage("session.onlyone"));
- private HttpServletRequest request ;
- /**获取request对象*/
- public void requestInitialized(ServletRequestEvent event) {
- request = (HttpServletRequest)event.getServletRequest();
- }
- /**以下是实现HttpSessionListener中的方法:该方法登录与否都会执行**/
- public void sessionCreated(HttpSessionEvent se){
- }
- /**以下是实现HttpSessionListener中的方法**/
- public void sessionDestroyed(HttpSessionEvent se){
- hUserName.remove(se.getSession().getId());
- UserObject.remove(se.getSession().getId());
- if(sessionMap!=null){
- sessionMap.remove(se.getSession().getId());
- }
- if(sessionMap1!=null){
- sessionMap1.remove(se.getSession().getId());
- }
- }
- /**
- * isAlreadyEnter-用于判断用户是否已经登录以及相应的处理方法
- * <该方法是系统业务的方法,不是处理单个用户登录的问题,以该方法做为程序的入口>
- */
- public static boolean isAlreadyEnter(HttpSession session,String sUserName,LoginUserInfo loginTriggers){
- boolean flag = false;
- return flag;
- }
- /**
- * 此方法,可以在登录时候添加一个session 用以判断是否已经登录,然后再进行登录人登录控制
- */
- public void attributeAdded(HttpSessionBindingEvent event) {
- //如果只允许一个账号一处登陆,单台客户端电脑只允许一个用户登录
- if(onlyOne.booleanValue()){
- String name = event.getName();
- if(name.equals("isLoginIn")){
- // 单台客户端电脑只允许一个用户登录
- String ipAddr = this.getIpAddr(request);
- //如果原先已登录,则踢出原先登陆的
- if(sessionMap1.containsKey(ipAddr) ){
- try{
- sessionMap1.get(ipAddr).invalidate();
- }catch(Exception e){}
- sessionMap1.remove(ipAddr);
- }
- if(ipAddr != null && event.getSession().isNew())
- sessionMap1.put(ipAddr, event.getSession());
- //只允许一个账号一个客户端登陆
- String userName= getUserName(event);
- if(sessionMap.containsKey(userName) ){
- try{
- sessionMap.get(userName).invalidate();
- }catch(Exception e){}
- sessionMap.remove(userName);
- }
- if(userName != null && event.getSession().isNew())
- sessionMap.put(userName, event.getSession());
- }
- }
- }
- public static String getIpAddr(HttpServletRequest request) {
- String ip = request.getHeader("x-forwarded-for");
- if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
- ip = request.getHeader("Proxy-Client-IP");
- }
- if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
- ip = request.getHeader("WL-Proxy-Client-IP");
- }
- if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
- ip = request.getRemoteAddr();
- }
- return ip;
- }
- /*获取session中存储的用户名*/
- private String getUserName(HttpSessionBindingEvent se) {
- String userName = null;
- return userName;
- }
- public void attributeRemoved(HttpSessionBindingEvent event) {
- // TODO Auto-generated method stub
- }
- public void attributeReplaced(HttpSessionBindingEvent arg0) {
- // TODO Auto-generated method stub
- }
- public void requestDestroyed(ServletRequestEvent arg0) {
- // TODO Auto-generated method stub
- }
SSH版最大会话连接数的更多相关文章
- 《linux就该这么学》课堂笔记13 网络会话、ssh、远程会话
1.常见的网卡绑定驱动有三种模式—mode0.mode1和mode6 mode0(平衡负载模式):平时两块网卡均工作,且自动备援,但需要在与服务器本地网卡相连的交换机设备上进行端口聚合来支持绑定技术. ...
- ORA-00020: maximum number of processes (40) exceeded模拟会话连接数满
问题描述:在正式生产环境中,有的库建的process和session连接数目设置的较小,导致后期满了无法连接.因为正式库无法进行停库修改,只能释放连接,做个测试模拟 1. 修改现有最大会话与进程连接数 ...
- 解决SSH会话连接超时问题
用SSH客户端连接linux服务器时,经常会出现与服务器会话连接中断现象,照成这个问题的原因便是SSH服务有自己独特的会话连接机制.记得在一年前就有朋友问过我这个问题,那时候我便是草草打发,结果自己现 ...
- 阿里云(ECS)Linux客户端SSH会话连接超时OperationTimedOut
问题描述:使用SecureCRT等SSH客户端连接Linux服务器时,提示Operation timed out. 问题原因:SSH服务未配置或注释掉向SSH客户端连接会话发送频率和时间. 解决方法: ...
- SSH的端口转发:本地转发Local Forward和远程转发Remote Forward
关于使用ssh portforwarding来进行FQ的操作,网络上已经有很多很好的文章,我在这里只是画两个图解释一下. 首先要记住一件事情就是: SSH 端口转发自然需要 SSH 连接,而 SSH ...
- Android手机SSH Client客户端推荐JuiceSSH
Windows上建立ssh服务器 参见: http://www.cnblogs.com/xred/archive/2012/04/21/2461627.html Android手机SSH Client ...
- SSH服务端配置、优化加速、安全防护
CentOS7自带的SSH服务是OpenSSH中的一个独立守护进程SSHD.由于使用telnet在网络中是明文传输所以用其管理服务器是非常不安全的不安全,SSH协议族可以用来对服务器的管理以及在计算机 ...
- Redhat 6.7 x64升级SSH到OpenSSH_7.4p1完整文档
原文链接:https://www.cnblogs.com/xshrim/p/6472679.html 导语 Redhat企业级系统的6.7版自带SSH版本为OpenSSH_5.3p1, 基于审计和安全 ...
- SSH的端口转发
这里是一篇很好的介绍SSH PortForwarding的文章http://www.ibm.com/developerworks/cn/linux/l-cn-sshforward/ 可以将远端服务器一 ...
随机推荐
- [SoapUI] Tips and Tricks(提示和技巧)
https://www.soapui.org/scripting-properties/tips-tricks.html
- 《Delphi XE6 android 编程入门教程》推荐
近5.6年已经没有看见关于delphi的新技术的书出来了(看来在国内delphi的使用量确实很低了), 高勇同学最近出了一本<Delphi XE6 android 编程入门教程>,上周刚拿 ...
- 2018.08.17 洛谷[POI2010]GRA-The Minima Game(线性dp)
传送门 短代码神奇dp. 自己yy的思路居然1A了好高兴啊! 不难想到每个人选择的时候一定是取连续的最大的那一段数,自然需要先排序. 然后可以用dp[i]表示当前最大数是a[i]的时候先手可以获得的最 ...
- RESTful Web API 实践
REST 概念来源 网络应用程序,分为前端和后端两个部分.当前的发展趋势,就是前端设备层出不穷(手机.平板.桌面电脑.其他专用设备...). 因此,必须有一种统一的机制,方便不同的前端设备与后端进行通 ...
- 优秀前端工程师必备:" checkbox & radio--单钩 & 多钩 "大比较:你是♂||♀ , 还是 ♂&♀
1 单选: type="radio" 需求: 男女input只能选择一个 <input type="radio" name="sex" ...
- 都有哪些 cache ?
1. spring http://www.springframework.org/schema/cache 2. ehcache LOGO关键词:palindrome [ˈpælɪndrəʊm] 正读 ...
- 一种基于Redis的10行代码实现IP频率控制方法
优点:可支持海量访问的频率控制,只需要增加Redis机器,单个Redis节点(只占用一个cpu core)即可支持10万/s以上的处理. 基于IP频率限制是种常见需求,基于Redis可以十分简单实现对 ...
- The First Android App----Adding the Action Bar
In its most basic form, the action bar displays the title for the activity and the app icon on the l ...
- Python学习-2.安装IDE
Python安装包中已经包含了一个IDE了,叫IDLE,可以在Python的安装目录内找到路径为 ./Lib/idlelib/idle.bat 或者可以在开始菜单中找到. 但是这个IDE功能很弱,缺少 ...
- Git安全配置
今天收到了阿里云异地登录的短信报警,登录阿里云后台发现,有人从深圳登录了我的服务器(本人在北京),查看详细信息一共登录了5次,前两次是使用的git用户进行登录,后两次已经变成了root用户,怀疑是 ...