根据上篇文章继续
Java SpringBoot集成WebSocket
修改内容
在WebSocketInterceptor拦截器中修改
/*** 在握手之前 可用于权限认证** @param serverHttpRequest 服务器http请求* @param serverHttpResponse 服务器http响应* @param webSocketHandler 网络套接字处理程序* @param map 地图* @return boolean* @throws Exception 异常*/@Overridepublic boolean beforeHandshake(ServerHttpRequest serverHttpRequest, ServerHttpResponse serverHttpResponse, WebSocketHandler webSocketHandler, Map<String, Object> map) throws Exception {log.info("握手之前");Map<String, String> headers = serverHttpRequest.getHeaders().toSingleValueMap();log.info("所有请求头信息:Header parameters: {}", headers);String authorization = headers.get("Authorization");if (CharSequenceUtil.isBlank(authorization)) {// 未传入tokenreturn false;}// 根据框架进行自行根据token校验是否有效return true;}