Ejemplo n.º 1
0
 public void stop() {
   ClassLoader old = getTccl();
   try {
     setTccl(servletContext.getClassLoader());
     this.started = false;
     final Map<String, SessionPersistenceManager.PersistentSession> objectData = new HashMap<>();
     for (String sessionId : sessionManager.getTransientSessions()) {
       Session session = sessionManager.getSession(sessionId);
       if (session != null) {
         final HttpSessionEvent event =
             new HttpSessionEvent(SecurityActions.forSession(session, servletContext, false));
         final Map<String, Object> sessionData = new HashMap<>();
         for (String attr : session.getAttributeNames()) {
           final Object attribute = session.getAttribute(attr);
           sessionData.put(attr, attribute);
           if (attribute instanceof HttpSessionActivationListener) {
             ((HttpSessionActivationListener) attribute).sessionWillPassivate(event);
           }
         }
         objectData.put(
             sessionId,
             new PersistentSession(
                 new Date(
                     session.getLastAccessedTime() + (session.getMaxInactiveInterval() * 1000)),
                 sessionData));
       }
     }
     sessionPersistenceManager.persistSessions(deploymentName, objectData);
     this.data.clear();
   } finally {
     setTccl(old);
   }
 }
  public HttpSession getSession(
      final ServletContextImpl originalServletContext,
      final HttpServerExchange exchange,
      boolean create) {
    SessionConfig c = originalServletContext.getSessionConfig();
    ConvergedHttpSessionFacade httpSession = exchange.getAttachment(sessionAttachmentKey);
    if (httpSession != null && httpSession.isValidIntern()) {
      exchange.removeAttachment(sessionAttachmentKey);
      httpSession = null;
    }
    if (httpSession == null) {
      final SessionManager sessionManager = context.getDeployment().getSessionManager();
      Session session = sessionManager.getSession(exchange, c);
      if (session != null) {
        httpSession =
            (ConvergedHttpSessionFacade)
                SecurityActions.forSession(session, this, false, sessionManager);
        exchange.putAttachment(sessionAttachmentKey, httpSession);
      } else if (create) {

        String existing = c.findSessionId(exchange);
        if (originalServletContext != this.context) {
          // this is a cross context request
          // we need to make sure there is a top level session
          originalServletContext.getSession(originalServletContext, exchange, true);
        } else if (existing != null) {
          c.clearSession(exchange, existing);
        }

        final Session newSession = sessionManager.createSession(exchange, c);
        httpSession =
            (ConvergedHttpSessionFacade)
                SecurityActions.forSession(newSession, this, true, sessionManager);
        // call access after creation to set LastAccessTime at sipAppSession.
        httpSession.access();
        // add delegate to InMemorySession to call sipAppSession.access(), when necessary:
        ((ConvergedInMemorySessionManager) sessionManager)
            .addConvergedSessionDeletegateToSession(
                newSession.getId(), httpSession.getConvergedSessionDelegate());

        exchange.putAttachment(sessionAttachmentKey, httpSession);
      }
    }
    return httpSession;
  }
 @Override
 public void remove(Session session) {
   this.sessions.remove(session.getSessionManager());
 }
 @Override
 public boolean contains(Session session) {
   return this.sessions.containsKey(session.getSessionManager());
 }
 @Override
 public void add(Session session) {
   this.sessions.put(session.getSessionManager(), session);
 }