-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWebSocketConfig.java
More file actions
49 lines (41 loc) · 2.06 KB
/
WebSocketConfig.java
File metadata and controls
49 lines (41 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package socket_server.common.config;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Configuration;
import org.springframework.messaging.simp.config.ChannelRegistration;
import org.springframework.messaging.simp.config.MessageBrokerRegistry;
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker;
import org.springframework.web.socket.config.annotation.StompEndpointRegistry;
import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer;
import socket_server.common.auth.JwtChannelInterceptor;
import socket_server.common.auth.UserStatusInterceptor;
@Configuration
@EnableWebSocketMessageBroker
@RequiredArgsConstructor
public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {
private static final String ENDPOINT = "/ws-connect";
private final JwtChannelInterceptor jwtChannelInterceptor;
private final UserStatusInterceptor userStatusInterceptor;
@Override
public void configureClientInboundChannel(ChannelRegistration registration) {
registration.interceptors(
jwtChannelInterceptor, // 1. 인증(jwt)
userStatusInterceptor // 2. 인가(정지 계정)
);
}
//레디스 메시지 브로커 사용
@Override
public void configureMessageBroker(MessageBrokerRegistry registry) {
registry.enableSimpleBroker("/sub", "/user"); // 구독 (Subscribe)
registry.setApplicationDestinationPrefixes("/pub"); // 발행 (Publish)
registry.setUserDestinationPrefix("/user");
}
//초기 핸드쉐이크 과정에서 사용할 endpoint
@Override
public void registerStompEndpoints(StompEndpointRegistry registry) {
registry.addEndpoint(ENDPOINT) //https로 변경시 wws로 변경
.setAllowedOriginPatterns("*")
.withSockJS(); // SockJS 지원
registry.addEndpoint(ENDPOINT) //todo : 실제 배포시엔 sockJs만 이용하므로, 해당 코드 삭제 필요
.setAllowedOriginPatterns("*");
}
}