This commit is contained in:
Maximilian Walz
2025-09-16 23:05:31 +02:00
commit adb8ef9c83
30 changed files with 1422 additions and 0 deletions

View 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();
}
}