|
68 | 68 | import org.springframework.security.authorization.AuthorizationDecision;
|
69 | 69 | import org.springframework.security.authorization.AuthorizationManager;
|
70 | 70 | import org.springframework.security.config.annotation.SecurityContextChangedListenerConfig;
|
| 71 | +import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; |
71 | 72 | import org.springframework.security.config.annotation.web.messaging.MessageSecurityMetadataSourceRegistry;
|
72 | 73 | import org.springframework.security.config.observation.SecurityObservationSettings;
|
73 | 74 | import org.springframework.security.core.Authentication;
|
@@ -438,6 +439,12 @@ public void sendMessageWhenExcludeAuthorizationObservationsThenUnobserved() {
|
438 | 439 | verifyNoInteractions(observationHandler);
|
439 | 440 | }
|
440 | 441 |
|
| 442 | + // gh-16011 |
| 443 | + @Test |
| 444 | + public void enableWebSocketSecurityWhenWebSocketSecurityUsedThenAutowires() { |
| 445 | + loadConfig(WithWebSecurity.class); |
| 446 | + } |
| 447 | + |
441 | 448 | private void assertHandshake(HttpServletRequest request) {
|
442 | 449 | TestHandshakeHandler handshakeHandler = this.context.getBean(TestHandshakeHandler.class);
|
443 | 450 | assertThatCsrfToken(handshakeHandler.attributes.get(CsrfToken.class.getName())).isEqualTo(this.token);
|
@@ -489,6 +496,7 @@ private <T extends MessageChannel> T clientInboundChannel() {
|
489 | 496 |
|
490 | 497 | private void loadConfig(Class<?>... configs) {
|
491 | 498 | this.context = new AnnotationConfigWebApplicationContext();
|
| 499 | + this.context.setAllowBeanDefinitionOverriding(false); |
492 | 500 | this.context.register(configs);
|
493 | 501 | this.context.setServletConfig(new MockServletConfig());
|
494 | 502 | this.context.refresh();
|
@@ -939,6 +947,13 @@ TestHandshakeHandler testHandshakeHandler() {
|
939 | 947 |
|
940 | 948 | }
|
941 | 949 |
|
| 950 | + @Configuration(proxyBeanMethods = false) |
| 951 | + @EnableWebSecurity |
| 952 | + @Import(WebSocketSecurityConfig.class) |
| 953 | + static class WithWebSecurity { |
| 954 | + |
| 955 | + } |
| 956 | + |
942 | 957 | @Configuration
|
943 | 958 | static class SyncExecutorConfig {
|
944 | 959 |
|
|
0 commit comments