验证和识别WebSocket连接

问题描述

我正在使用带有JWT和spring security的spring-boot。但是,我添加了websocket支持,无法找到方法来验证连接的身份(只有授权用户才能连接)以及如何识别连接所属的人。

在我的WebSecurity配置中,使用:

@Override
protected void configure(HttpSecurity httpSecurity) throws Exception {
    httpSecurity.csrf()
            .disable()
            .authorizeRequests().antMatchers("/register","/authenticate").permitAll()
            .anyRequest().authenticated().and()
            .exceptionHandling()
            .authenticationEntryPoint(jwtAuthenticationEntryPoint)
            .and()
            .sessionManagement()
            .sessionCreationPolicy(SessionCreationPolicy.STATELESS);
    httpSecurity.addFilterBefore(jwtRequestFilter,UsernamePasswordAuthenticationFilter.class);

但是,据我所知,WebSockets不会在握手时传输标头,这意味着我无法使用 jwtRequestFilter来检查JWT令牌。

处理此问题的正确方法是什么?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)