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