Spring security Spring安全性/Spring会话/Web套接字

Spring security Spring安全性/Spring会话/Web套接字,spring-security,spring-websocket,spring-messaging,spring-session,Spring Security,Spring Websocket,Spring Messaging,Spring Session,我们正在尝试结合使用spring会话、spring安全性和websocket来实现websocket API的安全性,而不使用cookie 理想情况下,我们将使用websocket/stomp消息使用授权头或身份验证,但在当前的springwebsocket支持下,这似乎是不可能的 我们正在使用预验证提供程序来验证查询参数令牌并让用户登录。我可以看到,在预授权中,适当的用户被拉出进行握手,但是连接到websocket的拦截器无法使用SecurityContext 我们的spring安全配置是

我们正在尝试结合使用spring会话、spring安全性和websocket来实现websocket API的安全性,而不使用cookie

理想情况下,我们将使用websocket/stomp消息使用授权头或身份验证,但在当前的springwebsocket支持下,这似乎是不可能的

我们正在使用预验证提供程序来验证查询参数令牌并让用户登录。我可以看到,在预授权中,适当的用户被拉出进行握手,但是连接到websocket的拦截器无法使用SecurityContext

我们的spring安全配置是


我们的websocket配置是

@配置
@使能调度
@EnableWebSocketMessageBroker
公共类WebsocketConfiguration扩展了AbstractSessionWebSocketMessageBrokerConfigure{
@注入
私有身份验证Interceptor AuthenticationValidationInterceptor;
@注入
专用选择器或QuotingInterceptor选择器或QuotingInterceptor;
@注入
private Selector ValidationInterceptor Selector ValidationInterceptor;
@凌驾
受保护的无效配置StompendPoints(StompEndpointRegistry注册表){
registry.addEndpoint(“/stomp”)
.withSockJS().SetSessionCookieEded(false);
}
@凌驾
public void配置MessageBroker(MessageBrokerRegistry注册表){
registry.enablestombrokerrelay(“/topic”)
.setRelayHost(“本地主机”)
.setRelayPort(7672);
registry.setApplicationDestinationPrefixes(“/api/data/streaming”);
}
@凌驾
公共无效配置ClientInBoundChannel(通道注册){
注册拦截程序(
authenticationValidationInterceptor,
选择器ValidationInterceptor,
选择器或引用接收器);
}
@凌驾
公共无效配置ClientOutboundChannel(通道注册){
}
}

这里被诅咒者的同事。我们的配置在很大程度上是正确的,但我们的问题源于对安全上下文及其在websocket方面的可用性的误解

从各种子问题中收集的评论导致我们从拦截器中的消息中获取登录用户主体

StompHeaderAccessor headerAccessor = StompHeaderAccessor.wrap(message);
Principal userPrincipal = headerAccessor.getUser();
而不是

SecurityContextHolder.getContext().getAuthentication().getName();

您使用的是哪个版本的spring framework?我们使用spring framework 4.1.2和spring Security 4.0RC1。我们也在使用SpringSession1.0相关问题:你能发布你的配置吗?在这种情况下,我很难找到校长。您使用什么类型的标题和标题值?
SecurityContextHolder.getContext().getAuthentication().getName();