|
32 | 32 | import org.springframework.security.config.test.SpringTestContextExtension;
|
33 | 33 | import org.springframework.security.config.users.ReactiveAuthenticationTestConfiguration;
|
34 | 34 | import org.springframework.security.web.server.WebFilterChainProxy;
|
| 35 | +import org.springframework.security.web.server.firewall.HttpStatusExchangeRejectedHandler; |
| 36 | +import org.springframework.security.web.server.firewall.ServerExchangeRejectedHandler; |
35 | 37 | import org.springframework.security.web.server.firewall.ServerWebExchangeFirewall;
|
36 | 38 | import org.springframework.web.server.handler.DefaultWebFilterChain;
|
37 | 39 |
|
@@ -70,6 +72,20 @@ void loadConfigWhenDefaultThenFirewalled() throws Exception {
|
70 | 72 | assertThat(exchange.getResponse().getStatusCode()).isEqualTo(HttpStatus.BAD_REQUEST);
|
71 | 73 | }
|
72 | 74 |
|
| 75 | + @Test |
| 76 | + void loadConfigWhenCustomRejectedHandler() throws Exception { |
| 77 | + this.spring |
| 78 | + .register(ServerHttpSecurityConfiguration.class, ReactiveAuthenticationTestConfiguration.class, |
| 79 | + WebFluxSecurityConfiguration.class, CustomServerExchangeRejectedHandlerConfig.class) |
| 80 | + .autowire(); |
| 81 | + WebFilterChainProxy webFilterChainProxy = this.spring.getContext().getBean(WebFilterChainProxy.class); |
| 82 | + MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/;/").build()); |
| 83 | + DefaultWebFilterChain chain = emptyChain(); |
| 84 | + webFilterChainProxy.filter(exchange, chain).block(); |
| 85 | + assertThat(exchange.getResponse().getStatusCode()) |
| 86 | + .isEqualTo(CustomServerExchangeRejectedHandlerConfig.EXPECTED_STATUS); |
| 87 | + } |
| 88 | + |
73 | 89 | @Test
|
74 | 90 | void loadConfigWhenFirewallBeanThenCustomized() throws Exception {
|
75 | 91 | this.spring
|
@@ -107,6 +123,18 @@ ServerWebExchangeFirewall noOpFirewall() {
|
107 | 123 |
|
108 | 124 | }
|
109 | 125 |
|
| 126 | + @Configuration |
| 127 | + static class CustomServerExchangeRejectedHandlerConfig { |
| 128 | + |
| 129 | + static HttpStatus EXPECTED_STATUS = HttpStatus.I_AM_A_TEAPOT; |
| 130 | + |
| 131 | + @Bean |
| 132 | + ServerExchangeRejectedHandler rejectedHandler() { |
| 133 | + return new HttpStatusExchangeRejectedHandler(EXPECTED_STATUS); |
| 134 | + } |
| 135 | + |
| 136 | + } |
| 137 | + |
110 | 138 | @Configuration
|
111 | 139 | static class SubclassConfig extends WebFluxSecurityConfiguration {
|
112 | 140 |
|
|
0 commit comments