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;
}
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;
}
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);
}
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();
}
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);
}
Aggregations