|
30 | 30 | import org.springframework.mock.web.MockServletConfig; |
31 | 31 | import org.springframework.security.config.BeanIds; |
32 | 32 | import org.springframework.security.config.util.InMemoryXmlWebApplicationContext; |
| 33 | +import org.springframework.security.test.web.reactive.server.SecurityMockServerConfigurers; |
| 34 | +import org.springframework.security.test.web.reactive.server.WebTestClientBuilder; |
33 | 35 | import org.springframework.security.web.servlet.MockServletContext; |
34 | 36 | import org.springframework.test.context.web.GenericXmlWebContextLoader; |
| 37 | +import org.springframework.test.web.reactive.server.WebTestClient; |
35 | 38 | import org.springframework.test.web.servlet.MockMvc; |
36 | 39 | import org.springframework.test.web.servlet.request.RequestPostProcessor; |
37 | 40 | import org.springframework.test.web.servlet.setup.ConfigurableMockMvcBuilder; |
|
42 | 45 | import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; |
43 | 46 | import org.springframework.web.context.support.XmlWebApplicationContext; |
44 | 47 | import org.springframework.web.filter.OncePerRequestFilter; |
| 48 | +import org.springframework.web.server.WebFilter; |
45 | 49 |
|
46 | 50 | import static org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.springSecurity; |
47 | 51 |
|
@@ -156,6 +160,18 @@ public void autowire() { |
156 | 160 | // @formatter:on |
157 | 161 | this.context.getBeanFactory().registerResolvableDependency(MockMvc.class, mockMvc); |
158 | 162 | } |
| 163 | + String webFluxSecurityBean = "org.springframework.security.config.annotation.web.reactive.WebFluxSecurityConfiguration.WebFilterChainFilter"; |
| 164 | + if (this.context.containsBean(webFluxSecurityBean)) { |
| 165 | + WebFilter springSecurityFilter = this.context.getBean(webFluxSecurityBean, WebFilter.class); |
| 166 | + // @formatter:off |
| 167 | + WebTestClient webTest = WebTestClient |
| 168 | + .bindToController(new WebTestClientBuilder.Http200RestController()) |
| 169 | + .webFilter(springSecurityFilter) |
| 170 | + .apply(SecurityMockServerConfigurers.springSecurity()) |
| 171 | + .build(); |
| 172 | + // @formatter:on |
| 173 | + this.context.getBeanFactory().registerResolvableDependency(WebTestClient.class, webTest); |
| 174 | + } |
159 | 175 | AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor(); |
160 | 176 | bpp.setBeanFactory(this.context.getBeanFactory()); |
161 | 177 | bpp.processInjection(this.test); |
|
0 commit comments