Init
This commit is contained in:
34
src/main/java/de/w665/testing/config/WebSocketConfig.java
Normal file
34
src/main/java/de/w665/testing/config/WebSocketConfig.java
Normal file
@@ -0,0 +1,34 @@
|
||||
package de.w665.testing.config;
|
||||
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
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 de.w665.testing.service.TokenService;
|
||||
|
||||
@Configuration
|
||||
@EnableWebSocketMessageBroker
|
||||
public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {
|
||||
private final TokenService tokenService;
|
||||
|
||||
public WebSocketConfig(TokenService tokenService) {
|
||||
this.tokenService = tokenService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void configureMessageBroker(MessageBrokerRegistry config) {
|
||||
config.enableSimpleBroker("/topic", "/queue");
|
||||
config.setApplicationDestinationPrefixes("/app");
|
||||
config.setUserDestinationPrefix("/user");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerStompEndpoints(StompEndpointRegistry registry) {
|
||||
registry.addEndpoint("/ws")
|
||||
.setAllowedOriginPatterns("*")
|
||||
.addInterceptors(new UsernameHandshakeInterceptor())
|
||||
.setHandshakeHandler(new UsernamePrincipalHandshakeHandler(tokenService))
|
||||
.withSockJS();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user