Home  >  Forum  >  Spring
Post New Query

Sessions are not persisting in the database for each user in same browser with different tabs using Spring Sessions with MySQL

Asked on January 24, 2017

I'm currently using db (mysql) to store my sessions with spring.It is generating new session id for each user .but it is replacing session id's of previously who are logged. Please give some suggestions to overcome this problem. The following is the service which is i am calling from controller for each request

public class MultiLoginServiceImpl
        public static String createMultiLogin(HttpServletRequest httpRequest)

                String alias = httpRequest.getParameter("_s");

            SessionRepository<Session> sessionRepository =(SessionRepository<Session>) httpRequest.getAttribute(SessionRepository.class.getName());

                Map<String, String> sessionIds = sessionManager.getSessionIds(httpRequest);
                for(Map.Entry<String, String> entry : sessionManager.getSessionIds(httpRequest).entrySet()) {

                    String aliasId = entry.getKey();
                    String sessionId = entry.getValue();
                    HttpSession httpSession = httpRequest.getSession(false);
                    Session storedSession = sessionRepository.getSession(sessionId);
                    if(storedSession.getAttribute("userEmailId")!= null)
                        httpSession.setAttribute("userEmailId", storedSession.getAttribute("userEmailId"));
                    System.out.println("mapids"+aliasId +" : "+sessionId);

                String addAlias = alias== null ? newSessionAlias1: requestedSessionAlias1; 

                /*if(alias == null || "".equals(alias.trim()))
                        alias = sessionManager.getNewSessionAlias(httpRequest);
                //SecurityContext context = (SecurityContext) httpSession.getAttribute(HttpSessionSecurityContextRepository.SPRING_SECURITY_CONTEXT_KEY);
                String addAccountUrl = sessionManager.encodeURL(httpRequest.getContextPath(), addAlias); 
                return addAccountUrl ;


Write Answer

©2022 concretepage.com | Privacy Policy | Contact Us