From 9789fcd3fa19d824388bfad792d44cebd3c29144 Mon Sep 17 00:00:00 2001 From: 648540858 <648540858@qq.com> Date: Sat, 2 Nov 2024 12:11:52 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=9D=E8=AF=95websocket=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E7=99=BB=E9=99=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../vmp/conf/security/JwtAuthenticationFilter.java | 11 ++++++++++- .../com/genersoft/iot/vmp/conf/webLog/LogChannel.java | 2 -- web_src/src/components/operationsForRealLog.vue | 10 ++++++++-- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/genersoft/iot/vmp/conf/security/JwtAuthenticationFilter.java b/src/main/java/com/genersoft/iot/vmp/conf/security/JwtAuthenticationFilter.java index 21ecfc97..cf44ad2e 100644 --- a/src/main/java/com/genersoft/iot/vmp/conf/security/JwtAuthenticationFilter.java +++ b/src/main/java/com/genersoft/iot/vmp/conf/security/JwtAuthenticationFilter.java @@ -50,11 +50,20 @@ public class JwtAuthenticationFilter extends OncePerRequestFilter { chain.doFilter(request, response); return; } + + + String jwt = request.getHeader(JwtUtils.getHeader()); // 这里如果没有jwt,继续往后走,因为后面还有鉴权管理器等去判断是否拥有身份凭证,所以是可以放行的 // 没有jwt相当于匿名访问,若有一些接口是需要权限的,则不能访问这些接口 + System.out.println("sec-websocket-protocol==" + request.getHeader("sec-websocket-protocol")); if (StringUtils.isBlank(jwt)) { - jwt = request.getParameter(JwtUtils.getHeader()); + String secWebsocketProtocolHeader = request.getHeader("sec-websocket-protocol"); + if (secWebsocketProtocolHeader != null) { + jwt = secWebsocketProtocolHeader; + }else { + jwt = request.getParameter(JwtUtils.getHeader()); + } if (StringUtils.isBlank(jwt)) { jwt = request.getHeader(JwtUtils.getApiKeyHeader()); if (StringUtils.isBlank(jwt)) { diff --git a/src/main/java/com/genersoft/iot/vmp/conf/webLog/LogChannel.java b/src/main/java/com/genersoft/iot/vmp/conf/webLog/LogChannel.java index 6729a142..8396de6d 100644 --- a/src/main/java/com/genersoft/iot/vmp/conf/webLog/LogChannel.java +++ b/src/main/java/com/genersoft/iot/vmp/conf/webLog/LogChannel.java @@ -19,8 +19,6 @@ public class LogChannel { @OnMessage(maxMessageSize = 1) // MaxMessage 1 byte public void onMessage(String message) { - log.debug("Recv Message: {}", message); - try { this.session.close(new CloseReason(CloseReason.CloseCodes.TOO_BIG, "此节点不接收任何客户端信息")); } catch (IOException e) { diff --git a/web_src/src/components/operationsForRealLog.vue b/web_src/src/components/operationsForRealLog.vue index 6771f4b6..a9c3ef1f 100755 --- a/web_src/src/components/operationsForRealLog.vue +++ b/web_src/src/components/operationsForRealLog.vue @@ -13,6 +13,8 @@