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/ 可以将远端服务器一 ...
随机推荐
- ipconfig 查看本机IP地址
打开cmd 窗口 然后输入ipconfig 就会为你展示你想要的IP地址了...
- 2018.09.19 atcoder Snuke's Subway Trip(最短路)
传送门 就是一个另类最短路啊. 利用颜色判断当前节点的最小花费的前驱边中有没有跟当前的边颜色相同的. 如果有这条边费用为0,否则费用为1. 这样跑出来就能ac了. 代码: #include<bi ...
- 打开yii2控制台命令
1.在控制台中切换到yii2控制台入口文件的工作路径.如:C:\users\2016-01>D:www\blogdemo\yii
- hdu-1176(动态规划)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1176 思路:类似数塔问题, 从最后一秒开始考虑,每次这一秒的状态确定意味着前一秒的状态也已经确定,所以 ...
- MAC安装远程工具Securecrt的破解方式(详细有图)
想要实现mac的远程连接功能,本来想使用终端的,但是终端的很多功能是欠佳的,所以决定安装一款,像windows的xshell一样好的软件,所以选择了这款Securecrt. 首先准备两个东西,一个是S ...
- 删除重复的feature vba VS 删除重复的feature python
VBA: Sub deleteDuplicatedFeature() Dim app As IApplication Set app = Application Dim pMxDocument As ...
- HDU1518 Square(DFS) 2016-07-24 15:08 49人阅读 评论(0) 收藏
Square Problem Description Given a set of sticks of various lengths, is it possible to join them end ...
- HDU1254 推箱子(BFS) 2016-07-24 14:24 86人阅读 评论(0) 收藏
推箱子 Problem Description 推箱子是一个很经典的游戏.今天我们来玩一个简单版本.在一个M*N的房间里有一个箱子和一个搬运工,搬运工的工作就是把箱子推到指定的位置,注意,搬运工只能推 ...
- WPF Out Of Memory
起因 程序发布后,运行突然奔溃报Out of Memory,查看日志发现如下类似错误(以下堆栈信息来之网络): System.OutOfMemoryException: Insufficient me ...
- 第二章 ConcurrentHashMap源码解析
注:在看这篇文章之前,如果对HashMap的层不清楚的话,建议先去看看HashMap源码解析. http://www.cnblogs.com/java-zhao/p/5106189.html 1.对于 ...