Package vaultWeb.config.websocket
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 -
Method Summary
Modifier and TypeMethodDescriptionvoidafterHandshake(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.booleanbeforeHandshake(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.
-
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:
beforeHandshakein interfaceorg.springframework.web.socket.server.HandshakeInterceptor- Parameters:
request- the current HTTP requestresponse- the current HTTP responsewsHandler- the target WebSocket handlerattributes- 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:
afterHandshakein interfaceorg.springframework.web.socket.server.HandshakeInterceptor- Parameters:
request- the current HTTP requestresponse- the current HTTP responsewsHandler- the target WebSocket handlerexception- an exception raised during handshake, or null if none
-