如何从Spring 4 stomp Websocket方法获取/设置主体和会话属性 [英] How to get/set the principal and session attributes from Spring 4 stomp websocket methods

查看:296
本文介绍了如何从Spring 4 stomp Websocket方法获取/设置主体和会话属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Spring 4 websockets和stomp ,我很难弄清楚如何在用@MessageMapping注释的消息处理方法中获取/设置当前用户和其他会话属性.

I'm doing experiments with Spring 4 websockets and stomp, and I have a hard time figuring out how to get/set the current user and other session attributes in a message handling method annotated with @MessageMapping.

文档说消息处理方法可以采用Principal作为参数,我发现Spring通过在本机套接字会话上调用getUserPrincipal()来检索该主体,然后与该套接字会话相关联,但是我没有除了编写servlet过滤器并将原始请求包装到返回我的cookie中的主体的包装器之外,没有找到任何其他方法可以轻松地自定义此行为.

The documentation says that the message handling methods can take a Principal as argument, and I found that the principal is retrieved by Spring by calling getUserPrincipal() on the native socket session, and then associated with the socket session, but I haven't found any way to easily customize this behavior, other than writing a servlet filter and wrap the original request into a wrapper returning the principal found in my cookie.

所以我的问题是:

  1. 当客户端连接时,如何手动将主体设置为套接字会话(由于有了自定义cookie,我获得了此信息,并且我不使用Spring安全性)?
  2. 如果不可能设置为1,那么当客户端连接时如何向套接字会话添加其他属性?
  3. 如何通过消息处理方法访问套接字会话及其属性?
  4. 是否可以访问连接时浏览器发送的登录名和密码. Spring似乎完全忽略了它们,并且无法访问它们.

推荐答案

暂时不可行(Spring 4.0).一个问题已经在Spring打开(并考虑): https://jira.springsource.org/browse/SPR-11228

This is impossible for the time being (Spring 4.0). An issue has been opened (and considered) at Spring: https://jira.springsource.org/browse/SPR-11228

这篇关于如何从Spring 4 stomp Websocket方法获取/设置主体和会话属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