Search in sources :

Example 1 with SessionConfig

use of io.undertow.server.session.SessionConfig 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 2 with SessionConfig

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

the class Sessions method getSession.

private static Session getSession(final HttpServerExchange exchange, boolean create) {
    SessionManager sessionManager = exchange.getAttachment(SessionManager.ATTACHMENT_KEY);
    SessionConfig sessionConfig = exchange.getAttachment(SessionConfig.ATTACHMENT_KEY);
    if (sessionManager == null) {
        throw UndertowMessages.MESSAGES.sessionManagerNotFound();
    }
    Session session = sessionManager.getSession(exchange, sessionConfig);
    if (session == null && create) {
        session = sessionManager.createSession(exchange, sessionConfig);
    }
    return session;
}
Also used : SessionManager(io.undertow.server.session.SessionManager) SessionConfig(io.undertow.server.session.SessionConfig) Session(io.undertow.server.session.Session)

Example 3 with SessionConfig

use of io.undertow.server.session.SessionConfig in project wildfly by wildfly.

the class DistributableSessionManagerTestCase method createSessionSpecifiedSessionId.

@Test
public void createSessionSpecifiedSessionId() {
    HttpServerExchange exchange = new HttpServerExchange(null);
    Batcher<Batch> batcher = mock(Batcher.class);
    Batch batch = mock(Batch.class);
    SessionConfig config = mock(SessionConfig.class);
    Session<LocalSessionContext> session = mock(Session.class);
    String sessionId = "session";
    when(config.findSessionId(exchange)).thenReturn(sessionId);
    when(this.manager.createSession(sessionId)).thenReturn(session);
    when(this.manager.getBatcher()).thenReturn(batcher);
    when(batcher.createBatch()).thenReturn(batch);
    when(session.getId()).thenReturn(sessionId);
    io.undertow.server.session.Session sessionAdapter = this.adapter.createSession(exchange, config);
    assertNotNull(sessionAdapter);
    verify(this.listener).sessionCreated(sessionAdapter, exchange);
    verify(batcher).suspendBatch();
    verify(this.statistics).record(sessionAdapter);
    String expected = "expected";
    when(session.getId()).thenReturn(expected);
    String result = sessionAdapter.getId();
    assertSame(expected, result);
}
Also used : HttpServerExchange(io.undertow.server.HttpServerExchange) Batch(org.wildfly.clustering.ee.Batch) SessionConfig(io.undertow.server.session.SessionConfig) Test(org.junit.Test)

Example 4 with SessionConfig

use of io.undertow.server.session.SessionConfig in project wildfly by wildfly.

the class DistributableSessionManagerTestCase method createSessionAlreadyExists.

@Test
public void createSessionAlreadyExists() {
    HttpServerExchange exchange = new HttpServerExchange(null);
    Batcher<Batch> batcher = mock(Batcher.class);
    Batch batch = mock(Batch.class);
    SessionConfig config = mock(SessionConfig.class);
    String sessionId = "session";
    when(config.findSessionId(exchange)).thenReturn(sessionId);
    when(this.manager.createSession(sessionId)).thenReturn(null);
    when(this.manager.getBatcher()).thenReturn(batcher);
    when(batcher.createBatch()).thenReturn(batch);
    IllegalStateException exception = null;
    try {
        this.adapter.createSession(exchange, config);
    } catch (IllegalStateException e) {
        exception = e;
    }
    assertNotNull(exception);
    verify(batch).discard();
    verify(batch).close();
}
Also used : HttpServerExchange(io.undertow.server.HttpServerExchange) Batch(org.wildfly.clustering.ee.Batch) SessionConfig(io.undertow.server.session.SessionConfig) Test(org.junit.Test)

Example 5 with SessionConfig

use of io.undertow.server.session.SessionConfig 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)

Aggregations

SessionConfig (io.undertow.server.session.SessionConfig)16 HttpServerExchange (io.undertow.server.HttpServerExchange)10 Test (org.junit.Test)8 SessionManager (io.undertow.server.session.SessionManager)6 Batch (org.wildfly.clustering.ee.Batch)6 Session (io.undertow.server.session.Session)5 AuthenticatedSession (io.undertow.security.api.AuthenticatedSessionManager.AuthenticatedSession)3 PathParameterSessionConfig (io.undertow.server.session.PathParameterSessionConfig)2 SslSessionConfig (io.undertow.server.session.SslSessionConfig)2 Map (java.util.Map)2 BatchContext (org.wildfly.clustering.ee.BatchContext)2 Undertow (io.undertow.Undertow)1 AuthenticatedSessionManager (io.undertow.security.api.AuthenticatedSessionManager)1 SecurityContext (io.undertow.security.api.SecurityContext)1 HttpHandler (io.undertow.server.HttpHandler)1 PathHandler (io.undertow.server.handlers.PathHandler)1 InMemorySessionManager (io.undertow.server.session.InMemorySessionManager)1 SessionAttachmentHandler (io.undertow.server.session.SessionAttachmentHandler)1 SessionCookieConfig (io.undertow.server.session.SessionCookieConfig)1 SessionListener (io.undertow.server.session.SessionListener)1