11package com .back .global .config ;
22
33import org .springframework .context .annotation .Configuration ;
4+ import org .springframework .messaging .simp .config .ChannelRegistration ;
45import org .springframework .messaging .simp .config .MessageBrokerRegistry ;
56import org .springframework .web .socket .config .annotation .EnableWebSocketMessageBroker ;
67import org .springframework .web .socket .config .annotation .StompEndpointRegistry ;
78import org .springframework .web .socket .config .annotation .WebSocketMessageBrokerConfigurer ;
89
10+ import com .back .global .properties .SiteProperties ;
11+ import com .back .global .websocket .auth .WebSocketAuthInterceptor ;
12+
13+ import lombok .RequiredArgsConstructor ;
14+
915@ Configuration
1016@ EnableWebSocketMessageBroker
17+ @ RequiredArgsConstructor
1118public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {
1219
20+ private final WebSocketAuthInterceptor webSocketAuthInterceptor ;
21+ private final SiteProperties siteProperties ;
22+
1323 @ Override
1424 public void configureMessageBroker (MessageBrokerRegistry registry ) {
1525
@@ -18,6 +28,9 @@ public void configureMessageBroker(MessageBrokerRegistry registry) {
1828
1929 //클라이언트 발행 경로
2030 registry .setApplicationDestinationPrefixes ("/app" );
31+
32+ // 특정 유저에게 메시지 보낼 때 사용할 prefix
33+ registry .setUserDestinationPrefix ("/user" );
2134 }
2235
2336 @ Override
@@ -26,6 +39,13 @@ public void registerStompEndpoints(StompEndpointRegistry registry) {
2639 //Websocket/stomp 연결 endpoint
2740 registry .addEndpoint ("/ws" )
2841 .setAllowedOriginPatterns ("*" )
42+ // .setAllowedOrigins(siteProperties.getFrontUrl()) 프론트 배포 후 변경
2943 .withSockJS ();
3044 }
45+
46+ @ Override
47+ public void configureClientInboundChannel (ChannelRegistration registration ) {
48+ registration .interceptors (webSocketAuthInterceptor );
49+ }
50+
3151}
0 commit comments