| | |
| | | * 1. 前端连接 websocket 时,会通过拼接 ?token={token} 到 ws:// 连接后,这样它可以被 {@link TokenAuthenticationFilter} 所认证通过 |
| | | * 2. {@link LoginUserHandshakeInterceptor} 负责把 {@link LoginUser} 添加到 {@link WebSocketSession} 中 |
| | | * |
| | | * @author 芋道源码 |
| | | * @author 超级管理员 |
| | | */ |
| | | public class LoginUserHandshakeInterceptor implements HandshakeInterceptor { |
| | | |
| | |
| | | public boolean beforeHandshake(ServerHttpRequest request, ServerHttpResponse response, |
| | | WebSocketHandler wsHandler, Map<String, Object> attributes) { |
| | | LoginUser loginUser = SecurityFrameworkUtils.getLoginUser(); |
| | | if (loginUser != null) { |
| | | WebSocketFrameworkUtils.setLoginUser(loginUser, attributes); |
| | | if (loginUser == null) { |
| | | return false; |
| | | } |
| | | WebSocketFrameworkUtils.setLoginUser(loginUser, attributes); |
| | | return true; |
| | | } |
| | | |