• 若依框架集成WebSocket带用户信息认证


    一、WebSocket 基础知识

          我们平时前后台请求用的最多的就是 HTTP/1.1协议,它有一个缺陷, 通信只能由客户端发起,如果想要不断获取服务器信息就要不断轮询发出请求,那么如果我们需要服务器状态变化的时候能够主动通知客户端就需要用到WebSocket了, WebSocket是一种网络传输协议,同样也位于 OSI 模型的应用层,建立在传输层协议TCP之上。主要特点是 全双工 通信允许数据在两个方向上同时传输,它在能力上相当于两个单工通信方式的结合 例如指 A→B 的同时 B→A ,是瞬时同步的 二进制帧 采用了二进制帧结构,语法、语义与 HTTP 完全不兼容
            相比 http/2,WebSocket 更侧重于“实时通信”,而 HTTP/2 更侧重于提高传输效率,所以两者的帧结构也有很大的区别 不像 HTTP/2 那样定义流,也就不存在多路复用、优先级等特性 自身就是全双工,也不需要服务器推送 协议名 引入 ws 和 wss 分别代表明文和密文的 websocket 协议,且默认端口使用 80 或 443,几乎与 http 一致
        如果只是服务单纯的向客户端推送消息,不涉及到客户端发送消息到服务端,也可以使用Spring WebFlux技术实现,直接建立在当前http连接上,本质上是保持一个http长连接,适合 简单的服务器数据推送的场景,使用服务器推送事件,更轻量更便捷
    ps:关于OSI七层模型可以看我的另一篇文章https://stronger.blog.csdn.net/article/details/127725957

    二、若依框架集成WebSocket

    在若依代码仓库gitee上的Issues,多次有人提到这个事,例如
    作者也在里面明确表示不会将WebSocket集成到框架里来,将会以扩展插件的形式给出,传送门 若依网址 下载作者网盘代码大致如下
    配置类WebSocketConfig
    1. import org.springframework.context.annotation.Bean;
    2. import org.springframework.context.annotation.Configuration;
    3. import org.springframework.web.socket.server.standard.ServerEndpointExporter;
    4. /**
    5. * websocket 配置
    6. *
    7. * @author ruoyi
    8. */
    9. @Configuration
    10. public class WebSocketConfig
    11. {
    12. @Bean
    13. public ServerEndpointExporter serverEndpointExporter()
    14. {
    15. return new ServerEndpointExporter();
    16. }
    17. }

    工具类 SemaphoreUtils

    1. import java.util.concurrent.Semaphore;
    2. import org.slf4j.Logger;
    3. import org.slf4j.LoggerFactory;
    4. /**
    5. * 信号量相关处理
    6. *
    7. * @author ruoyi
    8. */
    9. public class SemaphoreUtils{
    10. /**
    11. * SemaphoreUtils 日志控制器
    12. */
    13. private static final Logger LOGGER = LoggerFactory.getLogger(SemaphoreUtils.class);
    14. /**
    15. * 获取信号量
    16. *
    17. * @param semaphore
    18. * @return
    19. */
    20. public static boolean tryAcquire(Semaphore semaphore)
    21. {
    22. boolean flag = false;
    23. try
    24. {
    25. flag = semaphore.tryAcquire();
    26. }
    27. catch (Exception e)
    28. {
    29. LOGGER.error("获取信号量异常", e);
    30. }
    31. return flag;
    32. }
    33. /**
    34. * 释放信号量
    35. *
    36. * @param semaphore
    37. */
    38. public static void release(Semaphore semaphore)
    39. {
    40. try
    41. {
    42. semaphore.release();
    43. }
    44. catch (Exception e)
    45. {
    46. LOGGER.error("释放信号量异常", e);
    47. }
    48. }
    49. }

    服务端类WebSocketServer

    1. import java.util.concurrent.Semaphore;
    2. import javax.websocket.OnClose;
    3. import javax.websocket.OnError;
    4. import javax.websocket.OnMessage;
    5. import javax.websocket.OnOpen;
    6. import javax.websocket.Session;
    7. import javax.websocket.server.ServerEndpoint;
    8. import com.lxh.demo.util.SemaphoreUtils;
    9. import org.slf4j.Logger;
    10. import org.slf4j.LoggerFactory;
    11. import org.springframework.stereotype.Component;
    12. /**
    13. * websocket 消息处理
    14. *
    15. * @author ruoyi
    16. */
    17. @Component
    18. @ServerEndpoint("/websocket/message")
    19. public class WebSocketServer
    20. {
    21. /**
    22. * WebSocketServer 日志控制器
    23. */
    24. private static final Logger LOGGER = LoggerFactory.getLogger(WebSocketServer.class);
    25. /**
    26. * 默认最多允许同时在线人数100
    27. */
    28. public static int socketMaxOnlineCount = 100;
    29. private static Semaphore socketSemaphore = new Semaphore(socketMaxOnlineCount);
    30. /**
    31. * 连接建立成功调用的方法
    32. */
    33. @OnOpen
    34. public void onOpen(Session session) throws Exception{
    35. boolean semaphoreFlag = false;
    36. // 尝试获取信号量
    37. semaphoreFlag = SemaphoreUtils.tryAcquire(socketSemaphore);
    38. if (!semaphoreFlag)
    39. {
    40. // 未获取到信号量
    41. LOGGER.error("\n 当前在线人数超过限制数- {}", socketMaxOnlineCount);
    42. WebSocketUsers.sendMessageToUserByText(session, "当前在线人数超过限制数:" + socketMaxOnlineCount);
    43. session.close();
    44. }
    45. else
    46. {
    47. // 添加用户
    48. WebSocketUsers.put(session.getId(), session);
    49. LOGGER.info("\n 建立连接 - {}", session);
    50. LOGGER.info("\n 当前人数 - {}", WebSocketUsers.getUsers().size());
    51. WebSocketUsers.sendMessageToUserByText(session, "连接成功");
    52. }
    53. }
    54. /**
    55. * 连接关闭时处理
    56. */
    57. @OnClose
    58. public void onClose(Session session)
    59. {
    60. LOGGER.info("\n 关闭连接 - {}", session);
    61. // 移除用户
    62. WebSocketUsers.remove(session.getId());
    63. // 获取到信号量则需释放
    64. SemaphoreUtils.release(socketSemaphore);
    65. }
    66. /**
    67. * 抛出异常时处理
    68. */
    69. @OnError
    70. public void onError(Session session, Throwable exception) throws Exception
    71. {
    72. if (session.isOpen())
    73. {
    74. // 关闭连接
    75. session.close();
    76. }
    77. String sessionId = session.getId();
    78. LOGGER.info("\n 连接异常 - {}", sessionId);
    79. LOGGER.info("\n 异常信息 - {}", exception);
    80. // 移出用户
    81. WebSocketUsers.remove(sessionId);
    82. // 获取到信号量则需释放
    83. SemaphoreUtils.release(socketSemaphore);
    84. }
    85. /**
    86. * 服务器接收到客户端消息时调用的方法
    87. */
    88. @OnMessage
    89. public void onMessage(String message, Session session)
    90. {
    91. String msg = message.replace("你", "我").replace("吗", "");
    92. WebSocketUsers.sendMessageToUserByText(session, msg);
    93. }
    94. }

    WebSocketUsers工具类

    1. import java.io.IOException;
    2. import java.util.Collection;
    3. import java.util.Map;
    4. import java.util.Set;
    5. import java.util.concurrent.ConcurrentHashMap;
    6. import javax.websocket.Session;
    7. import org.slf4j.Logger;
    8. import org.slf4j.LoggerFactory;
    9. /**
    10. * websocket 客户端用户集
    11. *
    12. * @author ruoyi
    13. */
    14. public class WebSocketUsers
    15. {
    16. /**
    17. * WebSocketUsers 日志控制器
    18. */
    19. private static final Logger LOGGER = LoggerFactory.getLogger(WebSocketUsers.class);
    20. /**
    21. * 用户集
    22. */
    23. private static Map USERS = new ConcurrentHashMap();
    24. /**
    25. * 存储用户
    26. *
    27. * @param key 唯一键
    28. * @param session 用户信息
    29. */
    30. public static void put(String key, Session session)
    31. {
    32. USERS.put(key, session);
    33. }
    34. /**
    35. * 移除用户
    36. *
    37. * @param session 用户信息
    38. *
    39. * @return 移除结果
    40. */
    41. public static boolean remove(Session session)
    42. {
    43. String key = null;
    44. boolean flag = USERS.containsValue(session);
    45. if (flag)
    46. {
    47. Set> entries = USERS.entrySet();
    48. for (Map.Entry entry : entries)
    49. {
    50. Session value = entry.getValue();
    51. if (value.equals(session))
    52. {
    53. key = entry.getKey();
    54. break;
    55. }
    56. }
    57. }
    58. else
    59. {
    60. return true;
    61. }
    62. return remove(key);
    63. }
    64. /**
    65. * 移出用户
    66. *
    67. * @param key 键
    68. */
    69. public static boolean remove(String key)
    70. {
    71. LOGGER.info("\n 正在移出用户 - {}", key);
    72. Session remove = USERS.remove(key);
    73. if (remove != null)
    74. {
    75. boolean containsValue = USERS.containsValue(remove);
    76. LOGGER.info("\n 移出结果 - {}", containsValue ? "失败" : "成功");
    77. return containsValue;
    78. }
    79. else
    80. {
    81. return true;
    82. }
    83. }
    84. /**
    85. * 获取在线用户列表
    86. *
    87. * @return 返回用户集合
    88. */
    89. public static Map getUsers()
    90. {
    91. return USERS;
    92. }
    93. /**
    94. * 群发消息文本消息
    95. *
    96. * @param message 消息内容
    97. */
    98. public static void sendMessageToUsersByText(String message)
    99. {
    100. Collection values = USERS.values();
    101. for (Session value : values)
    102. {
    103. sendMessageToUserByText(value, message);
    104. }
    105. }
    106. /**
    107. * 发送文本消息
    108. *
    109. * @param session 缓存
    110. * @param message 消息内容
    111. */
    112. public static void sendMessageToUserByText(Session session, String message)
    113. {
    114. if (session != null)
    115. {
    116. try
    117. {
    118. session.getBasicRemote().sendText(message);
    119. }
    120. catch (IOException e)
    121. {
    122. LOGGER.error("\n[发送消息异常]", e);
    123. }
    124. }
    125. else
    126. {
    127. LOGGER.info("\n[你已离线]");
    128. }
    129. }
    130. }

    Html 页面代码

    1. html>
    2. <html lang="zh" xmlns:th="http://www.thymeleaf.org">
    3. <head>
    4. <meta charset="utf-8">
    5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
    6. <title>测试界面title>
    7. head>
    8. <body>
    9. <div>
    10. <input type="text" style="width: 20%" value="ws://127.0.0.1/websocket/message" id="url">
    11. <button id="btn_join">连接button>
    12. <button id="btn_exit">断开button>
    13. div>
    14. <br/>
    15. <textarea id="message" cols="100" rows="9">textarea> <button id="btn_send">发送消息button>
    16. <br/>
    17. <br/>
    18. <textarea id="text_content" readonly="readonly" cols="100" rows="9">textarea>返回内容
    19. <br/>
    20. <br/>
    21. <script th:src="@{/js/jquery.min.js}" >script>
    22. <script type="text/javascript">
    23. $(document).ready(function(){
    24. var ws = null;
    25. // 连接
    26. $('#btn_join').click(function() {
    27. var url = $("#url").val();
    28. ws = new WebSocket(url);
    29. ws.onopen = function(event) {
    30. $('#text_content').append('已经打开连接!' + '\n');
    31. }
    32. ws.onmessage = function(event) {
    33. $('#text_content').append(event.data + '\n');
    34. }
    35. ws.onclose = function(event) {
    36. $('#text_content').append('已经关闭连接!' + '\n');
    37. }
    38. });
    39. // 发送消息
    40. $('#btn_send').click(function() {
    41. var message = $('#message').val();
    42. if (ws) {
    43. ws.send(message);
    44. } else {
    45. alert("未连接到服务器");
    46. }
    47. });
    48. //断开
    49. $('#btn_exit').click(function() {
    50. if (ws) {
    51. ws.close();
    52. ws = null;
    53. }
    54. });
    55. })
    56. script>
    57. body>
    58. html>

    成功运行后,页面如下

    注意此时没有走用户认证,那么就要对路径放行,因为若依框架用的是SpringSecurity,所以找到文件SecurityConfig.java ,进行路径放行

    三、用户认证问题

    虽然按着上述步骤我们完成了浏览器(客户端)和Java(服务端)的WebSocket通信,但是我们不能限定哪些用户可以连接我们的服务端获取数据,服务端也不知道应该具体给哪些用户发送消息,在我们框架之前交互我们是通过浏览器传递toke 值来实现用户身份确认的,那么我们的WebSocket可不可以也这样呢?

    很不幸的是 ws连接是无法像http一样完全自主定义请求头的,给token认证带来了不便,我们大致可以通过以下集中方式完成用户认证

    1、将 token 明文携带在 url 中,例如ws://localhost:8080/weggo/websocket/message?Authorization=Bearer+token

    2、通过websocket下的子协议来实现,Stomp这个协议来实现,前端采用SocketJs框架来实现对应定制请求头。实现携带authorization=Bearer +token 的需求,这样就可以正常建立连接

    3、利用子协议数组,将 token 携带在 protocols 里,var ws = new WebSocket(url, ["token"]);

    这样后端在 onOpen 事件中,就可以从 server 中读取 Sec-WebSocket-Protocol 属性来进行 token 的获取,具体可以参考WebScoket构造函数官方文档

    1. var aWebSocket = new WebSocket(url [, protocols]);
    2. url
    3. 要连接的URL;这应该是WebSocket服务器将响应的URL
    4. protocols 可选
    5. 一个协议字符串或者一个包含协议字符串的数组。这些字符串用于指定子协议,这样单个服务器可以实现多个WebSocket子协议
    6. (例如,您可能希望一台服务器能够根据指定的协议(protocol)处理不同类型的交互)。如果不指定协议字符串,则假定为空字符串。

    protocols对应的就是发起ws连接时, 携带在请求头中的Sec-WebSocket-Protocol属性, 服务端可以获取到此属性的值用于通信逻辑(即通信子协议,当然用来进行token认证也是完全没问题的),前端人员在请求头上携带sec-websocket-protocol=Bearer +token后台在请求到达oauth2之前进行拦截,然后将在请求头上添加Authorization=Bearer +token(key首字母大写),然后在响应头(respone)上添加sec-websocket-protocol=Bearer +token(不添加会报错)

    方法3部分代码示例

    1. //前端
    2. var aWebSocket = new WebSocket(url ['用户token']);
    3. //后端
    4. @Override
    5. public void afterConnectionEstablished(WebSocketSession session) throws Exception {
    6. //这里就是我们所提交的token
    7. String submitedToken=session.getHandshakeHeaders().get("sec-websocket-protocol").get(0);
    8. //根据token取得登录用户信息(业务逻辑根据你自己的来处理)
    9. }

    另外,如果需要在第一次握手前的时候就取得token,只需要在header里面取得就可以啦

    1. @Override
    2. public boolean beforeHandshake(ServerHttpRequest serverHttpRequest, ServerHttpResponse serverHttpResponse, WebSocketHandler webSocketHandler, Map map) throws Exception {
    3. System.out.println("准备握手");
    4. String submitedToken = serverHttpRequest.getHeaders().get("sec-websocket-protocol")
    5. return true;
    6. }

    因为我的项目是APP 移动端与服务端进行交互,所以后来选择了最简单实现的方案一

    首先要解决的就是在拦截器获取url 的token 信息,原框架只从head里面获取,所以需要稍加改动

    找到TokenService.java文件里的getToken方法,改成如下,这样就可以获取url 中的token 了又不影响原来的Http 请求

    1. private String getToken(HttpServletRequest request)
    2. {
    3. String token = Optional.ofNullable(request.getHeader(header)).orElse(request.getParameter(header));
    4. if (StringUtils.isNotEmpty(token) && token.startsWith(Constants.TOKEN_PREFIX))
    5. {
    6. token = token.replace(Constants.TOKEN_PREFIX, "");
    7. }
    8. return token;
    9. }

    接下来就是需要对我们的WebSocket类进行改造了,为了方便阅读,去除了WebSocketUsers类,添加了类变量webSocketSet来存储客户端对象

    1. import com.alibaba.fastjson2.JSON;
    2. import com.tongchuang.common.utils.SecurityUtils;
    3. import com.tongchuang.web.mqtt.domain.DeviceInfo;
    4. import io.netty.util.HashedWheelTimer;
    5. import io.netty.util.Timeout;
    6. import org.slf4j.Logger;
    7. import org.slf4j.LoggerFactory;
    8. import org.springframework.security.core.Authentication;
    9. import org.springframework.stereotype.Component;
    10. import javax.websocket.*;
    11. import javax.websocket.server.PathParam;
    12. import javax.websocket.server.ServerEndpoint;
    13. import java.io.IOException;
    14. import java.util.HashMap;
    15. import java.util.Map;
    16. import java.util.concurrent.CopyOnWriteArraySet;
    17. import java.util.concurrent.Semaphore;
    18. import java.util.concurrent.TimeUnit;
    19. import java.util.concurrent.atomic.AtomicInteger;
    20. import java.util.function.Function;
    21. /**
    22. * websocket 消息处理
    23. *
    24. * @author stronger
    25. */
    26. @Component
    27. @ServerEndpoint("/websocket/message")
    28. public class WebSocketServer {
    29. /*========================声明类变量,意在所有实例共享=================================================*/
    30. /**
    31. * WebSocketServer 日志控制器
    32. */
    33. private static final Logger LOGGER = LoggerFactory.getLogger(WebSocketServer.class);
    34. /**
    35. * 默认最多允许同时在线人数100
    36. */
    37. public static int socketMaxOnlineCount = 100;
    38. private static Semaphore socketSemaphore = new Semaphore(socketMaxOnlineCount);
    39. HashedWheelTimer timer = new HashedWheelTimer(1, TimeUnit.SECONDS, 8);
    40. /**
    41. * concurrent包的线程安全Set,用来存放每个客户端对应的MyWebSocket对象。
    42. */
    43. private static final CopyOnWriteArraySet webSocketSet = new CopyOnWriteArraySet<>();
    44. /**
    45. * 连接数
    46. */
    47. private static final AtomicInteger count = new AtomicInteger();
    48. /*========================声明实例变量,意在每个实例独享=======================================================*/
    49. /**
    50. * 与某个客户端的连接会话,需要通过它来给客户端发送数据
    51. */
    52. private Session session;
    53. /**
    54. * 用户id
    55. */
    56. private String sid = "";
    57. /**
    58. * 连接建立成功调用的方法
    59. */
    60. @OnOpen
    61. public void onOpen(Session session) throws Exception {
    62. // 尝试获取信号量
    63. boolean semaphoreFlag = SemaphoreUtils.tryAcquire(socketSemaphore);
    64. if (!semaphoreFlag) {
    65. // 未获取到信号量
    66. LOGGER.error("\n 当前在线人数超过限制数- {}", socketMaxOnlineCount);
    67. // 给当前Session 登录用户发送消息
    68. sendMessageToUserByText(session, "当前在线人数超过限制数:" + socketMaxOnlineCount);
    69. session.close();
    70. } else {
    71. // 返回此会话的经过身份验证的用户,如果此会话没有经过身份验证的用户,则返回null
    72. Authentication authentication = (Authentication) session.getUserPrincipal();
    73. SecurityUtils.setAuthentication(authentication);
    74. String username = SecurityUtils.getUsername();
    75. this.session = session;
    76. //如果存在就先删除一个,防止重复推送消息
    77. for (WebSocketServer webSocket : webSocketSet) {
    78. if (webSocket.sid.equals(username)) {
    79. webSocketSet.remove(webSocket);
    80. count.getAndDecrement();
    81. }
    82. }
    83. count.getAndIncrement();
    84. webSocketSet.add(this);
    85. this.sid = username;
    86. LOGGER.info("\n 当前人数 - {}", count);
    87. sendMessageToUserByText(session, "连接成功");
    88. }
    89. }
    90. /**
    91. * 连接关闭时处理
    92. */
    93. @OnClose
    94. public void onClose(Session session) {
    95. LOGGER.info("\n 关闭连接 - {}", session);
    96. // 移除用户
    97. webSocketSet.remove(session);
    98. // 获取到信号量则需释放
    99. SemaphoreUtils.release(socketSemaphore);
    100. }
    101. /**
    102. * 抛出异常时处理
    103. */
    104. @OnError
    105. public void onError(Session session, Throwable exception) throws Exception {
    106. if (session.isOpen()) {
    107. // 关闭连接
    108. session.close();
    109. }
    110. String sessionId = session.getId();
    111. LOGGER.info("\n 连接异常 - {}", sessionId);
    112. LOGGER.info("\n 异常信息 - {}", exception);
    113. // 移出用户
    114. webSocketSet.remove(session);
    115. // 获取到信号量则需释放
    116. SemaphoreUtils.release(socketSemaphore);
    117. }
    118. /**
    119. * 服务器接收到客户端消息时调用的方法
    120. */
    121. @OnMessage
    122. public void onMessage(String message, Session session) {
    123. Authentication authentication = (Authentication) session.getUserPrincipal();
    124. LOGGER.info("收到来自" + sid + "的信息:" + message);
    125. // 实时更新
    126. this.refresh(sid, authentication);
    127. sendMessageToUserByText(session, "我收到了你的新消息哦");
    128. }
    129. /**
    130. * 刷新定时任务,发送信息
    131. */
    132. private void refresh(String userId, Authentication authentication) {
    133. this.start(5000L, task -> {
    134. // 判断用户是否在线,不在线则不用处理,因为在内部无法关闭该定时任务,所以通过返回值在外部进行判断。
    135. if (WebSocketServer.isConn(userId)) {
    136. // 因为这里是长链接,不会和普通网页一样,每次发送http 请求可以走拦截器【doFilterInternal】续约,所以需要手动续约
    137. SecurityUtils.setAuthentication(authentication);
    138. // 从数据库或者缓存中获取信息,构建自定义的Bean
    139. DeviceInfo deviceInfo = DeviceInfo.builder().Macaddress("de5a735951ee").Imei("351517175516665")
    140. .Battery("99").Charge("0").Latitude("116.402649").Latitude("39.914859").Altitude("80")
    141. .Method(SecurityUtils.getUsername()).build();
    142. // TODO判断数据是否有更新
    143. // 发送最新数据给前端
    144. WebSocketServer.sendInfo("JSON", deviceInfo, userId);
    145. // 设置返回值,判断是否需要继续执行
    146. return true;
    147. }
    148. return false;
    149. });
    150. }
    151. private void start(long delay, Function function) {
    152. timer.newTimeout(t -> {
    153. // 获取返回值,判断是否执行
    154. Boolean result = function.apply(t);
    155. if (result) {
    156. timer.newTimeout(t.task(), delay, TimeUnit.MILLISECONDS);
    157. }
    158. }, delay, TimeUnit.MILLISECONDS);
    159. }
    160. /**
    161. * 判断是否有链接
    162. *
    163. * @return
    164. */
    165. public static boolean isConn(String sid) {
    166. for (WebSocketServer item : webSocketSet) {
    167. if (item.sid.equals(sid)) {
    168. return true;
    169. }
    170. }
    171. return false;
    172. }
    173. /**
    174. * 群发自定义消息
    175. * 或者指定用户发送消息
    176. */
    177. public static void sendInfo(String type, Object data, @PathParam("sid") String sid) {
    178. // 遍历WebSocketServer对象集合,如果符合条件就推送
    179. for (WebSocketServer item : webSocketSet) {
    180. try {
    181. //这里可以设定只推送给这个sid的,为null则全部推送
    182. if (sid == null) {
    183. item.sendMessage(type, data);
    184. } else if (item.sid.equals(sid)) {
    185. item.sendMessage(type, data);
    186. }
    187. } catch (IOException ignored) {
    188. }
    189. }
    190. }
    191. /**
    192. * 实现服务器主动推送
    193. */
    194. private void sendMessage(String type, Object data) throws IOException {
    195. Map result = new HashMap<>();
    196. result.put("type", type);
    197. result.put("data", data);
    198. this.session.getAsyncRemote().sendText(JSON.toJSONString(result));
    199. }
    200. /**
    201. * 实现服务器主动推送-根据session
    202. */
    203. public static void sendMessageToUserByText(Session session, String message) {
    204. if (session != null) {
    205. try {
    206. session.getBasicRemote().sendText(message);
    207. } catch (IOException e) {
    208. LOGGER.error("\n[发送消息异常]", e);
    209. }
    210. } else {
    211. LOGGER.info("\n[你已离线]");
    212. }
    213. }
    214. }

    1. public class SecurityUtils
    2. {
    3. public static void setAuthentication(Authentication authentication) {
    4. SecurityContextHolder.getContext().setAuthentication(authentication);
    5. }
    6. }

  • 相关阅读:
    binary_cross_entropy和binary_cross_entropy_with_logits的区别
    Python实现贝叶斯岭回归模型(BayesianRidge算法)并使用K折交叉验证进行模型评估项目实战
    高级篇之ENC编码器多机位帧同步配置详解
    用检索做时间序列预测是一种怎样的体验
    剑指offer-62-圆圈中最后剩下的数字
    C#学习记录——GDI+绘图基础
    AgileConfig 1.8.0 已适配 .NET8
    webpack 原理
    加密货币恐怖融资惊动国会!而链上分析公司看不下去了,紧急辟谣?
    赶紧收藏!!!我直接上瘾!百万人都在学的 Docker
  • 原文地址:https://blog.csdn.net/neusoft2016/article/details/132919507