zoukankan      html  css  js  c++  java
  • 强制更新JsessionID的方法

    
    登录前的请求一般都是http的,http是不安全的,假设用户登录前的JSESSIONID被人取得,如果登录后不变更JSESSIONID的话,即使登录请求是https的,该用户仍然会被他人冒充。

    /** 
     * 重置sessionid,原session中的数据自动转存到新session中 
     * @param request 
     */  
    public static void reGenerateSessionId(HttpServletRequest request){  
          
        HttpSession session = request.getSession();  
          
        //首先将原session中的数据转移至一临时map中  
        Map<String,Object> tempMap = new HashMap();  
        Enumeration<String> sessionNames = session.getAttributeNames();  
        while(sessionNames.hasMoreElements()){  
            String sessionName = sessionNames.nextElement();  
            tempMap.put(sessionName, session.getAttribute(sessionName));  
        }  
          
        //注销原session,为的是重置sessionId  
        session.invalidate();  
          
        //将临时map中的数据转移至新session  
        session = request.getSession();  
        for(Map.Entry<String, Object> entry : tempMap.entrySet()){  
            session.setAttribute(entry.getKey(), entry.getValue());  
        }  
    } 





  • 相关阅读:
    Pika的设计及实现
    高性能网络编程
    C语言的结构体
    消息队列库——ZeroMQ
    Diffie-Hellman密钥交换算法
    mysql-proxy 读写分离
    位运算
    分布式学习之一:事务
    Redis Cluster
    SpringBoot整合ActiveMQ,看这篇就够了
  • 原文地址:https://www.cnblogs.com/DiZhang/p/12545112.html
Copyright © 2011-2022 走看看