Skip to content

Commit 25e6a2d

Browse files
committed
StompSubProtocolHandler consistently accesses current user
Issue: SPR-15822
1 parent f397577 commit 25e6a2d

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

spring-websocket/src/main/java/org/springframework/web/socket/messaging/StompSubProtocolHandler.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -258,12 +258,7 @@ else if (webSocketMessage instanceof BinaryMessage) {
258258

259259
headerAccessor.setSessionId(session.getId());
260260
headerAccessor.setSessionAttributes(session.getAttributes());
261-
262-
Principal user = getUser(session);
263-
if (user != null) {
264-
headerAccessor.setUser(user);
265-
}
266-
261+
headerAccessor.setUser(getUser(session));
267262
headerAccessor.setHeader(SimpMessageHeaderAccessor.HEART_BEAT_HEADER, headerAccessor.getHeartbeat());
268263
if (!detectImmutableMessageInterceptor(outputChannel)) {
269264
headerAccessor.setImmutable();
@@ -287,11 +282,13 @@ else if (StompCommand.DISCONNECT.equals(headerAccessor.getCommand())) {
287282

288283
if (sent) {
289284
if (isConnect) {
285+
Principal user = headerAccessor.getUser();
290286
if (user != null && user != session.getPrincipal()) {
291287
this.stompAuthentications.put(session.getId(), user);
292288
}
293289
}
294290
if (this.eventPublisher != null) {
291+
Principal user = getUser(session);
295292
if (isConnect) {
296293
publishEvent(this.eventPublisher, new SessionConnectEvent(this, message, user));
297294
}

0 commit comments

Comments
 (0)