spring-messaging

Spring security websocket and HTTP authentication/authorization

假如想象 提交于 2019-12-05 06:55:47
Summary I would like to implement websocket communication over STOMP. Authenticate The user in the time of the first (HTTP request) websocket handshake and use this Principal for authorizing websocket messages later. Problem The system authenticates the client at the first time when it tries to connect to the websocket endpoint (the time of HTTP handshake). My spring security filter and Authentication provider does its job and authenticates the client properly. After this I can check that the client gets the Roles and my Authentication object is stored in the SecurityContext as well. (At this

Send STOMP ERROR from Spring Websocket program

隐身守侯 提交于 2019-12-04 15:26:59
I have a Spring Websocket Stomp application that accepts SUBSCRIBE requests. In application I have a handler for SUBSCRIBE, that is, @Component public class SubscribeStompEventHandler implements ApplicationListener<SessionSubscribeEvent> { @Override public void onApplicationEvent(SessionSubscribeEvent event) {} } that I use to validate subscription. I would check something in the onApplicationEvent and send STOMP ERROR message back to client from this function. I found this recipe How to send ERROR message to STOMP clients with Spring WebSocket? but I need to understand how to get

Spring Stomp @SendToUser with unauthenticated user not working

我的梦境 提交于 2019-12-04 09:48:51
问题 I'm trying to respond to an unauthenticated user using @SendToUser . Spring 4.1.1 I'm using a newly created Spring Boot application and the only config I have is: @Configuration @EnableWebSocketMessageBroker public class WebSocketConfig extends AbstractWebSocketMessageBrokerConfigurer { @Override public void registerStompEndpoints(StompEndpointRegistry registry) { registry.addEndpoint("/stomp").withSockJS(); } @Override public void configureMessageBroker(MessageBrokerRegistry registry) {

How to send ERROR message to STOMP clients with Spring WebSocket?

泪湿孤枕 提交于 2019-12-03 11:56:06
问题 I am using Spring's STOMP over WebSocket implementation with a full-featured ActiveMQ broker. When users SUBSCRIBE to a topic, there is some permissions logic that they must pass through before being successfully subscribed. I am using a ChannelInterceptor to apply the permissions logic, as configured below: WebSocketConfig.java: @EnableWebSocketMessageBroker public class WebSocketConfig extends AbstractWebSocketMessageBrokerConfigurer { @Override public void registerStompEndpoints

How to get/set the principal and session attributes from Spring 4 stomp websocket methods

二次信任 提交于 2019-12-03 07:14:20
问题 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 . 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

How to send ERROR message to STOMP clients with Spring WebSocket?

孤者浪人 提交于 2019-12-03 05:44:42
I am using Spring's STOMP over WebSocket implementation with a full-featured ActiveMQ broker. When users SUBSCRIBE to a topic, there is some permissions logic that they must pass through before being successfully subscribed. I am using a ChannelInterceptor to apply the permissions logic, as configured below: WebSocketConfig.java: @EnableWebSocketMessageBroker public class WebSocketConfig extends AbstractWebSocketMessageBrokerConfigurer { @Override public void registerStompEndpoints(StompEndpointRegistry registry) { registry.addEndpoint("/stomp") .setAllowedOrigins("*") .withSockJS(); }

Spring Stomp @SendToUser with unauthenticated user not working

六眼飞鱼酱① 提交于 2019-12-03 04:05:43
I'm trying to respond to an unauthenticated user using @SendToUser . Spring 4.1.1 I'm using a newly created Spring Boot application and the only config I have is: @Configuration @EnableWebSocketMessageBroker public class WebSocketConfig extends AbstractWebSocketMessageBrokerConfigurer { @Override public void registerStompEndpoints(StompEndpointRegistry registry) { registry.addEndpoint("/stomp").withSockJS(); } @Override public void configureMessageBroker(MessageBrokerRegistry registry) { registry.enableSimpleBroker("/topic"); registry.setApplicationDestinationPrefixes("/app"); registry

How to get/set the principal and session attributes from Spring 4 stomp websocket methods

早过忘川 提交于 2019-12-02 20:48:21
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 . 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

How to reply to unauthenticated user in Spring 4 STOMP over WebSocket configuration?

南楼画角 提交于 2019-12-01 05:15:10
问题 I'm experimenting with Spring 4 WebSocket STOMP application. Is there a way to reply to a single unauthenticated user on condition that each user has unique session ID? Right now I can only either broadcast a message or send it directly to an authenticated user. @Controller public class ProductController { @MessageMapping("/products/{id}") @SendTo("/topic") // This line makes return value to be broadcasted to every connected user. public String getProduct(@DestinationVariable int id) { return

Could not autowire. No beans of SimpMessagingTemplate type found

爱⌒轻易说出口 提交于 2019-11-29 11:38:51
问题 I am configuring Websockets in Spring basically by following the guide provided in the documentation. I am currently trying to send a message from the server to the client as explained in the section "Sending messages from anywhere" Following the example, you can Autowire a class called SimpMessagingTemplate @Controller public class GreetingController { private SimpMessagingTemplate template; @Autowired public GreetingController(SimpMessagingTemplate template) { this.template = template; }