Skip to content

Commit 9ed4eb9

Browse files
aogburnfl4via
authored andcommitted
[UNDERTOW-2192] session.getServletContext returns wrong context with shared-session-config
1 parent bbb9fee commit 9ed4eb9

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

servlet/src/main/java/io/undertow/servlet/core/SessionListenerBridge.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import io.undertow.servlet.api.ThreadSetupHandler;
3333
import io.undertow.servlet.handlers.ServletRequestContext;
3434
import io.undertow.servlet.spec.HttpSessionImpl;
35+
import io.undertow.servlet.spec.ServletContextImpl;
3536

3637
/**
3738
* Class that bridges between Undertow native session listeners and servlet ones.
@@ -60,7 +61,10 @@ public Void call(HttpServerExchange exchange, Session session) throws ServletExc
6061

6162
@Override
6263
public void sessionCreated(final Session session, final HttpServerExchange exchange) {
63-
final HttpSessionImpl httpSession = SecurityActions.forSession(session, servletContext, true);
64+
ServletContext sc = servletContext;
65+
if (servletContext instanceof ServletContextImpl)
66+
sc = exchange.removeAttachment(((ServletContextImpl) servletContext).contextAttachmentKey);
67+
final HttpSessionImpl httpSession = SecurityActions.forSession(session, sc, true);
6468
applicationListeners.sessionCreated(httpSession);
6569
}
6670

servlet/src/main/java/io/undertow/servlet/spec/ServletContextImpl.java

+2
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ public class ServletContextImpl implements ServletContext {
115115
private final ConcurrentMap<String, Object> attributes;
116116
private final SessionCookieConfigImpl sessionCookieConfig;
117117
private final AttachmentKey<HttpSessionImpl> sessionAttachmentKey = AttachmentKey.create(HttpSessionImpl.class);
118+
public static final AttachmentKey<ServletContextImpl> contextAttachmentKey = AttachmentKey.create(ServletContextImpl.class);
118119
private volatile Set<SessionTrackingMode> sessionTrackingModes = new HashSet<>(Arrays.asList(new SessionTrackingMode[]{SessionTrackingMode.COOKIE, SessionTrackingMode.URL}));
119120
private volatile Set<SessionTrackingMode> defaultSessionTrackingModes = new HashSet<>(Arrays.asList(new SessionTrackingMode[]{SessionTrackingMode.COOKIE, SessionTrackingMode.URL}));
120121
private volatile SessionConfig sessionConfig;
@@ -982,6 +983,7 @@ public String rewriteUrl(String originalUrl, String sessionId) {
982983

983984
try {
984985
if (httpSession == null) {
986+
exchange.putAttachment(contextAttachmentKey, this);
985987
final Session newSession = sessionManager.createSession(exchange, c);
986988
httpSession = SecurityActions.forSession(newSession, this, true);
987989
exchange.putAttachment(sessionAttachmentKey, httpSession);

0 commit comments

Comments
 (0)