Skip to content

An example application made to use a socket and send messages to the frontend through a channel with authorization that supports the session for users

Notifications You must be signed in to change notification settings

RogerMontana/secured-socket-soket-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

socket-stomp-example

An example application made to use a socket and send messages to the frontend through a channel with authorization that supports the session for users

Technology stack

Front-end
  • Using SockJS over socket connection on UI
  • STOMP as messaging protocol
Back-end
  • Using Spring Messaging
  • Using SockJS over socket connection
  • STOMP protocol as standard for transferring data
LINKS

SOCKET CONNECTION DIAGRAM

  • WebSocketMessageBrokers - configuration for messaging and endpoint
  • WebSocketConfig - registration for socket (message broker and stomp endpoint )
  • ChatController - client endpoints

SECURITY

Common Connection flow

 ┌──────┐                                                                   ┌───────┐
 │UI_APP│                                                                   │SERVICE│
 └──┬───┘                                                                   └───┬───┘
    │                         do http handshake (/info)                         │    
    │ ──────────────────────────────────────────────────────────────────────────>    
    │                                                                           │    
    │                 provide info about WebSocketMessageBrokers                │    
    │ <──────────────────────────────────────────────────────────────────────────    
    │                                                                           │    
    │  esteblish connection on endpoint "/greeting-websocket" (WebSocketConfig) │    
    │ ──────────────────────────────────────────────────────────────────────────>    
    │                                                                           │    
    │        subscribe on "/user/queue/topic/greetings" (WebSocketConfig)       │    
    │ <──────────────────────────────────────────────────────────────────────────    
    │                                                                           │    
    │               send message to "/app/hello" (ChatController)               │    
    │ ──────────────────────────────────────────────────────────────────────────>    
    │                                                                           │    
    │ send message to session to "/user/queue/topic/greetings" (WebSocketConfig)│    
    │ <──────────────────────────────────────────────────────────────────────────    
 ┌──┴───┐                                                                   ┌───┴───┐
 │UI_APP│                                                                   │SERVICE│
 └──────┘                                                                   └───────┘

security components diagram (intreception security flow from http to socket channel):

┌─────────────┐          ┌───────────────────────────────┐               ┌─────────────────────────────┐          ┌─────────────────────────────┐
│     UI      │          │HttpSessionHandshakeInterceptor│               │AuthChannelInterceptorAdapter│          │WebSocketAuthenticatorService│
└──────┬──────┘          └───────────────┬───────────────┘               └──────────────┬──────────────┘          └──────────────┬──────────────┘
       │                                 │                                              │                                        │               
       |                                 │                                              │                                        │               
       │                                 │                                              │                                        │               
       │    sending request over http    │                                              │                                        │               
       │ ────────────────────────────────>                                              │                                        │               
       │                                 │                                              │                                        │               
       │                                 │────┐                                                                                  │               
       │                                 │    │ get auth header and put in socket channel                                        │               
       │                                 │<───┘                                                                                  │               
       │                                 │                                              │                                        │               
       │                                 │     intrecept and getSessionAttributes()     │                                        │               
       │                                 │ ─────────────────────────────────────────────>                                        │               
       │                                 │                                              │                                        │               
       │                                 │                                              │  validate token allow esteblish socket │               
       │                                 │                                              │ ───────────────────────────────────────>               
┌──────┴──────┐          ┌───────────────┴───────────────┐               ┌──────────────┴──────────────┐          ┌──────────────┴──────────────┐
│     UI      │          │HttpSessionHandshakeInterceptor│               │AuthChannelInterceptorAdapter│          │WebSocketAuthenticatorService│
└─────────────┘          └───────────────────────────────┘               └─────────────────────────────┘          └─────────────────────────────┘

About

An example application made to use a socket and send messages to the frontend through a channel with authorization that supports the session for users

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published