Class JwtHandshakeInterceptor

java.lang.Object
vaultWeb.config.websocket.JwtHandshakeInterceptor
All Implemented Interfaces:
org.springframework.web.socket.server.HandshakeInterceptor

public class JwtHandshakeInterceptor extends Object implements org.springframework.web.socket.server.HandshakeInterceptor
Intercepts WebSocket handshake requests to perform JWT-based authentication.

Extracts the JWT token from the query parameter "token" or "Authorization" header, validates it, and stores the corresponding Authentication object in attributes. If the token is invalid or missing, the handshake is rejected with HTTP 401.

  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    afterHandshake(org.springframework.http.server.ServerHttpRequest request, org.springframework.http.server.ServerHttpResponse response, org.springframework.web.socket.WebSocketHandler wsHandler, Exception exception)
    Invoked after the handshake is done.
    boolean
    beforeHandshake(org.springframework.http.server.ServerHttpRequest request, org.springframework.http.server.ServerHttpResponse response, org.springframework.web.socket.WebSocketHandler wsHandler, Map<String,Object> attributes)
    Intercepts the handshake request before it is processed.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • JwtHandshakeInterceptor

      public JwtHandshakeInterceptor()
  • Method Details

    • beforeHandshake

      public boolean beforeHandshake(org.springframework.http.server.ServerHttpRequest request, org.springframework.http.server.ServerHttpResponse response, org.springframework.web.socket.WebSocketHandler wsHandler, Map<String,Object> attributes)
      Intercepts the handshake request before it is processed.
      Specified by:
      beforeHandshake in interface org.springframework.web.socket.server.HandshakeInterceptor
      Parameters:
      request - the current HTTP request
      response - the current HTTP response
      wsHandler - the target WebSocket handler
      attributes - attributes shared across the handshake and WebSocket session
      Returns:
      true to proceed with the handshake, false to reject it
    • afterHandshake

      public void afterHandshake(org.springframework.http.server.ServerHttpRequest request, org.springframework.http.server.ServerHttpResponse response, org.springframework.web.socket.WebSocketHandler wsHandler, Exception exception)
      Invoked after the handshake is done. No actions needed here.
      Specified by:
      afterHandshake in interface org.springframework.web.socket.server.HandshakeInterceptor
      Parameters:
      request - the current HTTP request
      response - the current HTTP response
      wsHandler - the target WebSocket handler
      exception - an exception raised during handshake, or null if none