Skip to content

Commit 91832bf

Browse files
committed
Add EnableWebSecurity + EnableWebSocketSecurity Test
Issue gh-16011
1 parent 30c9860 commit 91832bf

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

config/src/test/java/org/springframework/security/config/annotation/web/socket/WebSocketMessageBrokerSecurityConfigurationTests.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
import org.springframework.security.authorization.AuthorizationDecision;
6969
import org.springframework.security.authorization.AuthorizationManager;
7070
import org.springframework.security.config.annotation.SecurityContextChangedListenerConfig;
71+
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
7172
import org.springframework.security.config.annotation.web.messaging.MessageSecurityMetadataSourceRegistry;
7273
import org.springframework.security.config.observation.SecurityObservationSettings;
7374
import org.springframework.security.core.Authentication;
@@ -438,6 +439,12 @@ public void sendMessageWhenExcludeAuthorizationObservationsThenUnobserved() {
438439
verifyNoInteractions(observationHandler);
439440
}
440441

442+
// gh-16011
443+
@Test
444+
public void enableWebSocketSecurityWhenWebSocketSecurityUsedThenAutowires() {
445+
loadConfig(WithWebSecurity.class);
446+
}
447+
441448
private void assertHandshake(HttpServletRequest request) {
442449
TestHandshakeHandler handshakeHandler = this.context.getBean(TestHandshakeHandler.class);
443450
assertThatCsrfToken(handshakeHandler.attributes.get(CsrfToken.class.getName())).isEqualTo(this.token);
@@ -489,6 +496,7 @@ private <T extends MessageChannel> T clientInboundChannel() {
489496

490497
private void loadConfig(Class<?>... configs) {
491498
this.context = new AnnotationConfigWebApplicationContext();
499+
this.context.setAllowBeanDefinitionOverriding(false);
492500
this.context.register(configs);
493501
this.context.setServletConfig(new MockServletConfig());
494502
this.context.refresh();
@@ -939,6 +947,13 @@ TestHandshakeHandler testHandshakeHandler() {
939947

940948
}
941949

950+
@Configuration(proxyBeanMethods = false)
951+
@EnableWebSecurity
952+
@Import(WebSocketSecurityConfig.class)
953+
static class WithWebSecurity {
954+
955+
}
956+
942957
@Configuration
943958
static class SyncExecutorConfig {
944959

0 commit comments

Comments
 (0)