Java secure session

前端 未结 4 1810
感动是毒
感动是毒 2020-12-11 18:10

Whenever you authenticate, your application should change the session identifier it uses. This helps to prevent someone from setting up a session, copying the session identi

4条回答
  •  温柔的废话
    2020-12-11 19:04

    You're still on the server while you invalidate the session.

    //get stuff out of session you want before invalidating it.
    currentSession = request.getSession(true);
    UserProfile userProfile = (UserProfile) currentSession.getAttribute("userProfile");
    
    //now invalidate it
    currentSession.invalidate();
    
    //get new session and stuff the data back in
    HttpSession newSession = request.getSession(true);
    newSession.setAttribute("userProfile", userProfile);
    

提交回复
热议问题