Tag: sockjs

如何结合Spring Security和js sockjs-client

我想通过sockjs-client创建一个Spring Server和一个Broswer javascript客户端连接。 应通过Spring Security确保连接。 我有以下两难困境: Spring Security似乎假设websocket握手是通过经过身份validation的http会话发生的(例如,JSESSIONID cookie设置,登录发生)。 然而,sockjs-client似乎对开发人员施加限制,即必须使用未经过身份validation的http会话(请参阅https://github.com/sockjs/sockjs-client/issues/196 ),以任何方式强制执行此操作。 我对这种困境的评价是否正确,是否有任何明显的解决方案来实现带有websockets的弹簧服务器的安全性,以便sockjs-client可以安全地连接? 如果用于创建经过身份validation的HttpSession,建议的在GET / info请求中传递任何身份validation令牌的解决方案看起来像是无法绕过SockJS安全限制。 这似乎是几个人问题的基础,例如: 在使用sockjs和stomp的/ info请求期间没有cookie Spring Websocket + SockJS的身份validation模型,并按用户发送消息 如何从Spring 4 stomp websocket方法获取/设置主体和会话属性 https://stackoverflow.com/questions/33156282 Spring Websockets @SendToUser没有登录? Spring Session Basic Auth令牌作为Spring-Websocket中的查询参数传递 Spring安全websocket和HTTP身份validation/授权 Spring Session,Websocket Security集成流程 Spring安全/ Spring会话/ Web套接字 Spring Boot,Websockets无法从Session获取用户(即java.security.Principal) Spring 4 WebSockect over STOMP Authentication http://sunitkatkar.blogspot.de/2014/01/spring-4-websockets-with-sockjs-stomp.html 我看到3种可选方式: 不要使用SockJs,而只使用本机Websockets 通过query-param Token在经过身份validation的Http Session上使用SockJS,并牺牲一些安全性 […]

Websockets,SockJs,Stomp,Spring,RabbitMQ,自动删除用户特定的队列

我希望有人可以帮我解决这个问题:我使用Spring的Websocket支持。 使用SockJs和StompJs我订阅这样的队列: var socket = new SockJS(localhost + ‘websocket’); stompClient = Stomp.over(socket); stompClient.connect(”, ”, function(frame) { stompClient.subscribe(“/user/queue/gotMessage”, function(message) { gotMessage((JSON.parse(message.body))); }); }, function(error) { }); 这对Spring的SimpMessageSendingOperations非常有用。 但是有一个大问题。 队列名称如下所示: gotMessage-user3w4tstcj并未将其声明为自动删除队列,但这正是我想要的。 否则我有10k个未使用的队列。 在队列为无消费者的那一刻,队列应该被删除。 我怎么能这样呢?

Spring Boot应用程序中的Websocket – 获取403禁止

Spring Boot应用程序中的Websocket – 获取403禁止 当我在eclipse(没有弹簧启动)中运行时,我可以使用sockjs / stompjs从客户端连接到websocket。 但是当我为websocket代码创建一个Spring启动jar(gradlew build)并运行java -jar websocket-code.jar时,我得到一个连接到websocket的403错误。 我没有websockets的身份validation。 我有一个CORSfilter,并认为请求/响应中的所有标题正确。 下面是我的build.gradle apply plugin: ‘java’ apply plugin: ‘spring-boot’ apply plugin: ‘war’ sourceCompatibility = 1.7 version = ‘1.0’ repositories { mavenCentral() } buildscript { repositories { mavenCentral() } dependencies { classpath(“org.springframework.boot:spring-boot-gradle-plugin:1.2.5.RELEASE”) } } configurations { compile.exclude module: “spring-boot-starter-tomcat” } dependencies { compile “org.springframework:spring-web:$spring_version” compile […]

Stomp spring web socket消息超出了大小限制

我正在我们的spring mvc web应用程序中实现spring web-socket。 但是当我尝试向端点发送一个非常大的消息时,我遇到了超过大小限制的消息。 我收到以下错误, message:The ‘content-length’ header 68718 exceeds the configured message buffer size limit 65536 14:49:11,506 ERROR [org.springframework.web.socket.messaging.StompSubProtocolHandler] (http-localhost/127.0.0.1:8080-4) Failed to parse TextMessage payload=[13684590},..], byteCount=16384, last=true] in session vlsxdeol. Sending STOMP ERROR to client.: org.springframework.messaging.simp.stomp.StompConversionException: The ‘content-length’ header 68718 exceeds the configured message buffer size limit 65536 at org.springframework.messaging.simp.stomp.BufferingStompDecoder.checkBufferLimits(BufferingStompDecoder.java:148) [spring-messaging-4.1.6.RELEASE.jar:4.1.6.RELEASE] at org.springframework.messaging.simp.stomp.BufferingStompDecoder.decode(BufferingStompDecoder.java:124) […]

