0Pricing
WebSockets & Real-Time Systems with Spring · Ders

Spring Security ile STOMP Uç Noktalarını Güvenceye Alma

Spring'de STOMP iletilerinin kimliğini doğrulamayı ve yetkilendirmeyi öğrenin; el sıkışmayı, hedefleri ve kullanıcı başına iletileri yetkisiz erişime karşı güvenceye alın.

Spring Security ile STOMP Uç Noktalarını Güvenceye Alma, CoddyKit'te ücretsiz bir WebSockets & Real-Time Systems with Spring dersidir. Bu, 4 dersinin 4. dersidir. Aşağıdan dersin tamamını ücretsiz okuyabilir, sonra tarayıcıda yerleşik kod editörü ve 7/24 yapay zeka koçu ile uygulamalı olarak pratik yapabilirsin. Bu, WebSockets & Real-Time Systems with Spring öğrenme yolunun bir parçasıdır ve ilerlemeniz web ve CoddyKit uygulaması arasında senkronize olur. WebSockets & Real-Time Systems with Spring kursu toplamda 4 dersten oluşur.

Bu dersin bazı bölümleri henüz çevrilmemiş olup İngilizce olarak gösterilmektedir.

Why Secure STOMP?

An open STOMP endpoint lets anyone subscribe to and publish on any destination. Securing STOMP ensures only authenticated users connect and only authorized users access specific destinations.

This lesson layers Spring Security onto STOMP messaging.

Two Layers of Security

STOMP security operates at two levels:

  • Handshake: authenticate the user when the WebSocket connection opens
  • Message: authorize each SUBSCRIBE and SEND to a destination

Both layers are needed for real protection.

Authenticating the Handshake

The connection should carry the user's identity. With session-based auth, Spring Security propagates the HTTP session principal into the WebSocket session automatically.

Token Auth on CONNECT

For token-based auth, read the token from the STOMP CONNECT frame headers using a ChannelInterceptor and set the authenticated principal on the message.

@Override
public Message<?> preSend(Message<?> message, MessageChannel channel) {
    StompHeaderAccessor acc = StompHeaderAccessor.wrap(message);
    if (StompCommand.CONNECT.equals(acc.getCommand())) {
        String token = acc.getFirstNativeHeader('Authorization');
        Authentication user = tokenService.validate(token);
        acc.setUser(user);
    }
    return message;
}

Authorizing Destinations

Spring provides AbstractSecurityWebSocketMessageBrokerConfigurer to define which roles may access which destinations, similar to HTTP security rules.

@Override
protected void configureInbound(MessageSecurityMetadataSourceRegistry messages) {
    messages
        .simpDestMatchers('/app/admin/**').hasRole('ADMIN')
        .simpSubscribeDestMatchers('/topic/public').permitAll()
        .anyMessage().authenticated();
}

Per-User Destinations

The /user/** prefix routes messages to a single user's private queue. Spring resolves these against the authenticated principal, so users only receive their own messages.

// Server side: send to a specific user
messagingTemplate.convertAndSendToUser(
    username, '/queue/notifications', payload);

CSRF Considerations

The WebSocket handshake is an HTTP request and can be subject to CSRF. Validate origins and, where applicable, require a CSRF token so attackers cannot open connections from malicious pages.

Restricting Origins

Always lock down allowed origins for the STOMP endpoint. An open origin policy lets any website connect on behalf of a logged-in user.

@Override
public void registerStompEndpoints(StompEndpointRegistry registry) {
    registry.addEndpoint('/ws')
            .setAllowedOrigins('https://app.example.com')
            .withSockJS();
}

Validating Message Payloads

Authentication is not enough; validate the content of every message. Reject oversized payloads, unexpected fields, and malformed data to prevent injection and resource exhaustion.

  • Enforce size limits
  • Validate against a schema
  • Reject unknown destinations

Logging Security Events

Log failed connections, denied subscriptions, and authorization failures. These events feed monitoring and help detect abuse or probing of your messaging layer.

Defense in Depth

Combine handshake auth, destination authorization, origin restriction, and payload validation. No single control is sufficient; layered controls keep your real-time messaging secure even if one fails.

Quick Check

Test your understanding of STOMP security.

Recap

You learned to secure STOMP at two layers: authenticate the handshake (session or token), then authorize destinations with Spring Security rules. Per-user destinations, origin restrictions, payload validation, and event logging together provide defense in depth for real-time messaging.

Sıkça Sorulan Sorular

“Spring Security ile STOMP Uç Noktalarını Güvenceye Alma” dersi ücretsiz mi?

Evet — “Spring Security ile STOMP Uç Noktalarını Güvenceye Alma” dersin tüm metni burada web'de ücretsiz olarak okunabilir. Etkileşimli olarak pratik yapmak (yerleşik kod editörü ve 7/24 yapay zeka koçu) ve WebSockets & Real-Time Systems with Spring kursunun geri kalanını açmak için CoddyKit PRO'ya yükselt. WebSockets & Real-Time Systems with Spring kursu toplamda 4 dersten oluşur.

“Spring Security ile STOMP Uç Noktalarını Güvenceye Alma” dersinde ne öğreneceğim?

Spring'de STOMP iletilerinin kimliğini doğrulamayı ve yetkilendirmeyi öğrenin; el sıkışmayı, hedefleri ve kullanıcı başına iletileri yetkisiz erişime karşı güvenceye alın. WebSockets & Real-Time Systems with Spring ile uygulamalı kodu tarayıcıda doğrudan çalıştırarak pratik yaparsın ve 7/24 yapay zeka koçu dersi çalışırken sorularını yanıtlar.

WebSockets & Real-Time Systems with Spring öğrenmeye başlamak için deneyim gerekli mi?

Önceden deneyim gerekmez. CoddyKit'te WebSockets & Real-Time Systems with Spring, başlangıçtan ileri seviyeye kadar yapılandırıldığı için buradan başlayabilir veya başından başlayıp kendi hızında ilerleme yapabilirsin. Bu, 4 dersinin 4. dersidir.

“Spring Security ile STOMP Uç Noktalarını Güvenceye Alma” dersi ne kadar sürer?

Çoğu CoddyKit dersi yaklaşık 5–10 dakika sürer. Her biri kısa ve etkileşimli olduğu için sabit ilerleme yaparsın ve web ile uygulama arasında tam olarak bıraktığın yerden devam edebilirsin.

Bu WebSockets & Real-Time Systems with Spring dersinde kod yazıp çalıştırabilir miyim?

Evet. Her WebSockets & Real-Time Systems with Spring dersi yerleşik bir kod editörü içerir, bu sayede tarayıcıda gerçek kod yazıp çalıştırabilir ve anlık yapay zeka geri bildirimi alırsın — yerel kurulum gerekli değildir.

Bu kursun tüm dersleri

  1. STOMP Protokolüne Giriş
  2. STOMP'u Spring ile Yapılandırma
  3. STOMP Mesajlarını Gönderme ve Alma
  4. Spring Security ile STOMP Uç Noktalarını Güvenceye Alma
← WebSockets & Real-Time Systems with Spring Sayfasına Dön