From 25e6a2da646c9a465fabf1c73796a1ae01886857 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Thu, 27 Jul 2017 11:32:32 +0200 Subject: [PATCH] StompSubProtocolHandler consistently accesses current user Issue: SPR-15822 --- .../web/socket/messaging/StompSubProtocolHandler.java | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/messaging/StompSubProtocolHandler.java b/spring-websocket/src/main/java/org/springframework/web/socket/messaging/StompSubProtocolHandler.java index e65b8739c0..88dd47bda7 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/messaging/StompSubProtocolHandler.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/messaging/StompSubProtocolHandler.java @@ -258,12 +258,7 @@ public class StompSubProtocolHandler implements SubProtocolHandler, ApplicationE headerAccessor.setSessionId(session.getId()); headerAccessor.setSessionAttributes(session.getAttributes()); - - Principal user = getUser(session); - if (user != null) { - headerAccessor.setUser(user); - } - + headerAccessor.setUser(getUser(session)); headerAccessor.setHeader(SimpMessageHeaderAccessor.HEART_BEAT_HEADER, headerAccessor.getHeartbeat()); if (!detectImmutableMessageInterceptor(outputChannel)) { headerAccessor.setImmutable(); @@ -287,11 +282,13 @@ public class StompSubProtocolHandler implements SubProtocolHandler, ApplicationE if (sent) { if (isConnect) { + Principal user = headerAccessor.getUser(); if (user != null && user != session.getPrincipal()) { this.stompAuthentications.put(session.getId(), user); } } if (this.eventPublisher != null) { + Principal user = getUser(session); if (isConnect) { publishEvent(this.eventPublisher, new SessionConnectEvent(this, message, user)); }