Class WebSocketAuthenticationHandshakeInterceptor

java.lang.Object
cn.herodotus.engine.message.websocket.interceptor.WebSocketAuthenticationHandshakeInterceptor
All Implemented Interfaces:
org.springframework.web.socket.server.HandshakeInterceptor

public class WebSocketAuthenticationHandshakeInterceptor extends Object implements org.springframework.web.socket.server.HandshakeInterceptor

Description: WebSocketSessionHandshakeInterceptor

不是开启websocket的必要步骤,根据自身的业务逻辑决定是否添加拦截器

当前主要处理 Token 获取,以及 Token 的验证。如果验证成功,使用返回的用户名进行下一步,如果验证失败返回 false 终止握手。

Author:
: gengwei.zheng
Date:
: 2022/12/4 21:34
  • Constructor Summary

    Constructors
    Constructor
    Description
    WebSocketAuthenticationHandshakeInterceptor(cn.herodotus.engine.assistant.core.support.BearerTokenResolver bearerTokenResolver)
     
  • 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 ex)
     
    boolean
    beforeHandshake(org.springframework.http.server.ServerHttpRequest request, org.springframework.http.server.ServerHttpResponse response, org.springframework.web.socket.WebSocketHandler wsHandler, Map<String,Object> attributes)
     

    Methods inherited from class java.lang.Object

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

    • WebSocketAuthenticationHandshakeInterceptor

      public WebSocketAuthenticationHandshakeInterceptor(cn.herodotus.engine.assistant.core.support.BearerTokenResolver bearerTokenResolver)
  • 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) throws Exception
      Specified by:
      beforeHandshake in interface org.springframework.web.socket.server.HandshakeInterceptor
      Throws:
      Exception
    • afterHandshake

      public void afterHandshake(org.springframework.http.server.ServerHttpRequest request, org.springframework.http.server.ServerHttpResponse response, org.springframework.web.socket.WebSocketHandler wsHandler, Exception ex)
      Specified by:
      afterHandshake in interface org.springframework.web.socket.server.HandshakeInterceptor