Skip to content

Commit cd67010

Browse files
committed
Update Principal check in TransportHandlingSockJsService
Closes gh-35753
1 parent 585b4e0 commit cd67010

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/TransportHandlingSockJsService.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -303,10 +303,15 @@ else if (transportType.supportsCors()) {
303303
}
304304
else {
305305
Principal principal = session.getPrincipal();
306-
if (principal != null && !principal.equals(request.getPrincipal())) {
307-
logger.debug("The user for the session does not match the user for the request.");
308-
response.setStatusCode(HttpStatus.NOT_FOUND);
309-
return;
306+
if (principal != null) {
307+
// Compare usernames, not full equality (different login timestamps)
308+
Principal currentPrincipal = request.getPrincipal();
309+
if (!principal.equals(currentPrincipal) &&
310+
(currentPrincipal == null || !principal.getName().equals(currentPrincipal.getName()))) {
311+
logger.debug("The user for the session does not match the user for the request.");
312+
response.setStatusCode(HttpStatus.NOT_FOUND);
313+
return;
314+
}
310315
}
311316
if (!transportHandler.checkSessionType(session)) {
312317
logger.debug("Session type does not match the transport type for the request.");

0 commit comments

Comments
 (0)