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) {
        if (!request.getParameterMap().isEmpty()) {
            String token = request.getParameterMap().get("token").get(0);
            String mac = request.getParameterMap().get("mac").get(0);
            sec.getUserProperties().put("token", token);
            sec.getUserProperties().put("mac", mac);
        }
    }
}
