Erweiterungen

This commit is contained in:
2025-08-29 14:43:10 +02:00
parent 4d2ed39275
commit 846b3999f2
5 changed files with 259 additions and 9 deletions

View File

@@ -5,6 +5,7 @@ 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 org.springframework.web.socket.server.support.HttpSessionHandshakeInterceptor;
/**
* WebSocket configuration for STOMP messaging.
@@ -23,15 +24,32 @@ public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {
// Designate the "/app" prefix for messages that are bound to methods
// annotated with @MessageMapping
config.setApplicationDestinationPrefixes("/app");
// Set user destination prefix for user-specific messages
config.setUserDestinationPrefix("/user");
}
@Override
public void registerStompEndpoints(StompEndpointRegistry registry) {
// Register the "/ws" endpoint for WebSocket connections
// withSockJS() enables SockJS fallback options for browsers that don't support WebSocket
registry.addEndpoint("/ws").withSockJS();
// Register the "/ws" endpoint for WebSocket connections with SockJS fallback
registry.addEndpoint("/ws")
.setAllowedOriginPatterns("*")
.addInterceptors(new HttpSessionHandshakeInterceptor())
.withSockJS()
.setHeartbeatTime(25000) // Set heartbeat interval
.setDisconnectDelay(5000) // Set disconnect delay
.setStreamBytesLimit(128 * 1024) // Set stream bytes limit
.setHttpMessageCacheSize(1000) // Set HTTP message cache size
.setSessionCookieNeeded(false); // Disable session cookie requirement
// Also add a plain WebSocket endpoint without SockJS for native WebSocket clients
registry.addEndpoint("/websocket");
// Plain WebSocket endpoint without SockJS for native WebSocket clients (Flutter, mobile apps)
registry.addEndpoint("/websocket")
.setAllowedOriginPatterns("*")
.addInterceptors(new HttpSessionHandshakeInterceptor());
// Additional endpoint specifically for mobile/Flutter clients that might have URL issues
registry.addEndpoint("/stomp")
.setAllowedOriginPatterns("*")
.addInterceptors(new HttpSessionHandshakeInterceptor());
}
}

View File

@@ -37,10 +37,26 @@ public class SecurityConfig extends VaadinWebSecurity {
new AntPathRequestMatcher("/frontend/**"),
new AntPathRequestMatcher("/webjars/**"),
new AntPathRequestMatcher("/h2-console/**"),
new AntPathRequestMatcher("/frontend-es5/**", "/frontend-es6/**")
new AntPathRequestMatcher("/frontend-es5/**", "/frontend-es6/**"),
// WebSocket und STOMP Endpunkte
new AntPathRequestMatcher("/ws/**"),
new AntPathRequestMatcher("/websocket/**"),
new AntPathRequestMatcher("/stomp/**"),
new AntPathRequestMatcher("/app/**"),
new AntPathRequestMatcher("/topic/**"),
new AntPathRequestMatcher("/queue/**")
).permitAll()
);
// CSRF für WebSocket-Endpunkte deaktivieren
http.csrf(csrf -> csrf
.ignoringRequestMatchers(
new AntPathRequestMatcher("/ws/**"),
new AntPathRequestMatcher("/websocket/**"),
new AntPathRequestMatcher("/stomp/**")
)
);
// Delegiere die Basis-Konfiguration an VaadinWebSecurity
// Dies fügt automatisch .anyRequest().authenticated() hinzu
super.configure(http);

View File

@@ -1,4 +1,5 @@
server.port=${PORT:8080}
server.address=0.0.0.0
logging.level.org.atmosphere=warn
spring.mustache.check-template-location=false