diff --git a/backend/src/main/java/com/twtw/backend/config/socket/StompConfig.java b/backend/src/main/java/com/twtw/backend/config/socket/StompConfig.java index fafbd77f..b479852b 100644 --- a/backend/src/main/java/com/twtw/backend/config/socket/StompConfig.java +++ b/backend/src/main/java/com/twtw/backend/config/socket/StompConfig.java @@ -1,7 +1,9 @@ package com.twtw.backend.config.socket; import com.twtw.backend.global.properties.RabbitMQProperties; + import lombok.RequiredArgsConstructor; + import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Profile; import org.springframework.messaging.simp.config.ChannelRegistration; diff --git a/backend/src/main/java/com/twtw/backend/config/socket/StompHandler.java b/backend/src/main/java/com/twtw/backend/config/socket/StompHandler.java index 4d29ca69..aa46cdd6 100644 --- a/backend/src/main/java/com/twtw/backend/config/socket/StompHandler.java +++ b/backend/src/main/java/com/twtw/backend/config/socket/StompHandler.java @@ -1,7 +1,9 @@ package com.twtw.backend.config.socket; import com.twtw.backend.config.security.jwt.TokenProvider; + import lombok.RequiredArgsConstructor; + import org.springframework.core.Ordered; import org.springframework.core.annotation.Order; import org.springframework.messaging.Message; @@ -28,21 +30,26 @@ public Message preSend(final Message message, final MessageChannel channel final StompHeaderAccessor acessor = StompHeaderAccessor.wrap(message); if (StompCommand.CONNECT == acessor.getCommand()) { - final Optional headerValue = Optional.ofNullable(acessor.getFirstNativeHeader(AUTHORIZATION_HEADER)); - resolveToken(headerValue).ifPresent(header -> { - tokenProvider.validateToken(header); - SecurityContextHolder.getContext().setAuthentication(tokenProvider.getAuthentication(header)); - }); + final Optional headerValue = + Optional.ofNullable(acessor.getFirstNativeHeader(AUTHORIZATION_HEADER)); + resolveToken(headerValue) + .ifPresent( + header -> { + tokenProvider.validateToken(header); + SecurityContextHolder.getContext() + .setAuthentication(tokenProvider.getAuthentication(header)); + }); } return message; } private Optional resolveToken(final Optional headerValue) { - return headerValue.map(header -> { - if (header.startsWith(BEARER_PREFIX)) { - return header.substring(7); - } - return header; - }); + return headerValue.map( + header -> { + if (header.startsWith(BEARER_PREFIX)) { + return header.substring(7); + } + return header; + }); } }