package com.ruoyi.ws.config;

import javax.websocket.HandshakeResponse;
import javax.websocket.server.HandshakeRequest;
import javax.websocket.server.ServerEndpointConfig;

/**
 * WebSocket认证配置器
 */
public class WebSocketAuthConfigurator extends ServerEndpointConfig.Configurator {
    @Override
    public void modifyHandshake(ServerEndpointConfig sec, HandshakeRequest request, HandshakeResponse response) {
        String token = null;
        if (!request.getParameterMap().isEmpty()) {
            token = request.getParameterMap().get("token").get(0);
        }
        sec.getUserProperties().put("token", token);
    }
} 