Skip to content

Commit 5a66d16

Browse files
pferrarofl4via
authored andcommitted
[UNDERTOW-2523] Add support for HttpSession.getAccessor().
1 parent 47d02fb commit 5a66d16

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

core/src/main/java/io/undertow/server/session/Session.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,4 +189,12 @@ public interface Session {
189189
* @return <ul><li><b>true</b> - if session is no longer valid</li><li><b>false</b> - otherwise</li></ul>
190190
*/
191191
boolean isInvalid();
192+
193+
/**
194+
* Returns a detached view of this session for use outside of request scope.
195+
* @return a detached view of this session for use outside of request scope.
196+
*/
197+
default Session detach() {
198+
return this;
199+
}
192200
}

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@
2323
import java.util.HashSet;
2424
import java.util.Iterator;
2525
import java.util.Set;
26+
import java.util.function.Consumer;
2627

2728
import jakarta.servlet.ServletContext;
2829
import jakarta.servlet.http.HttpSession;
29-
3030
import io.undertow.server.session.Session;
3131
import io.undertow.servlet.UndertowServletMessages;
3232
import io.undertow.servlet.handlers.ServletRequestContext;
@@ -175,6 +175,18 @@ public boolean isNew() {
175175
return newSession;
176176
}
177177

178+
@Override
179+
public Accessor getAccessor() {
180+
Session detached = this.session.detach();
181+
ServletContext context = this.servletContext;
182+
return new Accessor() {
183+
@Override
184+
public void access(Consumer<HttpSession> consumer) {
185+
consumer.accept(new HttpSessionImpl(detached, context, false, null));
186+
}
187+
};
188+
}
189+
178190
@SuppressWarnings("removal")
179191
public Session getSession() {
180192
SecurityManager sm = System.getSecurityManager();

0 commit comments

Comments
 (0)