コード例 #1
0
  @Override
  public io.undertow.server.session.Session createSession(
      HttpServerExchange exchange, SessionConfig config) {
    if (config == null) {
      throw UndertowMessages.MESSAGES.couldNotFindSessionCookieConfig();
    }

    String id = config.findSessionId(exchange);

    if (id == null) {
      int attempts = 0;
      do {
        if (++attempts > MAX_SESSION_ID_GENERATION_ATTEMPTS) {
          throw UndertowMessages.MESSAGES.couldNotGenerateUniqueSessionId();
        }
        id = this.manager.createIdentifier();
      } while (this.manager.containsSession(id));

      config.setSessionId(exchange, id);
    }

    Batch batch = this.manager.getBatcher().createBatch();
    try {
      Session<LocalSessionContext> session = this.manager.createSession(id);
      io.undertow.server.session.Session adapter =
          new DistributableSession(this, session, config, batch);
      this.sessionListeners.sessionCreated(adapter, exchange);
      return adapter;
    } catch (RuntimeException | Error e) {
      batch.discard();
      throw e;
    }
  }
コード例 #2
0
 @Override
 public String changeSessionId(HttpServerExchange exchange, SessionConfig config) {
   Session<LocalSessionContext> oldSession = this.entry.getKey();
   SessionManager<LocalSessionContext, Batch> manager = this.manager.getSessionManager();
   String id = manager.createIdentifier();
   try (BatchContext context =
       this.manager.getSessionManager().getBatcher().resumeBatch(this.batch)) {
     Session<LocalSessionContext> newSession = manager.createSession(id);
     for (String name : oldSession.getAttributes().getAttributeNames()) {
       newSession
           .getAttributes()
           .setAttribute(name, oldSession.getAttributes().getAttribute(name));
     }
     newSession
         .getMetaData()
         .setMaxInactiveInterval(oldSession.getMetaData().getMaxInactiveInterval());
     newSession.getMetaData().setLastAccessedTime(oldSession.getMetaData().getLastAccessedTime());
     newSession
         .getLocalContext()
         .setAuthenticatedSession(oldSession.getLocalContext().getAuthenticatedSession());
     config.setSessionId(exchange, id);
     this.entry = new SimpleImmutableEntry<>(newSession, config);
     oldSession.invalidate();
   }
   // Invoke listeners outside of the context of the batch associated with this session
   this.manager.getSessionListeners().sessionIdChanged(this, oldSession.getId());
   return id;
 }
コード例 #3
0
  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;
  }
コード例 #4
0
 /** Appends routing information to session identifier. */
 private io.undertow.server.session.Session getSession(
     Session<Void> session, HttpServerExchange exchange, SessionConfig config) {
   SessionFacade facade = new SessionFacade(this, session, config);
   if (this.config.getUseJK().booleanValue()) {
     String id = session.getId();
     config.setSessionId(exchange, this.format(id, this.locate(id)));
   }
   return facade;
 }
コード例 #5
0
  @Override
  public io.undertow.server.session.Session getSession(
      HttpServerExchange exchange, SessionConfig config) {
    String id = config.findSessionId(exchange);
    if (id == null) return null;

    Batch batch = this.manager.getBatcher().createBatch();
    try {
      Session<LocalSessionContext> session = this.manager.findSession(id);
      if (session == null) {
        batch.discard();
        return null;
      }
      return new DistributableSession(this, session, config, batch);
    } catch (RuntimeException | Error e) {
      batch.discard();
      throw e;
    }
  }
コード例 #6
0
 /** Strips routing information from requested session identifier. */
 private String findSessionId(HttpServerExchange exchange, SessionConfig config) {
   String id = config.findSessionId(exchange);
   return this.config.getUseJK().booleanValue() ? this.parse(id).getKey() : id;
 }