Search in sources :

Example 11 with Session

use of io.undertow.server.session.Session in project undertow by undertow-io.

the class ServletContextImpl method getSession.

/**
 * Gets the session with the specified ID if it exists
 *
 * @param sessionId The session ID
 * @return The session
 */
public HttpSessionImpl getSession(final String sessionId) {
    final SessionManager sessionManager = deployment.getSessionManager();
    Session session = sessionManager.getSession(sessionId);
    if (session != null) {
        return SecurityActions.forSession(session, this, false);
    }
    return null;
}
Also used : SessionManager(io.undertow.server.session.SessionManager) Session(io.undertow.server.session.Session)

Example 12 with Session

use of io.undertow.server.session.Session in project undertow by undertow-io.

the class ServletContextImpl method updateSessionAccessTime.

public void updateSessionAccessTime(final HttpServerExchange exchange) {
    HttpSessionImpl httpSession = getSession(exchange, false);
    if (httpSession != null) {
        Session underlyingSession;
        if (System.getSecurityManager() == null) {
            underlyingSession = httpSession.getSession();
        } else {
            underlyingSession = AccessController.doPrivileged(new HttpSessionImpl.UnwrapSessionAction(httpSession));
        }
        underlyingSession.requestDone(exchange);
    }
}
Also used : Session(io.undertow.server.session.Session)

Example 13 with Session

use of io.undertow.server.session.Session in project undertow by undertow-io.

the class LearningPushHandler method doPush.

private void doPush(HttpServerExchange exchange, String fullPath) {
    if (exchange.getConnection().isPushSupported()) {
        Map<String, PushedRequest> toPush = cache.get(fullPath);
        if (toPush != null) {
            Session session = getSession(exchange);
            if (session == null) {
                return;
            }
            Map<String, Object> pushed = (Map<String, Object>) session.getAttribute(SESSION_ATTRIBUTE);
            if (pushed == null) {
                pushed = Collections.synchronizedMap(new HashMap<String, Object>());
            }
            for (Map.Entry<String, PushedRequest> entry : toPush.entrySet()) {
                PushedRequest request = entry.getValue();
                Object pushedKey = pushed.get(request.getPath());
                boolean doPush = pushedKey == null;
                if (!doPush) {
                    if (pushedKey instanceof String && !pushedKey.equals(request.getEtag())) {
                        doPush = true;
                    } else if (pushedKey instanceof Long && ((Long) pushedKey) != request.getLastModified()) {
                        doPush = true;
                    }
                }
                if (doPush) {
                    exchange.getConnection().pushResource(request.getPath(), Methods.GET, request.getRequestHeaders());
                    if (request.getEtag() != null) {
                        pushed.put(request.getPath(), request.getEtag());
                    } else {
                        pushed.put(request.getPath(), request.getLastModified());
                    }
                }
            }
            session.setAttribute(SESSION_ATTRIBUTE, pushed);
        }
    }
}
Also used : HashMap(java.util.HashMap) HashMap(java.util.HashMap) HeaderMap(io.undertow.util.HeaderMap) Map(java.util.Map) Session(io.undertow.server.session.Session)

Example 14 with Session

use of io.undertow.server.session.Session in project undertow by undertow-io.

the class LearningPushHandler method getSession.

protected Session getSession(HttpServerExchange exchange) {
    SessionConfig sc = exchange.getAttachment(SessionConfig.ATTACHMENT_KEY);
    SessionManager sm = exchange.getAttachment(SessionManager.ATTACHMENT_KEY);
    if (sc == null || sm == null) {
        return null;
    }
    Session session = sm.getSession(exchange, sc);
    if (session == null) {
        return sm.createSession(exchange, sc);
    }
    return session;
}
Also used : SessionManager(io.undertow.server.session.SessionManager) SessionConfig(io.undertow.server.session.SessionConfig) Session(io.undertow.server.session.Session)

Example 15 with Session

use of io.undertow.server.session.Session in project undertow by undertow-io.

the class HttpServletRequestImpl method changeSessionId.

@Override
public String changeSessionId() {
    HttpSessionImpl session = servletContext.getSession(originalServletContext, exchange, false);
    if (session == null) {
        throw UndertowServletMessages.MESSAGES.noSession();
    }
    String oldId = session.getId();
    Session underlyingSession;
    if (System.getSecurityManager() == null) {
        underlyingSession = session.getSession();
    } else {
        underlyingSession = AccessController.doPrivileged(new HttpSessionImpl.UnwrapSessionAction(session));
    }
    String newId = underlyingSession.changeSessionId(exchange, originalServletContext.getSessionConfig());
    servletContext.getDeployment().getApplicationListeners().httpSessionIdChanged(session, oldId);
    return newId;
}
Also used : HttpString(io.undertow.util.HttpString) Session(io.undertow.server.session.Session) HttpSession(javax.servlet.http.HttpSession)

Aggregations

Session (io.undertow.server.session.Session)33 SessionManager (io.undertow.server.session.SessionManager)19 Test (org.junit.Test)10 HttpServerExchange (io.undertow.server.HttpServerExchange)9 AuthenticatedSession (io.undertow.security.api.AuthenticatedSessionManager.AuthenticatedSession)7 ServletRequestContext (io.undertow.servlet.handlers.ServletRequestContext)7 HttpSessionImpl (io.undertow.servlet.spec.HttpSessionImpl)7 HttpString (io.undertow.util.HttpString)7 HttpHandler (io.undertow.server.HttpHandler)6 InMemorySessionManager (io.undertow.server.session.InMemorySessionManager)6 SessionAttachmentHandler (io.undertow.server.session.SessionAttachmentHandler)6 IOException (java.io.IOException)6 BatchContext (org.wildfly.clustering.ee.BatchContext)6 SessionConfig (io.undertow.server.session.SessionConfig)5 SessionCookieConfig (io.undertow.server.session.SessionCookieConfig)4 TestHttpClient (io.undertow.testutils.TestHttpClient)4 Map (java.util.Map)4 Header (org.apache.http.Header)4 HttpResponse (org.apache.http.HttpResponse)4 HeaderMap (io.undertow.util.HeaderMap)3