use of io.undertow.servlet.handlers.ServletRequestContext in project undertow by undertow-io.
the class SessionListenerBridge method sessionDestroyed.
@Override
public void sessionDestroyed(final Session session, final HttpServerExchange exchange, final SessionDestroyedReason reason) {
if (reason == SessionDestroyedReason.TIMEOUT) {
try {
// we need to perform thread setup actions
destroyedAction.call(exchange, session);
} catch (Exception e) {
throw new RuntimeException(e);
}
} else {
doDestroy(session);
}
ServletRequestContext current = SecurityActions.currentServletRequestContext();
Session underlying = null;
if (current != null && current.getSession() != null) {
if (System.getSecurityManager() == null) {
underlying = current.getSession().getSession();
} else {
underlying = AccessController.doPrivileged(new HttpSessionImpl.UnwrapSessionAction(current.getSession()));
}
}
if (current != null && underlying == session) {
current.setSession(null);
}
}
use of io.undertow.servlet.handlers.ServletRequestContext in project undertow by undertow-io.
the class ServletRelativePathAttribute method readAttribute.
@Override
public String readAttribute(final HttpServerExchange exchange) {
ServletRequestContext src = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY);
if (src == null) {
return RequestURLAttribute.INSTANCE.readAttribute(exchange);
}
String path = (String) src.getServletRequest().getAttribute(RequestDispatcher.FORWARD_PATH_INFO);
String sp = (String) src.getServletRequest().getAttribute(RequestDispatcher.FORWARD_SERVLET_PATH);
if (path == null && sp == null) {
return RequestURLAttribute.INSTANCE.readAttribute(exchange);
}
if (sp == null) {
return path;
} else if (path == null) {
return sp;
} else {
return sp + path;
}
}
use of io.undertow.servlet.handlers.ServletRequestContext in project undertow by undertow-io.
the class ServletRequestAttribute method writeAttribute.
@Override
public void writeAttribute(final HttpServerExchange exchange, final String newValue) throws ReadOnlyAttributeException {
ServletRequestContext context = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY);
if (context != null) {
context.getServletRequest().setAttribute(attributeName, newValue);
} else {
Map<String, String> attrs = exchange.getAttachment(HttpServerExchange.REQUEST_ATTRIBUTES);
if (attrs == null) {
exchange.putAttachment(HttpServerExchange.REQUEST_ATTRIBUTES, attrs = new HashMap<>());
}
attrs.put(attributeName, newValue);
}
}
use of io.undertow.servlet.handlers.ServletRequestContext in project keycloak by keycloak.
the class ChangeSessionId method changeSessionId.
public static String changeSessionId(HttpServerExchange exchange, boolean create) {
final ServletRequestContext sc = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY);
ServletContextImpl currentServletContext = sc.getCurrentServletContext();
HttpSessionImpl session = currentServletContext.getSession(exchange, create);
if (session == null) {
return null;
}
Session underlyingSession;
if (System.getSecurityManager() == null) {
underlyingSession = session.getSession();
} else {
underlyingSession = AccessController.doPrivileged(new HttpSessionImpl.UnwrapSessionAction(session));
}
return underlyingSession.changeSessionId(exchange, currentServletContext.getSessionConfig());
}
use of io.undertow.servlet.handlers.ServletRequestContext in project keycloak by keycloak.
the class SavedRequest method trySaveRequest.
public static void trySaveRequest(final HttpServerExchange exchange) {
io.undertow.servlet.util.SavedRequest.trySaveRequest(exchange);
final ServletRequestContext sc = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY);
HttpSessionImpl session = sc.getCurrentServletContext().getSession(exchange, true);
Session underlyingSession;
if (System.getSecurityManager() == null) {
underlyingSession = session.getSession();
} else {
underlyingSession = AccessController.doPrivileged(new HttpSessionImpl.UnwrapSessionAction(session));
}
io.undertow.servlet.util.SavedRequest request = (io.undertow.servlet.util.SavedRequest) underlyingSession.removeAttribute(io.undertow.servlet.util.SavedRequest.class.getName());
if (request != null)
underlyingSession.setAttribute(SESSION_KEY, request);
}
Aggregations