Expose allowedOriginPatterns in SocketJS XML config

Closes gh-26108
This commit is contained in:
Rossen Stoyanchev
2020-11-18 21:20:38 +00:00
parent 8130bf505f
commit 684e695b08
8 changed files with 57 additions and 12 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -226,8 +226,8 @@ public class HandlersBeanDefinitionParserTests {
List<HandshakeInterceptor> interceptors = transportService.getHandshakeInterceptors();
assertThat(interceptors).extracting("class").containsExactly(OriginHandshakeInterceptor.class);
assertThat(transportService.shouldSuppressCors()).isTrue();
assertThat(transportService.getAllowedOrigins().contains("https://mydomain1.example")).isTrue();
assertThat(transportService.getAllowedOrigins().contains("https://mydomain2.example")).isTrue();
assertThat(transportService.getAllowedOrigins()).containsExactly("https://mydomain1.example", "https://mydomain2.example");
assertThat(transportService.getAllowedOriginPatterns()).containsExactly("https://*.mydomain.example");
}

View File

@@ -181,8 +181,8 @@ public class MessageBrokerBeanDefinitionParserTests {
interceptors = defaultSockJsService.getHandshakeInterceptors();
assertThat(interceptors).extracting("class").containsExactly(FooTestInterceptor.class,
BarTestInterceptor.class, OriginHandshakeInterceptor.class);
assertThat(defaultSockJsService.getAllowedOrigins().contains("https://mydomain3.com")).isTrue();
assertThat(defaultSockJsService.getAllowedOrigins().contains("https://mydomain4.com")).isTrue();
assertThat(defaultSockJsService.getAllowedOrigins()).containsExactly("https://mydomain3.com", "https://mydomain4.com");
assertThat(defaultSockJsService.getAllowedOriginPatterns()).containsExactly("https://*.mydomain.com");
SimpUserRegistry userRegistry = this.appContext.getBean(SimpUserRegistry.class);
assertThat(userRegistry).isNotNull();

View File

@@ -17,7 +17,9 @@
</websocket:decorator-factories>
</websocket:transport>
<websocket:stomp-endpoint path=" /foo,/bar" allowed-origins="https://mydomain1.example,https://mydomain2.example">
<websocket:stomp-endpoint path=" /foo,/bar"
allowed-origins="https://mydomain1.example,https://mydomain2.example"
allowed-origin-patterns="https://*.mydomain.com">
<websocket:handshake-handler ref="myHandler"/>
<websocket:handshake-interceptors>
<bean class="org.springframework.web.socket.config.FooTestInterceptor"/>
@@ -25,7 +27,9 @@
</websocket:handshake-interceptors>
</websocket:stomp-endpoint>
<websocket:stomp-endpoint path="/test,/sockjs" allowed-origins="https://mydomain3.com,https://mydomain4.com">
<websocket:stomp-endpoint path="/test,/sockjs"
allowed-origins="https://mydomain3.com,https://mydomain4.com"
allowed-origin-patterns="https://*.mydomain.com">
<websocket:handshake-handler ref="myHandler"/>
<websocket:handshake-interceptors>
<bean class="org.springframework.web.socket.config.FooTestInterceptor"/>

View File

@@ -5,7 +5,7 @@
http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/websocket https://www.springframework.org/schema/websocket/spring-websocket.xsd">
<websocket:handlers allowed-origins="https://mydomain1.example, https://mydomain2.example">
<websocket:handlers allowed-origins="https://mydomain1.example, https://mydomain2.example" allowed-origin-patterns="https://*.mydomain.example">
<websocket:mapping path="/test" handler="testHandler"/>
<websocket:sockjs name="testSockJsService" scheduler="testTaskScheduler" websocket-enabled="false"
session-cookie-needed="false" stream-bytes-limit="2048" disconnect-delay="256"