使用sockjs使用Spring 4 WebSocket无法连接套接字

尝试使用sockjs在套接字上使用带有STOMP的Spring 4 WebSocket。 我遇到了一个问题。 我的配置: websocket.xml – spring上下文的一部分 控制器代码: @MessageMapping(“/ws”) @SendTo(“/topic/ws”) public AjaxResponse hello() throws Exception { AjaxResponse ajaxResponse = new AjaxResponse(); ajaxResponse.setSuccess(true); ajaxResponse.addSuccessMessage(“WEB SOCKET!!! HELL YEAH!”); return ajaxResponse; } 客户端: var socket = new SockJS(“”); var stompClient = Stomp.over(socket); stompClient.connect({}, function(frame) { alert(‘Connected: ‘ + frame); stompClient.send(“/app/ws”, {}, {}); stompClient.subscribe(‘/topic/ws’, function(response){ alert(response.success); }); }); […]

如何使用Sping Websocket在特定的userName上订阅+从方法中获取通知,分别来自BOTH @RequestMapping和@MessageMapping?

我正在实施通知系统。 并希望在用户登录时初始化Socket连接,并向他显示他的通知,以及是否发生某些事件。 以下是我项目的代码片段 web_socket.js var stompClient = null; function connect( temp, context_path ) { var socket = new SockJS( “/ContextPath/websock?nsec=”+temp ); stompClient = Stomp.over(socket); console.log( stompClient ); stompClient.connect({userName: “123456”}, function( frame ){ console.log( “Connected :- “+frame ); stompClient.subscribe(“/user/queue/notifications”, function( notifications ) { notifications_display( notifications.body ); }); stompClient.subscribe(“/user/queue/errors”, function( error ) { console.log( “Error :- “+error […]

当请求的凭据模式为“include”时,响应中的标头不能是通配符“*”

我正在使用Auth0进行用户身份validation,只允许登录用户访问Spring(Boot) RestController 。 此时我正在创建一个实时消息function,用户可以使用stompjs和sockjs将消息从Angular 2客户端( localhost:4200 )发送到Spring服务器(localhost:8081)。 尝试创建Stomp客户端并启动连接时,我收到以下控制台错误: The value of the ‘Access-Control-Allow-Origin’ header in the response must not be the wildcard ‘*’ when the request’s credentials mode is ‘include’. Origin ‘http://localhost:4200’ is therefore not allowed access. The credentials mode of requests initiated by the XMLHttpRequest is controlled by the withCredentials attribute. 在研究了这个问题之后,看起来无法同时设置选项origins = *和credentials […]

哪个“user”来自convertAndSendToUser在SockJS + Spring Websocket中工作?

我想了解convertAndSendToUser如何在Spring SockJS + Websocket框架中工作。 在客户端,我们将连接为 stompClient.connect(login, password, callback()) 这将导致连接请求与登录和密码的“Stomp凭证”,例如,如果我们处理SessionConnectEvent http://www.sergialmar.com/2014/03/detect-websocket-connects-and-disconnects-in -spring-4 / 但我仍然不清楚这是否是服务器端向队列发送操作的“用户”: simpMessagingTemplate.convertAndSendToUser(username, “/queue/reply”, message); 我能得到的最接近的是阅读这个post在Spring Websocket上向特定用户发送消息 ,由Thanh Nguyen Van回答,但目前还不清楚。 基本上我需要做的是订阅一些客户端到同一主题,但在服务器上,发送不同的数据。 客户可以提供用户标识符。