Search in sources :

Example 21 with SessionManager

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

the class ServletFormAuthenticationMechanism method storeInitialLocation.

/**
 * This method doesn't save content of request but instead uses data from parameter.
 * This should be used in case that data from request was already read and therefore it is not possible to save them.
 *
 * @param exchange
 * @param bytes
 * @param contentLength
 */
protected void storeInitialLocation(final HttpServerExchange exchange, byte[] bytes, int contentLength) {
    if (!saveOriginalRequest) {
        return;
    }
    final ServletRequestContext servletRequestContext = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY);
    HttpSessionImpl httpSession = servletRequestContext.getCurrentServletContext().getSession(exchange, true);
    Session session;
    if (System.getSecurityManager() == null) {
        session = httpSession.getSession();
    } else {
        session = AccessController.doPrivileged(new HttpSessionImpl.UnwrapSessionAction(httpSession));
    }
    SessionManager manager = session.getSessionManager();
    if (seenSessionManagers.add(manager)) {
        manager.registerSessionListener(LISTENER);
    }
    session.setAttribute(SESSION_KEY, RedirectBuilder.redirect(exchange, exchange.getRelativePath()));
    if (bytes == null) {
        SavedRequest.trySaveRequest(exchange);
    } else {
        SavedRequest.trySaveRequest(exchange, bytes, contentLength);
    }
}
Also used : HttpSessionImpl(io.undertow.servlet.spec.HttpSessionImpl) SessionManager(io.undertow.server.session.SessionManager) ServletRequestContext(io.undertow.servlet.handlers.ServletRequestContext) Session(io.undertow.server.session.Session)

Example 22 with SessionManager

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

the class CachedAuthenticatedSessionHandler method handleRequest.

@Override
public void handleRequest(HttpServerExchange exchange) throws Exception {
    SecurityContext securityContext = exchange.getSecurityContext();
    securityContext.registerNotificationReceiver(NOTIFICATION_RECEIVER);
    SessionManager sessionManager = exchange.getAttachment(SessionManager.ATTACHMENT_KEY);
    SessionConfig sessionConfig = exchange.getAttachment(SessionConfig.ATTACHMENT_KEY);
    if (sessionManager == null || sessionConfig == null) {
        next.handleRequest(exchange);
        return;
    }
    Session session = sessionManager.getSession(exchange, sessionConfig);
    // the AuthenticatedSessionManager.
    if (session != null) {
        exchange.putAttachment(AuthenticatedSessionManager.ATTACHMENT_KEY, SESSION_MANAGER);
    }
    next.handleRequest(exchange);
}
Also used : SessionManager(io.undertow.server.session.SessionManager) AuthenticatedSessionManager(io.undertow.security.api.AuthenticatedSessionManager) SecurityContext(io.undertow.security.api.SecurityContext) SessionConfig(io.undertow.server.session.SessionConfig) Session(io.undertow.server.session.Session) AuthenticatedSession(io.undertow.security.api.AuthenticatedSessionManager.AuthenticatedSession)

Example 23 with SessionManager

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

the class AsyncWebSocketHttpServerExchange method getSession.

@Override
public Object getSession() {
    SessionManager sm = exchange.getAttachment(SessionManager.ATTACHMENT_KEY);
    SessionConfig sessionCookieConfig = exchange.getAttachment(SessionConfig.ATTACHMENT_KEY);
    if (sm != null && sessionCookieConfig != null) {
        return sm.getSession(exchange, sessionCookieConfig);
    }
    return null;
}
Also used : SessionManager(io.undertow.server.session.SessionManager) SessionConfig(io.undertow.server.session.SessionConfig)

Aggregations

SessionManager (io.undertow.server.session.SessionManager)23 Session (io.undertow.server.session.Session)19 Test (org.junit.Test)9 HttpServerExchange (io.undertow.server.HttpServerExchange)8 AuthenticatedSession (io.undertow.security.api.AuthenticatedSessionManager.AuthenticatedSession)7 InMemorySessionManager (io.undertow.server.session.InMemorySessionManager)7 HttpHandler (io.undertow.server.HttpHandler)6 SessionAttachmentHandler (io.undertow.server.session.SessionAttachmentHandler)6 SessionConfig (io.undertow.server.session.SessionConfig)6 BatchContext (org.wildfly.clustering.ee.BatchContext)6 HttpString (io.undertow.util.HttpString)5 IOException (java.io.IOException)5 SessionCookieConfig (io.undertow.server.session.SessionCookieConfig)4 DeploymentManager (io.undertow.servlet.api.DeploymentManager)4 TestHttpClient (io.undertow.testutils.TestHttpClient)4 Header (org.apache.http.Header)4 HttpResponse (org.apache.http.HttpResponse)4 HttpGet (org.apache.http.client.methods.HttpGet)4 DeploymentInfo (io.undertow.servlet.api.DeploymentInfo)3 BasicCookieStore (org.apache.http.impl.client.BasicCookieStore)3