use of org.springframework.messaging.simp.SimpMessageHeaderAccessor in project spring-framework by spring-projects.
the class StompSubProtocolHandlerTests method handleMessageToClientWithSimpDisconnectAck.
@Test
public void handleMessageToClientWithSimpDisconnectAck() {
StompHeaderAccessor accessor = StompHeaderAccessor.create(StompCommand.DISCONNECT);
Message<?> connectMessage = MessageBuilder.createMessage(EMPTY_PAYLOAD, accessor.getMessageHeaders());
SimpMessageHeaderAccessor ackAccessor = SimpMessageHeaderAccessor.create(SimpMessageType.DISCONNECT_ACK);
ackAccessor.setHeader(SimpMessageHeaderAccessor.DISCONNECT_MESSAGE_HEADER, connectMessage);
Message<byte[]> ackMessage = MessageBuilder.createMessage(EMPTY_PAYLOAD, ackAccessor.getMessageHeaders());
this.protocolHandler.handleMessageToClient(this.session, ackMessage);
assertEquals(1, this.session.getSentMessages().size());
TextMessage actual = (TextMessage) this.session.getSentMessages().get(0);
assertEquals("ERROR\n" + "message:Session closed.\n" + "content-length:0\n" + "\n ", actual.getPayload());
}
use of org.springframework.messaging.simp.SimpMessageHeaderAccessor in project spring-framework by spring-projects.
the class DefaultSimpUserRegistryTests method createMessage.
private Message<byte[]> createMessage(SimpMessageType type, String sessionId, String subscriptionId, String destination) {
SimpMessageHeaderAccessor accessor = SimpMessageHeaderAccessor.create(type);
accessor.setSessionId(sessionId);
if (destination != null) {
accessor.setDestination(destination);
}
if (subscriptionId != null) {
accessor.setSubscriptionId(subscriptionId);
}
return MessageBuilder.createMessage(new byte[0], accessor.getMessageHeaders());
}
use of org.springframework.messaging.simp.SimpMessageHeaderAccessor in project spring-security by spring-projects.
the class AbstractSecurityWebSocketMessageBrokerConfigurerTests method csrfProtectionForConnect.
@Test
public void csrfProtectionForConnect() throws InterruptedException {
loadConfig(SockJsSecurityConfig.class);
SimpMessageHeaderAccessor headers = SimpMessageHeaderAccessor.create(SimpMessageType.CONNECT);
Message<?> message = message(headers, "/authentication");
MessageChannel messageChannel = clientInboundChannel();
try {
messageChannel.send(message);
fail("Expected Exception");
} catch (MessageDeliveryException success) {
assertThat(success.getCause()).isInstanceOf(MissingCsrfTokenException.class);
}
}
use of org.springframework.messaging.simp.SimpMessageHeaderAccessor in project spring-security by spring-projects.
the class AbstractSecurityWebSocketMessageBrokerConfigurerTests method messagesConnectUseCsrfTokenHandshakeInterceptorMultipleMappings.
@Test
public void messagesConnectUseCsrfTokenHandshakeInterceptorMultipleMappings() throws Exception {
loadConfig(SockJsSecurityConfig.class);
SimpMessageHeaderAccessor headers = SimpMessageHeaderAccessor.create(SimpMessageType.CONNECT);
Message<?> message = message(headers, "/authentication");
MockHttpServletRequest request = sockjsHttpRequest("/other");
HttpRequestHandler handler = handler(request);
handler.handleRequest(request, new MockHttpServletResponse());
assertHandshake(request);
}
use of org.springframework.messaging.simp.SimpMessageHeaderAccessor in project spring-security by spring-projects.
the class AbstractSecurityWebSocketMessageBrokerConfigurerTests method messagesConnectUseCsrfTokenHandshakeInterceptor.
@Test
public void messagesConnectUseCsrfTokenHandshakeInterceptor() throws Exception {
loadConfig(SockJsSecurityConfig.class);
SimpMessageHeaderAccessor headers = SimpMessageHeaderAccessor.create(SimpMessageType.CONNECT);
Message<?> message = message(headers, "/authentication");
MockHttpServletRequest request = sockjsHttpRequest("/chat");
HttpRequestHandler handler = handler(request);
handler.handleRequest(request, new MockHttpServletResponse());
assertHandshake(request);
}
Aggregations